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