source: node_modules/ramda/es/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.4 KB
Line 
1import _concat from "./internal/_concat.js";
2import _curry2 from "./internal/_curry2.js";
3import _reduce from "./internal/_reduce.js";
4import 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
32var 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
42export default ap;
Note: See TracBrowser for help on using the repository browser.