[d24f17c] | 1 | import _concat from "./internal/_concat.js";
|
---|
| 2 | import _curry2 from "./internal/_curry2.js";
|
---|
| 3 | import _reduce from "./internal/_reduce.js";
|
---|
| 4 | import map from "./map.js";
|
---|
| 5 | /**
|
---|
| 6 | * ap applies a list of functions to a list of values.
|
---|
| 7 | *
|
---|
| 8 | * Dispatches to the `ap` method of the first argument, if present. Also
|
---|
| 9 | * treats curried functions as applicatives.
|
---|
| 10 | *
|
---|
| 11 | * @func
|
---|
| 12 | * @memberOf R
|
---|
| 13 | * @since v0.3.0
|
---|
| 14 | * @category Function
|
---|
| 15 | * @sig [a -> b] -> [a] -> [b]
|
---|
| 16 | * @sig Apply f => f (a -> b) -> f a -> f b
|
---|
| 17 | * @sig (r -> a -> b) -> (r -> a) -> (r -> b)
|
---|
| 18 | * @param {*} applyF
|
---|
| 19 | * @param {*} applyX
|
---|
| 20 | * @return {*}
|
---|
| 21 | * @example
|
---|
| 22 | *
|
---|
| 23 | * R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6]
|
---|
| 24 | * R.ap([R.concat('tasty '), R.toUpper], ['pizza', 'salad']); //=> ["tasty pizza", "tasty salad", "PIZZA", "SALAD"]
|
---|
| 25 | *
|
---|
| 26 | * // R.ap can also be used as S combinator
|
---|
| 27 | * // when only two functions are passed
|
---|
| 28 | * R.ap(R.concat, R.toUpper)('Ramda') //=> 'RamdaRAMDA'
|
---|
| 29 | * @symb R.ap([f, g], [a, b]) = [f(a), f(b), g(a), g(b)]
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 | var ap =
|
---|
| 33 | /*#__PURE__*/
|
---|
| 34 | _curry2(function ap(applyF, applyX) {
|
---|
| 35 | return typeof applyX['fantasy-land/ap'] === 'function' ? applyX['fantasy-land/ap'](applyF) : typeof applyF.ap === 'function' ? applyF.ap(applyX) : typeof applyF === 'function' ? function (x) {
|
---|
| 36 | return applyF(x)(applyX(x));
|
---|
| 37 | } : _reduce(function (acc, f) {
|
---|
| 38 | return _concat(acc, map(f, applyX));
|
---|
| 39 | }, [], applyF);
|
---|
| 40 | });
|
---|
| 41 |
|
---|
| 42 | export default ap; |
---|