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