source: node_modules/ramda/es/thunkify.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 946 bytes
RevLine 
[d24f17c]1import curryN from "./curryN.js";
2import _curry1 from "./internal/_curry1.js";
3/**
4 * Creates a thunk out of a function. A thunk delays a calculation until
5 * its result is needed, providing lazy evaluation of arguments.
6 *
7 * @func
8 * @memberOf R
9 * @since v0.26.0
10 * @category Function
11 * @sig ((a, b, ..., j) -> k) -> (a, b, ..., j) -> (() -> k)
12 * @param {Function} fn A function to wrap in a thunk
13 * @return {Function} Expects arguments for `fn` and returns a new function
14 * that, when called, applies those arguments to `fn`.
15 * @see R.partial, R.partialRight
16 * @example
17 *
18 * R.thunkify(R.identity)(42)(); //=> 42
19 * R.thunkify((a, b) => a + b)(25, 17)(); //=> 42
20 */
21
22var thunkify =
23/*#__PURE__*/
24_curry1(function thunkify(fn) {
25 return curryN(fn.length, function createThunk() {
26 var fnArgs = arguments;
27 return function invokeThunk() {
28 return fn.apply(this, fnArgs);
29 };
30 });
31});
32
33export default thunkify;
Note: See TracBrowser for help on using the repository browser.