source: node_modules/ramda/src/ap.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.5 KB
Line 
1var _concat =
2/*#__PURE__*/
3require("./internal/_concat.js");
4
5var _curry2 =
6/*#__PURE__*/
7require("./internal/_curry2.js");
8
9var _reduce =
10/*#__PURE__*/
11require("./internal/_reduce.js");
12
13var map =
14/*#__PURE__*/
15require("./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
44var 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
54module.exports = ap;
Note: See TracBrowser for help on using the repository browser.