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