UNPKG

ruddy

Version:

Modularized state-management tools for modern front-end applications. Manage dispatched messages in a clean and predictable way for either small or large scale projects

1,804 lines (1,635 loc) 288 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global.ruddy = {}))); }(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; function _reduced(x) { return x && x['@@transducer/reduced'] ? x : { '@@transducer/value': x, '@@transducer/reduced': true }; } var _reduced_1 = _reduced; var XAll = /*#__PURE__*/function () { function XAll(f, xf) { this.xf = xf; this.f = f; this.all = true; } XAll.prototype['@@transducer/init'] = _xfBase.init; XAll.prototype['@@transducer/result'] = function (result) { if (this.all) { result = this.xf['@@transducer/step'](result, true); } return this.xf['@@transducer/result'](result); }; XAll.prototype['@@transducer/step'] = function (result, input) { if (!this.f(input)) { this.all = false; result = _reduced_1(this.xf['@@transducer/step'](result, false)); } return result; }; return XAll; }(); var _xall = /*#__PURE__*/_curry2_1(function _xall(f, xf) { return new XAll(f, xf); }); var _xall_1 = _xall; /** * Returns `true` if all elements of the list match the predicate, `false` if * there are any that don't. * * Dispatches to the `all` method of the second argument, if present. * * Acts as a transducer if a transformer is given in list position. * * @func * @memberOf R * @since v0.1.0 * @category List * @sig (a -> Boolean) -> [a] -> Boolean * @param {Function} fn The predicate function. * @param {Array} list The array to consider. * @return {Boolean} `true` if the predicate is satisfied by every element, `false` * otherwise. * @see R.any, R.none, R.transduce * @example * * var equals3 = R.equals(3); * R.all(equals3)([3, 3, 3, 3]); //=> true * R.all(equals3)([3, 3, 1, 3]); //=> false */ var all = /*#__PURE__*/_curry2_1( /*#__PURE__*/_dispatchable_1(['all'], _xall_1, function all(fn, list) { var idx = 0; while (idx < list.length) { if (!fn(list[idx])) { return false; } idx += 1; } return true; })); var all_1 = all; function _isFunction(x) { return Object.prototype.toString.call(x) === '[object Function]'; } var _isFunction_1 = _isFunction; /** * Returns `true` if both arguments are `true`; `false` otherwise. * * @func * @memberOf R * @since v0.1.0 * @category Logic * @sig a -> b -> a | b * @param {Any} a * @param {Any} b * @return {Any} the first argument if it is falsy, otherwise the second argument. * @see R.both * @example * * R.and(true, true); //=> true * R.and(true, false); //=> false * R.and(false, true); //=> false * R.and(false, false); //=> false */ var and = /*#__PURE__*/_curry2_1(function and(a, b) { return a && b; }); var and_1 = and; /** * Private `concat` function to merge two array-like objects. * * @private * @param {Array|Arguments} [set1=[]] An array-like object. * @param {Array|Arguments} [set2=[]] An array-like object. * @return {Array} A new, merged array. * @example * * _concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3] */ function _concat(set1, set2) { set1 = set1 || []; set2 = set2 || []; var idx; var len1 = set1.length; var len2 = set2.length; var result = []; idx = 0; while (idx < len1) { result[result.length] = set1[idx]; idx += 1; } idx = 0; while (idx < len2) { result[result.length] = set2[idx]; idx += 1; } return result; } var _concat_1 = _concat; /** * ap applies a list of functions to a list of values. * * Dispatches to the `ap` method of the second argument, if present. Also * treats curried functions as applicatives. * * @func * @memberOf R * @since v0.3.0 * @category Function * @sig [a -> b] -> [a] -> [b] * @sig Apply f => f (a -> b) -> f a -> f b * @sig (a -> b -> c) -> (a -> b) -> (a -> c) * @param {*} applyF * @param {*} applyX * @return {*} * @example * * R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6] * R.ap([R.concat('tasty '), R.toUpper], ['pizza', 'salad']); //=> ["tasty pizza", "tasty salad", "PIZZA", "SALAD"] * * // R.ap can also be used as S combinator * // when only two functions are passed * R.ap(R.concat, R.toUpper)('Ramda') //=> 'RamdaRAMDA' * @symb R.ap([f, g], [a, b]) = [f(a), f(b), g(a), g(b)] */ var ap = /*#__PURE__*/_curry2_1(function ap(applyF, applyX) { return typeof applyX['fantasy-land/ap'] === 'function' ? applyX['fantasy-land/ap'](applyF) : typeof applyF.ap === 'function' ? applyF.ap(applyX) : typeof applyF === 'function' ? function (x) { return applyF(x)(applyX(x)); } : // else _reduce_1(function (acc, f) { return _concat_1(acc, map_1(f, applyX)); }, [], applyF); }); var ap_1 = ap; /** * "lifts" a function to be the specified arity, so that it may "map over" that * many lists, Functions or other objects that satisfy the [FantasyLand Apply spec](https://github.com/fantasyland/fantasy-land#apply). * * @func * @memberOf R * @since v0.7.0 * @category Function * @sig Number -> (*... -> *) -> ([*]... -> [*]) * @param {Function} fn The function to lift into higher context * @return {Function} The lifted function. * @see R.lift, R.ap * @example * * var madd3 = R.liftN(3, (...args) => R.sum(args)); * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] */ var liftN = /*#__PURE__*/_curry2_1(function liftN(arity, fn) { var lifted = curryN_1(arity, fn); return curryN_1(arity, function () { return _reduce_1(ap_1, map_1(lifted, arguments[0]), Array.prototype.slice.call(arguments, 1)); }); }); var liftN_1 = liftN; /** * "lifts" a function of arity > 1 so that it may "map over" a list, Function or other * object that satisfies the [FantasyLand Apply spec](https://github.com/fantasyland/fantasy-land#apply). * * @func * @memberOf R * @since v0.7.0 * @category Function * @sig (*... -> *) -> ([*]... -> [*]) * @param {Function} fn The function to lift into higher context * @return {Function} The lifted function. * @see R.liftN * @example * * var madd3 = R.lift((a, b, c) => a + b + c); * * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] * * var madd5 = R.lift((a, b, c, d, e) => a + b + c + d + e); * * madd5([1,2], [3], [4, 5], [6], [7, 8]); //=> [21, 22, 22, 23, 22, 23, 23, 24] */ var lift = /*#__PURE__*/_curry1_1(function lift(fn) { return liftN_1(fn.length, fn); }); var lift_1 = lift; /** * A function which calls the two provided functions and returns the `&&` * of the results. * It returns the result of the first function if it is false-y and the result * of the second function otherwise. Note that this is short-circuited, * meaning that the second function will not be invoked if the first returns a * false-y value. * * In addition to functions, `R.both` also accepts any fantasy-land compatible * applicative functor. * * @func * @memberOf R * @since v0.12.0 * @category Logic * @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean) * @param {Function} f A predicate * @param {Function} g Another predicate * @return {Function} a function that applies its arguments to `f` and `g` and `&&`s their outputs together. * @see R.and * @example * * var gt10 = R.gt(R.__, 10) * var lt20 = R.lt(R.__, 20) * var f = R.both(gt10, lt20); * f(15); //=> true * f(30); //=> false */ var both = /*#__PURE__*/_curry2_1(function both(f, g) { return _isFunction_1(f) ? function _both() { return f.apply(this, arguments) && g.apply(this, arguments); } : lift_1(and_1)(f, g); }); var both_1 = both; /** * Applies a function to the value at the given index of an array, returning a * new copy of the array with the element at the given index replaced with the * result of the function application. * * @func * @memberOf R * @since v0.14.0 * @category List * @sig (a -> a) -> Number -> [a] -> [a] * @param {Function} fn The function to apply. * @param {Number} idx The index. * @param {Array|Arguments} list An array-like object whose value * at the supplied index will be replaced. * @return {Array} A copy of the supplied array-like object with * the element at index `idx` replaced with the value * returned by applying `fn` to the existing element. * @see R.update * @example * * R.adjust(R.add(10), 1, [1, 2, 3]); //=> [1, 12, 3] * R.adjust(R.add(10))(1)([1, 2, 3]); //=> [1, 12, 3] * @symb R.adjust(f, -1, [a, b]) = [a, f(b)] * @symb R.adjust(f, 0, [a, b]) = [f(a), b] */ var adjust = /*#__PURE__*/_curry3_1(function adjust(fn, idx, list) { if (idx >= list.length || idx < -list.length) { return list; } var start = idx < 0 ? list.length : 0; var _idx = start + idx; var _list = _concat_1(list); _list[_idx] = fn(list[_idx]); return _list; }); var adjust_1 = adjust; /** * 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 r