UNPKG

attadux

Version:

Implementation of the redux-modular-ducks, forked from the extensible-duck implementation and extended to include spected validators, state machines, helpers, web workers, effect handling, action multipliers, action enhancers, action throttling/debouncing

1,789 lines (1,625 loc) 283 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global.attadux = {}))); }(this, (function (exports) { 'use strict'; function _isPlaceholder(a) { return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; } var _isPlaceholder_1 = _isPlaceholder; /** * Optimized internal one-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curry1(fn) { return function f1(a) { if (arguments.length === 0 || _isPlaceholder_1(a)) { return f1; } else { return fn.apply(this, arguments); } }; } var _curry1_1 = _curry1; /** * Optimized internal two-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curry2(fn) { return function f2(a, b) { switch (arguments.length) { case 0: return f2; case 1: return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { return fn(a, _b); }); default: return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { return fn(_a, b); }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { return fn(a, _b); }) : fn(a, b); } }; } var _curry2_1 = _curry2; /** * Applies function `fn` to the argument list `args`. This is useful for * creating a fixed-arity function from a variadic function. `fn` should be a * bound function if context is significant. * * @func * @memberOf R * @since v0.7.0 * @category Function * @sig (*... -> a) -> [*] -> a * @param {Function} fn The function which will be called with `args` * @param {Array} args The arguments to call `fn` with * @return {*} result The result, equivalent to `fn(...args)` * @see R.call, R.unapply * @example * * var nums = [1, 2, 3, -99, 42, 6, 7]; * R.apply(Math.max, nums); //=> 42 * @symb R.apply(f, [a, b, c]) = f(a, b, c) */ var apply = /*#__PURE__*/_curry2_1(function apply(fn, args) { return fn.apply(this, args); }); var apply_1 = apply; function _arity(n, fn) { /* eslint-disable no-unused-vars */ switch (n) { case 0: return function () { return fn.apply(this, arguments); }; case 1: return function (a0) { return fn.apply(this, arguments); }; case 2: return function (a0, a1) { return fn.apply(this, arguments); }; case 3: return function (a0, a1, a2) { return fn.apply(this, arguments); }; case 4: return function (a0, a1, a2, a3) { return fn.apply(this, arguments); }; case 5: return function (a0, a1, a2, a3, a4) { return fn.apply(this, arguments); }; case 6: return function (a0, a1, a2, a3, a4, a5) { return fn.apply(this, arguments); }; case 7: return function (a0, a1, a2, a3, a4, a5, a6) { return fn.apply(this, arguments); }; case 8: return function (a0, a1, a2, a3, a4, a5, a6, a7) { return fn.apply(this, arguments); }; case 9: return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.apply(this, arguments); }; case 10: return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.apply(this, arguments); }; default: throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); } } var _arity_1 = _arity; /** * Internal curryN function. * * @private * @category Function * @param {Number} length The arity of the curried function. * @param {Array} received An array of arguments received thus far. * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curryN(length, received, fn) { return function () { var combined = []; var argsIdx = 0; var left = length; var combinedIdx = 0; while (combinedIdx < received.length || argsIdx < arguments.length) { var result; if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { result = received[combinedIdx]; } else { result = arguments[argsIdx]; argsIdx += 1; } combined[combinedIdx] = result; if (!_isPlaceholder_1(result)) { left -= 1; } combinedIdx += 1; } return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); }; } var _curryN_1 = _curryN; /** * Returns a curried equivalent of the provided function, with the specified * arity. The curried function has two unusual capabilities. First, its * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the * following are equivalent: * * - `g(1)(2)(3)` * - `g(1)(2, 3)` * - `g(1, 2)(3)` * - `g(1, 2, 3)` * * Secondly, the special placeholder value [`R.__`](#__) may be used to specify * "gaps", allowing partial application of any combination of arguments, * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), * the following are equivalent: * * - `g(1, 2, 3)` * - `g(_, 2, 3)(1)` * - `g(_, _, 3)(1)(2)` * - `g(_, _, 3)(1, 2)` * - `g(_, 2)(1)(3)` * - `g(_, 2)(1, 3)` * - `g(_, 2)(_, 3)(1)` * * @func * @memberOf R * @since v0.5.0 * @category Function * @sig Number -> (* -> a) -> (* -> a) * @param {Number} length The arity for the returned function. * @param {Function} fn The function to curry. * @return {Function} A new, curried function. * @see R.curry * @example * * var sumArgs = (...args) => R.sum(args); * * var curriedAddFourNumbers = R.curryN(4, sumArgs); * var f = curriedAddFourNumbers(1, 2); * var g = f(3); * g(4); //=> 10 */ var curryN = /*#__PURE__*/_curry2_1(function curryN(length, fn) { if (length === 1) { return _curry1_1(fn); } return _arity_1(length, _curryN_1(length, [], fn)); }); var curryN_1 = curryN; /** * Tests whether or not an object is an array. * * @private * @param {*} val The object to test. * @return {Boolean} `true` if `val` is an array, `false` otherwise. * @example * * _isArray([]); //=> true * _isArray(null); //=> false * _isArray({}); //=> false */ var _isArray = Array.isArray || function _isArray(val) { return val != null && val.length >= 0 && Object.prototype.toString.call(val) === '[object Array]'; }; function _isTransformer(obj) { return typeof obj['@@transducer/step'] === 'function'; } var _isTransformer_1 = _isTransformer; /** * Returns a function that dispatches with different strategies based on the * object in list position (last argument). If it is an array, executes [fn]. * Otherwise, if it has a function with one of the given method names, it will * execute that function (functor case). Otherwise, if it is a transformer, * uses transducer [xf] to return a new transformer (transducer case). * Otherwise, it will default to executing [fn]. * * @private * @param {Array} methodNames properties to check for a custom implementation * @param {Function} xf transducer to initialize if object is transformer * @param {Function} fn default ramda implementation * @return {Function} A function that dispatches on object in list position */ function _dispatchable(methodNames, xf, fn) { return function () { if (arguments.length === 0) { return fn(); } var args = Array.prototype.slice.call(arguments, 0); var obj = args.pop(); if (!_isArray(obj)) { var idx = 0; while (idx < methodNames.length) { if (typeof obj[methodNames[idx]] === 'function') { return obj[methodNames[idx]].apply(obj, args); } idx += 1; } if (_isTransformer_1(obj)) { var transducer = xf.apply(null, args); return transducer(obj); } } return fn.apply(this, arguments); }; } var _dispatchable_1 = _dispatchable; function _map(fn, functor) { var idx = 0; var len = functor.length; var result = Array(len); while (idx < len) { result[idx] = fn(functor[idx]); idx += 1; } return result; } var _map_1 = _map; function _isString(x) { return Object.prototype.toString.call(x) === '[object String]'; } var _isString_1 = _isString; /** * Tests whether or not an object is similar to an array. * * @private * @category Type * @category List * @sig * -> Boolean * @param {*} x The object to test. * @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise. * @example * * _isArrayLike([]); //=> true * _isArrayLike(true); //=> false * _isArrayLike({}); //=> false * _isArrayLike({length: 10}); //=> false * _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true */ var _isArrayLike = /*#__PURE__*/_curry1_1(function isArrayLike(x) { if (_isArray(x)) { return true; } if (!x) { return false; } if (typeof x !== 'object') { return false; } if (_isString_1(x)) { return false; } if (x.nodeType === 1) { return !!x.length; } if (x.length === 0) { return true; } if (x.length > 0) { return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1); } return false; }); var _isArrayLike_1 = _isArrayLike; var XWrap = /*#__PURE__*/function () { function XWrap(fn) { this.f = fn; } XWrap.prototype['@@transducer/init'] = function () { throw new Error('init not implemented on XWrap'); }; XWrap.prototype['@@transducer/result'] = function (acc) { return acc; }; XWrap.prototype['@@transducer/step'] = function (acc, x) { return this.f(acc, x); }; return XWrap; }(); function _xwrap(fn) { return new XWrap(fn); } var _xwrap_1 = _xwrap; /** * Creates a function that is bound to a context. * Note: `R.bind` does not provide the additional argument-binding capabilities of * [Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind). * * @func * @memberOf R * @since v0.6.0 * @category Function * @category Object * @sig (* -> *) -> {*} -> (* -> *) * @param {Function} fn The function to bind to context * @param {Object} thisObj The context to bind `fn` to * @return {Function} A function that will execute in the context of `thisObj`. * @see R.partial * @example * * var log = R.bind(console.log, console); * R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3} * // logs {a: 2} * @symb R.bind(f, o)(a, b) = f.call(o, a, b) */ var bind = /*#__PURE__*/_curry2_1(function bind(fn, thisObj) { return _arity_1(fn.length, function () { return fn.apply(thisObj, arguments); }); }); var bind_1 = bind; function _arrayReduce(xf, acc, list) { var idx = 0; var len = list.length; while (idx < len) { acc = xf['@@transducer/step'](acc, list[idx]); if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } idx += 1; } return xf['@@transducer/result'](acc); } function _iterableReduce(xf, acc, iter) { var step = iter.next(); while (!step.done) { acc = xf['@@transducer/step'](acc, step.value); if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } step = iter.next(); } return xf['@@transducer/result'](acc); } function _methodReduce(xf, acc, obj, methodName) { return xf['@@transducer/result'](obj[methodName](bind_1(xf['@@transducer/step'], xf), acc)); } var symIterator = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator'; function _reduce(fn, acc, list) { if (typeof fn === 'function') { fn = _xwrap_1(fn); } if (_isArrayLike_1(list)) { return _arrayReduce(fn, acc, list); } if (typeof list['fantasy-land/reduce'] === 'function') { return _methodReduce(fn, acc, list, 'fantasy-land/reduce'); } if (list[symIterator] != null) { return _iterableReduce(fn, acc, list[symIterator]()); } if (typeof list.next === 'function') { return _iterableReduce(fn, acc, list); } if (typeof list.reduce === 'function') { return _methodReduce(fn, acc, list, 'reduce'); } throw new TypeError('reduce: list must be array or iterable'); } var _reduce_1 = _reduce; var _xfBase = { init: function () { return this.xf['@@transducer/init'](); }, result: function (result) { return this.xf['@@transducer/result'](result); } }; var XMap = /*#__PURE__*/function () { function XMap(f, xf) { this.xf = xf; this.f = f; } XMap.prototype['@@transducer/init'] = _xfBase.init; XMap.prototype['@@transducer/result'] = _xfBase.result; XMap.prototype['@@transducer/step'] = function (result, input) { return this.xf['@@transducer/step'](result, this.f(input)); }; return XMap; }(); var _xmap = /*#__PURE__*/_curry2_1(function _xmap(f, xf) { return new XMap(f, xf); }); var _xmap_1 = _xmap; function _has(prop, obj) { return Object.prototype.hasOwnProperty.call(obj, prop); } var _has_1 = _has; var toString$1 = Object.prototype.toString; var _isArguments = function () { return toString$1.call(arguments) === '[object Arguments]' ? function _isArguments(x) { return toString$1.call(x) === '[object Arguments]'; } : function _isArguments(x) { return _has_1('callee', x); }; }; var _isArguments_1 = _isArguments; // cover IE < 9 keys issues var hasEnumBug = ! /*#__PURE__*/{ toString: null }.propertyIsEnumerable('toString'); var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; // Safari bug var hasArgsEnumBug = /*#__PURE__*/function () { 'use strict'; return arguments.propertyIsEnumerable('length'); }(); var contains = function contains(list, item) { var idx = 0; while (idx < list.length) { if (list[idx] === item) { return true; } idx += 1; } return false; }; /** * Returns a list containing the names of all the enumerable own properties of * the supplied object. * Note that the order of the output array is not guaranteed to be consistent * across different JS platforms. * * @func * @memberOf R * @since v0.1.0 * @category Object * @sig {k: v} -> [k] * @param {Object} obj The object to extract properties from * @return {Array} An array of the object's own properties. * @see R.keysIn, R.values * @example * * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c'] */ var _keys = typeof Object.keys === 'function' && !hasArgsEnumBug ? function keys(obj) { return Object(obj) !== obj ? [] : Object.keys(obj); } : function keys(obj) { if (Object(obj) !== obj) { return []; } var prop, nIdx; var ks = []; var checkArgsLength = hasArgsEnumBug && _isArguments_1(obj); for (prop in obj) { if (_has_1(prop, obj) && (!checkArgsLength || prop !== 'length')) { ks[ks.length] = prop; } } if (hasEnumBug) { nIdx = nonEnumerableProps.length - 1; while (nIdx >= 0) { prop = nonEnumerableProps[nIdx]; if (_has_1(prop, obj) && !contains(ks, prop)) { ks[ks.length] = prop; } nIdx -= 1; } } return ks; }; var keys = /*#__PURE__*/_curry1_1(_keys); var keys_1 = keys; /** * Takes a function and * a [functor](https://github.com/fantasyland/fantasy-land#functor), * applies the function to each of the functor's values, and returns * a functor of the same shape. * * Ramda provides suitable `map` implementations for `Array` and `Object`, * so this function may be applied to `[1, 2, 3]` or `{x: 1, y: 2, z: 3}`. * * Dispatches to the `map` method of the second argument, if present. * * Acts as a transducer if a transformer is given in list position. * * Also treats functions as functors and will compose them together. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig Functor f => (a -> b) -> f a -> f b * @param {Function} fn The function to be called on every element of the input `list`. * @param {Array} list The list to be iterated over. * @return {Array} The new list. * @see R.transduce, R.addIndex * @example * * var double = x => x * 2; * * R.map(double, [1, 2, 3]); //=> [2, 4, 6] * * R.map(double, {x: 1, y: 2, z: 3}); //=> {x: 2, y: 4, z: 6} * @symb R.map(f, [a, b]) = [f(a), f(b)] * @symb R.map(f, { x: a, y: b }) = { x: f(a), y: f(b) } * @symb R.map(f, functor_o) = functor_o.map(f) */ var map = /*#__PURE__*/_curry2_1( /*#__PURE__*/_dispatchable_1(['fantasy-land/map', 'map'], _xmap_1, function map(fn, functor) { switch (Object.prototype.toString.call(functor)) { case '[object Function]': return curryN_1(functor.length, function () { return fn.call(this, functor.apply(this, arguments)); }); case '[object Object]': return _reduce_1(function (acc, key) { acc[key] = fn(functor[key]); return acc; }, {}, keys_1(functor)); default: return _map_1(fn, functor); } })); var map_1 = map; /** * Returns the larger of its two arguments. * * @func * @memberOf R * @since v0.1.0 * @category Relation * @sig Ord a => a -> a -> a * @param {*} a * @param {*} b * @return {*} * @see R.maxBy, R.min * @example * * R.max(789, 123); //=> 789 * R.max('a', 'b'); //=> 'b' */ var max = /*#__PURE__*/_curry2_1(function max(a, b) { return b > a ? b : a; }); var max_1 = max; /** * Retrieve the value at a given path. * * @func * @memberOf R * @since v0.2.0 * @category Object * @typedefn Idx = String | Int * @sig [Idx] -> {a} -> a | Undefined * @param {Array} path The path to use. * @param {Object} obj The object to retrieve the nested property from. * @return {*} The data at `path`. * @see R.prop * @example * * R.path(['a', 'b'], {a: {b: 2}}); //=> 2 * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined */ var path = /*#__PURE__*/_curry2_1(function path(paths, obj) { var val = obj; var idx = 0; while (idx < paths.length) { if (val == null) { return; } val = val[paths[idx]]; idx += 1; } return val; }); var path_1 = path; /** * Returns a function that when supplied an object returns the indicated * property of that object, if it exists. * * @func * @memberOf R * @since v0.1.0 * @category Object * @sig s -> {s: a} -> a | Undefined * @param {String} p The property name * @param {Object} obj The object to query * @return {*} The value at `obj.p`. * @see R.path * @example * * R.prop('x', {x: 100}); //=> 100 * R.prop('x', {}); //=> undefined */ var prop = /*#__PURE__*/_curry2_1(function prop(p, obj) { return path_1([p], obj); }); var prop_1 = prop; /** * Returns a new list by plucking the same named property off all objects in * the list supplied. * * `pluck` will work on * any [functor](https://github.com/fantasyland/fantasy-land#functor) in * addition to arrays, as it is equivalent to `R.map(R.prop(k), f)`. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig Functor f => k -> f {k: v} -> f v * @param {Number|String} key The key name to pluck off of each object. * @param {Array} f The array or functor to consider. * @return {Array} The list of values for the given key. * @see R.props * @example * * R.pluck('a')([{a: 1}, {a: 2}]); //=> [1, 2] * R.pluck(0)([[1, 2], [3, 4]]); //=> [1, 3] * R.pluck('val', {a: {val: 3}, b: {val: 5}}); //=> {a: 3, b: 5} * @symb R.pluck('x', [{x: 1, y: 2}, {x: 3, y: 4}, {x: 5, y: 6}]) = [1, 3, 5] * @symb R.pluck(0, [[1, 2], [3, 4], [5, 6]]) = [1, 3, 5] */ var pluck = /*#__PURE__*/_curry2_1(function pluck(p, list) { return map_1(prop_1(p), list); }); var pluck_1 = pluck; /** * Optimized internal three-arity curry function. * * @private * @category Function * @param {Function} fn The function to curry. * @return {Function} The curried function. */ function _curry3(fn) { return function f3(a, b, c) { switch (arguments.length) { case 0: return f3; case 1: return _isPlaceholder_1(a) ? f3 : _curry2_1(function (_b, _c) { return fn(a, _b, _c); }); case 2: return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f3 : _isPlaceholder_1(a) ? _curry2_1(function (_a, _c) { return fn(_a, b, _c); }) : _isPlaceholder_1(b) ? _curry2_1(function (_b, _c) { return fn(a, _b, _c); }) : _curry1_1(function (_c) { return fn(a, b, _c); }); default: return _isPlaceholder_1(a) && _isPlaceholder_1(b) && _isPlaceholder_1(c) ? f3 : _isPlaceholder_1(a) && _isPlaceholder_1(b) ? _curry2_1(function (_a, _b) { return fn(_a, _b, c); }) : _isPlaceholder_1(a) && _isPlaceholder_1(c) ? _curry2_1(function (_a, _c) { return fn(_a, b, _c); }) : _isPlaceholder_1(b) && _isPlaceholder_1(c) ? _curry2_1(function (_b, _c) { return fn(a, _b, _c); }) : _isPlaceholder_1(a) ? _curry1_1(function (_a) { return fn(_a, b, c); }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { return fn(a, _b, c); }) : _isPlaceholder_1(c) ? _curry1_1(function (_c) { return fn(a, b, _c); }) : fn(a, b, c); } }; } var _curry3_1 = _curry3; /** * Returns a single item by iterating through the list, successively calling * the iterator function and passing it an accumulator value and the current * value from the array, and then passing the result to the next call. * * The iterator function receives two values: *(acc, value)*. It may use * [`R.reduced`](#reduced) to shortcut the iteration. * * The arguments' order of [`reduceRight`](#reduceRight)'s iterator function * is *(value, acc)*. * * Note: `R.reduce` does not skip deleted or unassigned indices (sparse * arrays), unlike the native `Array.prototype.reduce` method. For more details * on this behavior, see: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description * * Dispatches to the `reduce` method of the third argument, if present. When * doing so, it is up to the user to handle the [`R.reduced`](#reduced) * shortcuting, as this is not implemented by `reduce`. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig ((a, b) -> a) -> a -> [b] -> a * @param {Function} fn The iterator function. Receives two values, the accumulator and the * current element from the array. * @param {*} acc The accumulator value. * @param {Array} list The list to iterate over. * @return {*} The final, accumulated value. * @see R.reduced, R.addIndex, R.reduceRight * @example * * R.reduce(R.subtract, 0, [1, 2, 3, 4]) // => ((((0 - 1) - 2) - 3) - 4) = -10 * // - -10 * // / \ / \ * // - 4 -6 4 * // / \ / \ * // - 3 ==> -3 3 * // / \ / \ * // - 2 -1 2 * // / \ / \ * // 0 1 0 1 * * @symb R.reduce(f, a, [b, c, d]) = f(f(f(a, b), c), d) */ var reduce = /*#__PURE__*/_curry3_1(_reduce_1); var reduce_1 = reduce; /** * Returns a list of all the enumerable own properties of the supplied object. * Note that the order of the output array is not guaranteed across different * JS platforms. * * @func * @memberOf R * @since v0.1.0 * @category Object * @sig {k: v} -> [v] * @param {Object} obj The object to extract values from * @return {Array} An array of the values of the object's own properties. * @see R.valuesIn, R.keys * @example * * R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3] */ var values = /*#__PURE__*/_curry1_1(function values(obj) { var props = keys_1(obj); var len = props.length; var vals = []; var idx = 0; while (idx < len) { vals[idx] = obj[props[idx]]; idx += 1; } return vals; }); var values_1 = values; /** * Given a spec object recursively mapping properties to functions, creates a * function producing an object of the same structure, by mapping each property * to the result of calling its associated function with the supplied arguments. * * @func * @memberOf R * @since v0.20.0 * @category Function * @sig {k: ((a, b, ..., m) -> v)} -> ((a, b, ..., m) -> {k: v}) * @param {Object} spec an object recursively mapping properties to functions for * producing the values for these properties. * @return {Function} A function that returns an object of the same structure * as `spec', with each property set to the value returned by calling its * associated function with the supplied arguments. * @see R.converge, R.juxt * @example * * var getMetrics = R.applySpec({ * sum: R.add, * nested: { mul: R.multiply } * }); * getMetrics(2, 4); // => { sum: 6, nested: { mul: 8 } } * @symb R.applySpec({ x: f, y: { z: g } })(a, b) = { x: f(a, b), y: { z: g(a, b) } } */ var applySpec = /*#__PURE__*/_curry1_1(function applySpec(spec) { spec = map_1(function (v) { return typeof v == 'function' ? v : applySpec(v); }, spec); return curryN_1(reduce_1(max_1, 0, pluck_1('length', values_1(spec))), function () { var args = arguments; return map_1(function (f) { return apply_1(f, args); }, spec); }); }); var applySpec_1 = applySpec; /** * Accepts a converging function and a list of branching functions and returns * a new function. When invoked, this new function is applied to some * arguments, each branching function is applied to those same arguments. The * results of each branching function are passed as arguments to the converging * function to produce the return value. * * @func * @memberOf R * @since v0.4.2 * @category Function * @sig ((x1, x2, ...) -> z) -> [((a, b, ...) -> x1), ((a, b, ...) -> x2), ...] -> (a -> b -> ... -> z) * @param {Function} after A function. `after` will be invoked with the return values of * `fn1` and `fn2` as its arguments. * @param {Array} functions A list of functions. * @return {Function} A new function. * @see R.useWith * @example * * var average = R.converge(R.divide, [R.sum, R.length]) * average([1, 2, 3, 4, 5, 6, 7]) //=> 4 * * var strangeConcat = R.converge(R.concat, [R.toUpper, R.toLower]) * strangeConcat("Yodel") //=> "YODELyodel" * * @symb R.converge(f, [g, h])(a, b) = f(g(a, b), h(a, b)) */ var converge = /*#__PURE__*/_curry2_1(function converge(after, fns) { return curryN_1(reduce_1(max_1, 0, pluck_1('length', fns)), function () { var args = arguments; var context = this; return after.apply(context, _map_1(function (fn) { return fn.apply(context, args); }, fns)); }); }); var converge_1 = converge; /** * juxt applies a list of functions to a list of values. * * @func * @memberOf R * @since v0.19.0 * @category Function * @sig [(a, b, ..., m) -> n] -> ((a, b, ..., m) -> [n]) * @param {Array} fns An array of functions * @return {Function} A function that returns a list of values after applying each of the original `fns` to its parameters. * @see R.applySpec * @example * * var getRange = R.juxt([Math.min, Math.max]); * getRange(3, 4, 9, -3); //=> [-3, 9] * @symb R.juxt([f, g, h])(a, b) = [f(a, b), g(a, b), h(a, b)] */ var juxt = /*#__PURE__*/_curry1_1(function juxt(fns) { return converge_1(function () { return Array.prototype.slice.call(arguments, 0); }, fns); }); var juxt_1 = juxt; /** * Determine if the passed argument is an integer. * * @private * @param {*} n * @category Type * @return {Boolean} */ var _isInteger = Number.isInteger || function _isInteger(n) { return n << 0 === n; }; /** * Makes a shallow clone of an object, setting or overriding the specified * property with the given value. Note that this copies and flattens prototype * properties onto the new object as well. All non-primitive properties are * copied by reference. * * @func * @memberOf R * @since v0.8.0 * @category Object * @sig String -> a -> {k: v} -> {k: v} * @param {String} prop The property name to set * @param {*} val The new value * @param {Object} obj The object to clone * @return {Object} A new object equivalent to the original except for the changed property. * @see R.dissoc * @example * * R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3} */ var assoc = /*#__PURE__*/_curry3_1(function assoc(prop, val, obj) { var result = {}; for (var p in obj) { result[p] = obj[p]; } result[prop] = val; return result; }); var assoc_1 = assoc; /** * Checks if the input value is `null` or `undefined`. * * @func * @memberOf R * @since v0.9.0 * @category Type * @sig * -> Boolean * @param {*} x The value to test. * @return {Boolean} `true` if `x` is `undefined` or `null`, otherwise `false`. * @example * * R.isNil(null); //=> true * R.isNil(undefined); //=> true * R.isNil(0); //=> false * R.isNil([]); //=> false */ var isNil = /*#__PURE__*/_curry1_1(function isNil(x) { return x == null; }); var isNil_1 = isNil; /** * Makes a shallow clone of an object, setting or overriding the nodes required * to create the given path, and placing the specific value at the tail end of * that path. Note that this copies and flattens prototype properties onto the * new object as well. All non-primitive properties are copied by reference. * * @func * @memberOf R * @since v0.8.0 * @category Object * @typedefn Idx = String | Int * @sig [Idx] -> a -> {a} -> {a} * @param {Array} path the path to set * @param {*} val The new value * @param {Object} obj The object to clone * @return {Object} A new object equivalent to the original except along the specified path. * @see R.dissocPath * @example * * R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}} * * // Any missing or non-object keys in path will be overridden * R.assocPath(['a', 'b', 'c'], 42, {a: 5}); //=> {a: {b: {c: 42}}} */ var assocPath = /*#__PURE__*/_curry3_1(function assocPath(path, val, obj) { if (path.length === 0) { return val; } var idx = path[0]; if (path.length > 1) { var nextObj = !isNil_1(obj) && _has_1(idx, obj) ? obj[idx] : _isInteger(path[1]) ? [] : {}; val = assocPath(Array.prototype.slice.call(path, 1), val, nextObj); } if (_isInteger(idx) && _isArray(obj)) { var arr = [].concat(obj); arr[idx] = val; return arr; } else { return assoc_1(idx, val, obj); } }); var assocPath_1 = assocPath; /** * Takes a value and applies a function to it. * * This function is also known as the `thrush` combinator. * * @func * @memberOf R * @since v0.25.0 * @category Function * @sig a -> (a -> b) -> b * @param {*} x The value * @param {Function} f The function to apply * @return {*} The result of applying `f` to `x` * @example * * var t42 = R.applyTo(42); * t42(R.identity); //=> 42 * t42(R.add(1)); //=> 43 */ var applyTo = /*#__PURE__*/_curry2_1(function applyTo(x, f) { return f(x); }); var applyTo_1 = applyTo; function _isObject(x) { return Object.prototype.toString.call(x) === '[object Object]'; } var _isObject_1 = _isObject; /** * Returns the empty value of its argument's type. Ramda defines the empty * value of Array (`[]`), Object (`{}`), String (`''`), and Arguments. Other * types are supported if they define `<Type>.empty`, * `<Type>.prototype.empty` or implement the * [FantasyLand Monoid spec](https://github.com/fantasyland/fantasy-land#monoid). * * Dispatches to the `empty` method of the first argument, if present. * * @func * @memberOf R * @since v0.3.0 * @category Function * @sig a -> a * @param {*} x * @return {*} * @example * * R.empty(Just(42)); //=> Nothing() * R.empty([1, 2, 3]); //=> [] * R.empty('unicorns'); //=> '' * R.empty({x: 1, y: 2}); //=> {} */ var empty = /*#__PURE__*/_curry1_1(function empty(x) { return x != null && typeof x['fantasy-land/empty'] === 'function' ? x['fantasy-land/empty']() : x != null && x.constructor != null && typeof x.constructor['fantasy-land/empty'] === 'function' ? x.constructor['fantasy-land/empty']() : x != null && typeof x.empty === 'function' ? x.empty() : x != null && x.constructor != null && typeof x.constructor.empty === 'function' ? x.constructor.empty() : _isArray(x) ? [] : _isString_1(x) ? '' : _isObject_1(x) ? {} : _isArguments_1(x) ? function () { return arguments; }() : // else void 0; }); var empty_1 = empty; function _arrayFromIterator(iter) { var list = []; var next; while (!(next = iter.next()).done) { list.push(next.value); } return list; } var _arrayFromIterator_1 = _arrayFromIterator; function _containsWith(pred, x, list) { var idx = 0; var len = list.length; while (idx < len) { if (pred(x, list[idx])) { return true; } idx += 1; } return false; } var _containsWith_1 = _containsWith; function _functionName(f) { // String(x => x) evaluates to "x => x", so the pattern may not match. var match = String(f).match(/^function (\w*)/); return match == null ? '' : match[1]; } var _functionName_1 = _functionName; /** * Returns true if its arguments are identical, false otherwise. Values are * identical if they reference the same memory. `NaN` is identical to `NaN`; * `0` and `-0` are not identical. * * @func * @memberOf R * @since v0.15.0 * @category Relation * @sig a -> a -> Boolean * @param {*} a * @param {*} b * @return {Boolean} * @example * * var o = {}; * R.identical(o, o); //=> true * R.identical(1, 1); //=> true * R.identical(1, '1'); //=> false * R.identical([], []); //=> false * R.identical(0, -0); //=> false * R.identical(NaN, NaN); //=> true */ var identical = /*#__PURE__*/_curry2_1(function identical(a, b) { // SameValue algorithm if (a === b) { // Steps 1-5, 7-10 // Steps 6.b-6.e: +0 != -0 return a !== 0 || 1 / a === 1 / b; } else { // Step 6.a: NaN == NaN return a !== a && b !== b; } }); var identical_1 = identical; /** * Gives a single-word string description of the (native) type of a value, * returning such answers as 'Object', 'Number', 'Array', or 'Null'. Does not * attempt to distinguish user Object types any further, reporting them all as * 'Object'. * * @func * @memberOf R * @since v0.8.0 * @category Type * @sig (* -> {*}) -> String * @param {*} val The value to test * @return {String} * @example * * R.type({}); //=> "Object" * R.type(1); //=> "Number" * R.type(false); //=> "Boolean" * R.type('s'); //=> "String" * R.type(null); //=> "Null" * R.type([]); //=> "Array" * R.type(/[A-z]/); //=> "RegExp" * R.type(() => {}); //=> "Function" * R.type(undefined); //=> "Undefined" */ var type = /*#__PURE__*/_curry1_1(function type(val) { return val === null ? 'Null' : val === undefined ? 'Undefined' : Object.prototype.toString.call(val).slice(8, -1); }); var type_1 = type; /** * private _uniqContentEquals function. * That function is checking equality of 2 iterator contents with 2 assumptions * - iterators lengths are the same * - iterators values are unique * * false-positive result will be returned for comparision of, e.g. * - [1,2,3] and [1,2,3,4] * - [1,1,1] and [1,2,3] * */ function _uniqContentEquals(aIterator, bIterator, stackA, stackB) { var a = _arrayFromIterator_1(aIterator); var b = _arrayFromIterator_1(bIterator); function eq(_a, _b) { return _equals(_a, _b, stackA.slice(), stackB.slice()); } // if *a* array contains any element that is not included in *b* return !_containsWith_1(function (b, aItem) { return !_containsWith_1(eq, aItem, b); }, b, a); } function _equals(a, b, stackA, stackB) { if (identical_1(a, b)) { return true; } var typeA = type_1(a); if (typeA !== type_1(b)) { return false; } if (a == null || b == null) { return false; } if (typeof a['fantasy-land/equals'] === 'function' || typeof b['fantasy-land/equals'] === 'function') { return typeof a['fantasy-land/equals'] === 'function' && a['fantasy-land/equals'](b) && typeof b['fantasy-land/equals'] === 'function' && b['fantasy-land/equals'](a); } if (typeof a.equals === 'function' || typeof b.equals === 'function') { return typeof a.equals === 'function' && a.equals(b) && typeof b.equals === 'function' && b.equals(a); } switch (typeA) { case 'Arguments': case 'Array': case 'Object': if (typeof a.constructor === 'function' && _functionName_1(a.constructor) === 'Promise') { return a === b; } break; case 'Boolean': case 'Number': case 'String': if (!(typeof a === typeof b && identical_1(a.valueOf(), b.valueOf()))) { return false; } break; case 'Date': if (!identical_1(a.valueOf(), b.valueOf())) { return false; } break; case 'Error': return a.name === b.name && a.message === b.message; case 'RegExp': if (!(a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.sticky === b.sticky && a.unicode === b.unicode)) { return false; } break; } var idx = stackA.length - 1; while (idx >= 0) { if (stackA[idx] === a) { return stackB[idx] === b; } idx -= 1; } switch (typeA) { case 'Map': if (a.size !== b.size) { return false; } return _uniqContentEquals(a.entries(), b.entries(), stackA.concat([a]), stackB.concat([b])); case 'Set': if (a.size !== b.size) { return false; } return _uniqContentEquals(a.values(), b.values(), stackA.concat([a]), stackB.concat([b])); case 'Arguments': case 'Array': case 'Object': case 'Boolean': case 'Number': case 'String': case 'Date': case 'Error': case 'RegExp': case 'Int8Array': case 'Uint8Array': case 'Uint8ClampedArray': case 'Int16Array': case 'Uint16Array': case 'Int32Array': case 'Uint32Array': case 'Float32Array': case 'Float64Array': case 'ArrayBuffer': break; default: // Values of other types are only equal if identical. return false; } var keysA = keys_1(a); if (keysA.length !== keys_1(b).length) { return false; } var extendedStackA = stackA.concat([a]); var extendedStackB = stackB.concat([b]); idx = keysA.length - 1; while (idx >= 0) { var key = keysA[idx]; if (!(_has_1(key, b) && _equals(b[key], a[key], extendedStackA, extendedStackB))) { return false; } idx -= 1; } return true; } var _equals_1 = _equals; /** * Returns `true` if its arguments are equivalent, `false` otherwise. Handles * cyclical data structures. * * Dispatches symmetrically to the `equals` methods of both arguments, if * present. * * @func * @memberOf R * @since v0.15.0 * @category Relation * @sig a -> b -> Boolean * @param {*} a * @param {*} b * @return {Boolean} * @example * * R.equals(1, 1); //=> true * R.equals(1, '1'); //=> false * R.equals([1, 2, 3], [1, 2, 3]); //=> true * * var a = {}; a.v = a; * var b = {}; b.v = b; * R.equals(a, b); //=> true */ var equals = /*#__PURE__*/_curry2_1(function equals(a, b) { return _equals_1(a, b, [], []); }); var equals_1 = equals; /** * Returns `true` if the given value is its type's empty value; `false` * otherwise. * * @func * @memberOf R * @since v0.1.0 * @category Logic * @sig a -> Boolean * @param {*} x * @return {Boolean} * @see R.empty * @example * * R.isEmpty([1, 2, 3]); //=> false * R.isEmpty([]); //=> true * R.isEmpty(''); //=> true * R.isEmpty(null); //=> false * R.isEmpty({}); //=> true * R.isEmpty({length: 0}); //=> false */ var isEmpty = /*#__PURE__*/_curry1_1(function isEmpty(x) { return x != null && equals_1(x, empty_1(x)); }); var isEmpty_1 = isEmpty; /** * Returns `true` if the specified object property satisfies the given * predicate; `false` otherwise. You can test multiple properties with * [`R.where`](#where). * * @func * @memberOf R * @since v0.16.0 * @category Logic * @sig (a -> Boolean) -> String -> {String: a} -> Boolean * @param {Function} pred * @param {String} name * @param {*} obj * @return {Boolean} * @see R.where, R.propEq, R.propIs * @example * * R.propSatisfies(x => x > 0, 'x', {x: 1, y: 2}); //=> true */ var propSatisfies = /*#__PURE__*/_curry3_1(function propSatisfies(pred, name, obj) { return pred(obj[name]); }); var propSatisfies_1 = propSatisfies; /** * A function that returns the `!` of its argument. It will return `true` when * passed false-y value, and `false` when passed a truth-y one. * * @func * @memberOf R * @since v0.1.0 * @category Logic * @sig * -> Boolean * @param {*} a any value * @return {Boolean} the logical inverse of passed argument. * @see R.complement * @example * * R.not(true); //=> false * R.not(false); //=> true * R.not(0); //=> true * R.not(1); //=> false */ var not = /*#__PURE__*/_curry1_1(function not(a) { return !a; }); var not_1 = not; /** * Takes a list of predicates and returns a predicate that returns true for a * given list of arguments if at least one of the provided predicates is * satisfied by those arguments. * * The function returned is a curried function whose arity matches that of the * highest-arity predicate. * * @func * @memberOf R * @since v0.9.0 * @category Logic * @sig [(*... -> Boolean)] -> (*... -> Boolean) * @param {Array} predicates An array of predicates to check * @return {Function} The combined predicate * @see R.allPass * @example * * var isClub = R.propEq('suit', '♣'); * var isSpade = R.propEq('suit', '♠'); * var isBlackCard = R.anyPass([isClub, isSpade]); * * isBlackCard({rank: '10', suit: '♣'}); //=> true * isBlackCard({rank: 'Q', suit: '♠'}); //=> true * isBlackCard({rank: 'Q', suit: '♦'}); //=> false */ var anyPass = /*#__PURE__*/_curry1_1(function anyPass(preds) { return curryN_1(reduce_1(max_1, 0, pluck_1('length', preds)), function () { var idx = 0; var len = preds.length; while (idx < len) { if (preds[idx].apply(this, arguments)) { return true; } idx += 1; } return false; }); }); var anyPass_1 = anyPass; /** * Takes a list of predicates and returns a predicate that returns true for a * given list of arguments if every one of the provided predicates is satisfied * by those arguments. * * The function returned is a curried function whose arity matches that of the * highest-arity predicate. * * @func * @memberOf R * @since v0.9.0 * @category Logic * @sig [(*... -> Boolean)] -> (*... -> Boolean) * @param {Array} predicates An array of predicates to check * @return {Function} The combined predicate * @see R.anyPass * @example * * var isQueen = R.propEq('rank', 'Q'); * var isSpade = R.propEq('suit', '♠︎'); * var isQueenOfSpades = R.allPass([isQueen, isSpade]); * * isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false * isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true */ var allPass = /*#__PURE__*/_curry1_1(function allPass(preds) { return curryN_1(reduce_1(max_1, 0, pluck_1('length', preds)), function () { var idx = 0; var len = preds.length; while (idx < len) { if (!preds[idx].apply(this, arguments)) { return false; } idx += 1; } return true; }); }); var allPass_1 = allPass; /** * Returns a curried equivalent of the provided function. The curried function * has two unusual capabilities. First, its arguments needn't be provided one * at a time. If `f` is a ternary function and `g` is `R.curry(f)`, the * following are equivalent: * * - `g(1)(2)(3)` * - `g(1)(2, 3)` * - `g(1, 2)(3)` * - `g(1, 2, 3)` * * Secondly, the special placeholder value [`R.__`](#__) may be used to specify * "gaps", allowing partial application of any combination of arguments, * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), * the following are equivalent: * * - `g(1, 2, 3)` * - `g(_, 2, 3)(1)` * - `g(_, _, 3)(1)(2)` * - `g(_, _, 3)(1, 2)` * - `g(_, 2)(1)(3)` * - `g(_, 2)(1, 3)` * - `g(_, 2)(_, 3)(1)` * * @func * @memberOf R * @since v0.1.0 * @category Function * @sig (* -> a) -> (* -> a) * @param {Function} fn The function to curry. * @return {Function} A new, curried function. * @see R.curryN * @example * * var addFourNumbers = (a, b, c, d) => a + b + c + d; * * var curriedAddFourNumbers = R.curry(addFourNumbers); * var f = curriedAddFourNumbers(1, 2); * var g = f(3); * g(4); //=> 10 */ var curry = /*#__PURE__*/_curry1_1(function curry(fn) { return curryN_1(fn.length, fn); }); var curry_1 = curry; /** * Returns the result of calling its first argument with the remaining * arguments. This is occasionally useful as a converging function for * [`R.converge`](#converge): the first branch can produce a function while the * remaining branches produce values to be passed to that function as its * arguments. * * @func * @memberOf R * @since v0.9.0 * @category Function * @sig (*... -> a),*... -> a * @param {Function} fn The function to apply to the remaining arguments. * @param {...*} args Any number of positional arguments. * @return {*} * @see R.apply * @example * * R.call(R.add, 1, 2); //=> 3 * * var indentN = R.pipe(R.repeat(' '), * R.join(''), * R.replace(/^(?!$)/gm)); * * var format = R.converge(R.call, [ * R.pipe(R.prop('indent'), indentN), * R.prop('value') * ]); * * format({indent: 2, value: 'foo\nbar\nbaz\n'}); //=> ' foo\n bar\n baz\n' * @symb R.call(f, a, b) = f(a, b) */ var call = /*#__PURE__*/curry_1(function call(fn) { return fn.apply(this, Array.prototype.slice.call(arguments, 1)); }); var call_1 = call; /** * Returns `true` if the specified object property at given path satisfies the * given predicate; `false` otherwise. * * @func * @memberOf R * @since v0.19.0 * @category Logic * @typedefn Idx = String | Int * @sig (a -> Boolean) -> [Idx] -> {a} -> Boolean * @param {Function} pred * @param {Array} propPath * @param {*} obj * @return {Boolean} * @see R.propSatisfies, R.path * @example * * R.pathSatisfies(y => y > 0, ['x', 'y'], {x: {y: 2}}); //=> true */ var pathSatisfies = /*#__PURE__*/_curry3_1(function pathSatisfies(pred, propPath, obj) { return propPath.length > 0 && pred(path_1(propPath, obj)); }); var pathSatisfies_1 = pathSatisfies; /** * Creates a function that will process either the `onTrue` or the `onFalse` * function depending upon the result of the `condition` predicate. * * @func * @memberOf R * @since v0.8.0 * @category Logic * @sig (*... -> Boolean) -> (*... -> *) -> (*... -> *) -> (*... -> *) * @param {Function} condition A predicate function * @param {Function} onTrue A function to invoke when the `condition` evaluates to a truthy value. * @param {Function} onFalse A function to invoke when the `condition` evaluates to a falsy value. * @return {Function} A new unary function that will process either the `onTrue` or the `onFalse` * function depending upon the result of the `condition` predicate. * @see R.unless, R.when * @example * * var incCount = R.ifElse( * R.has('count'), * R.over(R.lensProp('count'), R.inc), * R.assoc('count', 1) * ); * incCount({}); //=> { count: 1 } * incCount({ count: 1 }); //=> { count: 2 } */ var ifElse = /*#__PURE__*/_curry3_1(function ifElse(condition, onTrue, onFalse) { return curryN_1(Math.max(condition.length, onTrue.length, onFalse.length), function _ifElse() { return condition.apply(this, arguments) ? onTrue.apply(this, arguments) : onFalse.apply(this, arguments); }); }); var ifElse_1 = ifElse; /** * Returns `true` if the specified object property is equal, in * [`R.equals`](#equals) terms, to the given value; `false` otherwise. * You can test multiple properties with [`R.where`](#where). * * @func * @memberOf R * @since v0.1.0 * @category Relation * @sig String -> a -> Object -> Boolean * @param {String} name * @param {*} val * @param {*} obj * @return {Boolean} * @see R.whereEq, R.propSatisfies, R.equals * @example * * var abby = {name: 'Abby', age: 7, hair: 'blond'}; * var fred = {name: 'Fred', age: 12, hair: 'brown'}; * var rusty = {name: 'Rusty', age: 10, hair: 'brown'}; * var alois = {name: 'Alois', age: 15, disposition: 'surly'}; * var kids = [abby, fred, rusty, alois]; * var hasBrownHair = R.propEq('hair', 'brown'); * R.filter(hasBrownHair, kids); //=> [fred, rusty] */ var propEq = /*#__PURE__*/_curry3_1(function propEq(name, val, obj) { return equals_1(val, obj[name]); }); var propEq_1 = propEq; /** * Returns a partial copy of an object containing only the keys specified. If * the key does not exist, the property is ignored. * * @func * @memberOf R * @since v0.1.0 * @category