source: node_modules/ramda/es/useWith.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: 1.8 KB
Line 
1import _curry2 from "./internal/_curry2.js";
2import curryN from "./curryN.js";
3/**
4 * Accepts a function `fn` and a list of transformer functions and returns a
5 * new curried function. When the new function is invoked, it calls the
6 * function `fn` with parameters consisting of the result of calling each
7 * supplied handler on successive arguments to the new function.
8 *
9 * If more arguments are passed to the returned function than transformer
10 * functions, those arguments are passed directly to `fn` as additional
11 * parameters. If you expect additional arguments that don't need to be
12 * transformed, although you can ignore them, it's best to pass an identity
13 * function so that the new function reports the correct arity.
14 *
15 * @func
16 * @memberOf R
17 * @since v0.1.0
18 * @category Function
19 * @sig ((x1, x2, ...) -> z) -> [(a -> x1), (b -> x2), ...] -> (a -> b -> ... -> z)
20 * @param {Function} fn The function to wrap.
21 * @param {Array} transformers A list of transformer functions
22 * @return {Function} The wrapped function.
23 * @see R.converge
24 * @example
25 *
26 * R.useWith(Math.pow, [R.identity, R.identity])(3, 4); //=> 81
27 * R.useWith(Math.pow, [R.identity, R.identity])(3)(4); //=> 81
28 * R.useWith(Math.pow, [R.dec, R.inc])(3, 4); //=> 32
29 * R.useWith(Math.pow, [R.dec, R.inc])(3)(4); //=> 32
30 * @symb R.useWith(f, [g, h])(a, b) = f(g(a), h(b))
31 */
32
33var useWith =
34/*#__PURE__*/
35_curry2(function useWith(fn, transformers) {
36 return curryN(transformers.length, function () {
37 var args = [];
38 var idx = 0;
39
40 while (idx < transformers.length) {
41 args.push(transformers[idx].call(this, arguments[idx]));
42 idx += 1;
43 }
44
45 return fn.apply(this, args.concat(Array.prototype.slice.call(arguments, transformers.length)));
46 });
47});
48
49export default useWith;
Note: See TracBrowser for help on using the repository browser.