UNPKG

978 BJavaScriptView Raw
1var curryN =
2/*#__PURE__*/
3require("./curryN");
4
5var _curry1 =
6/*#__PURE__*/
7require("./internal/_curry1");
8/**
9 * Creates a thunk out of a function. A thunk delays a calculation until
10 * its result is needed, providing lazy evaluation of arguments.
11 *
12 * @func
13 * @memberOf R
14 * @since v0.26.0
15 * @category Function
16 * @sig ((a, b, ..., j) -> k) -> (a, b, ..., j) -> (() -> k)
17 * @param {Function} fn A function to wrap in a thunk
18 * @return {Function} Expects arguments for `fn` and returns a new function
19 * that, when called, applies those arguments to `fn`.
20 * @see R.partial, R.partialRight
21 * @example
22 *
23 * R.thunkify(R.identity)(42)(); //=> 42
24 * R.thunkify((a, b) => a + b)(25, 17)(); //=> 42
25 */
26
27
28var thunkify =
29/*#__PURE__*/
30_curry1(function thunkify(fn) {
31 return curryN(fn.length, function createThunk() {
32 var fnArgs = arguments;
33 return function invokeThunk() {
34 return fn.apply(this, fnArgs);
35 };
36 });
37});
38
39module.exports = thunkify;
\No newline at end of file