source: node_modules/ramda-adjunct/es/liftFN.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.9 KB
RevLine 
[d24f17c]1import { curry, head, slice, reduce, curryN, map } from 'ramda';
2import ap from './internal/ap';
3
4/**
5 * "lifts" a function to be the specified arity, so that it may "map over" objects that satisfy
6 * the fantasy land Apply spec of algebraic structures.
7 *
8 * Lifting is specific for {@link https://github.com/scalaz/scalaz|scalaz} and {@link http://www.functionaljava.org/|functional java} implementations.
9 * Old version of fantasy land spec were not compatible with this approach,
10 * but as of fantasy land 1.0.0 Apply spec also adopted this approach.
11 *
12 * This function acts as interop for ramda <= 0.23.0 and {@link https://monet.github.io/monet.js/|monet.js}.
13 *
14 * More info {@link https://github.com/fantasyland/fantasy-land/issues/50|here}.
15 *
16 * @func liftFN
17 * @memberOf RA
18 * @since {@link https://char0n.github.io/ramda-adjunct/1.2.0|v1.2.0}
19 * @category Function
20 * @sig Apply a => Number -> (a... -> a) -> (a... -> a)
21 * @param {number} arity The arity of the lifter function
22 * @param {Function} fn The function to lift into higher context
23 * @return {Function} The lifted function
24 * @see {@link http://ramdajs.com/docs/#lift|R.lift}, {@link http://ramdajs.com/docs/#ap|R.ap}
25 * @example
26 *
27 * const { Maybe } = require('monet');
28 *
29 * const add3 = (a, b, c) => a + b + c;
30 * const madd3 = RA.liftFN(3, add3);
31 *
32 * madd3(Maybe.Some(10), Maybe.Some(15), Maybe.Some(17)); //=> Maybe.Some(42)
33 * madd3(Maybe.Some(10), Maybe.Nothing(), Maybe.Some(17)); //=> Maybe.Nothing()
34 */
35var liftFN = curry(function (arity, fn) {
36 var lifted = curryN(arity, fn);
37 return curryN(arity, function () {
38 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
39 args[_key] = arguments[_key];
40 }
41 var accumulator = map(lifted, head(args));
42 var apps = slice(1, Infinity, args);
43 return reduce(ap, accumulator, apps);
44 });
45});
46export default liftFN;
Note: See TracBrowser for help on using the repository browser.