diff --git a/docs/dist/ramda.js b/docs/dist/ramda.js index 805eb3d..34a9254 100644 --- a/docs/dist/ramda.js +++ b/docs/dist/ramda.js @@ -1,6 +1,6 @@ -// Ramda v0.29.1 +// Ramda v0.30.0 // https://github.com/ramda/ramda -// (c) 2013-2023 Scott Sauyet, Michael Hurley, and David Chambers +// (c) 2013-2024 Scott Sauyet, Michael Hurley, and David Chambers // Ramda may be freely distributed under the MIT license. (function (global, factory) { @@ -47,53 +47,12 @@ return true; }; - /** - * A special placeholder value used to specify "gaps" within curried functions, - * allowing partial application of any combination of arguments, regardless of - * their positions. - * - * If `g` is a curried ternary function 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)(1, 3)` - * - `g(_, 2)(_, 3)(1)` - * - * @name __ - * @constant - * @memberOf R - * @since v0.6.0 - * @category Function - * @example - * - * const greet = R.replace('{name}', R.__, 'Hello, {name}!'); - * greet('Alice'); //=> 'Hello, Alice!' - */ - var __ = { + var _placeholder = { '@@functional/placeholder': true }; - function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - } - - return _typeof(obj); - } - function _isPlaceholder(a) { - return a != null && _typeof(a) === 'object' && a['@@functional/placeholder'] === true; + return a === _placeholder; } /** @@ -104,7 +63,6 @@ * @param {Function} fn The function to curry. * @return {Function} The curried function. */ - function _curry1(fn) { return function f1(a) { if (arguments.length === 0 || _isPlaceholder(a)) { @@ -123,18 +81,15 @@ * @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(a) ? f2 : _curry1(function (_b) { return fn(a, _b); }); - default: return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function (_a) { return fn(_a, b); @@ -162,7 +117,6 @@ * R.add(2, 3); //=> 5 * R.add(7)(10); //=> 17 */ - var add = _curry2(function add(a, b) { return Number(a) + Number(b); }); @@ -186,19 +140,15 @@ 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; } @@ -209,57 +159,46 @@ 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'); } @@ -275,7 +214,6 @@ * @param {Function} fn The function to curry. * @return {Function} The curried function. */ - function _curryN(length, received, fn) { return function () { var combined = []; @@ -283,28 +221,22 @@ var left = length; var combinedIdx = 0; var hasPlaceholder = false; - while (combinedIdx < received.length || argsIdx < arguments.length) { var result; - if (combinedIdx < received.length && (!_isPlaceholder(received[combinedIdx]) || argsIdx >= arguments.length)) { result = received[combinedIdx]; } else { result = arguments[argsIdx]; argsIdx += 1; } - combined[combinedIdx] = result; - if (!_isPlaceholder(result)) { left -= 1; } else { hasPlaceholder = true; } - combinedIdx += 1; } - return !hasPlaceholder && left <= 0 ? fn.apply(this, combined) : _arity(Math.max(0, left), _curryN(length, combined, fn)); }; } @@ -351,12 +283,10 @@ * const g = f(3); * g(4); //=> 10 */ - var curryN = _curry2(function curryN(length, fn) { if (length === 1) { return _curry1(fn); } - return _arity(length, _curryN(length, [], fn)); }); @@ -384,20 +314,17 @@ * mapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']); * //=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r'] */ - var addIndex = _curry1(function addIndex(fn) { return curryN(fn.length, function () { var idx = 0; var origFn = arguments[0]; var list = arguments[arguments.length - 1]; var args = Array.prototype.slice.call(arguments, 0); - args[0] = function () { var result = origFn.apply(this, _concat(arguments, [idx, list])); idx += 1; return result; }; - return fn.apply(this, args); }); }); @@ -424,20 +351,17 @@ * revmapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']); * //=> [ '5-r', '4-a', '3-b', '2-o', '1-o', '0-f' ] */ - var addIndexRight = _curry1(function addIndex(fn) { return curryN(fn.length, function () { var origFn = arguments[0]; var list = arguments[arguments.length - 1]; var idx = list.length - 1; var args = Array.prototype.slice.call(arguments, 0); - args[0] = function () { var result = origFn.apply(this, _concat(arguments, [idx, list])); idx -= 1; return result; }; - return fn.apply(this, args); }); }); @@ -450,18 +374,15 @@ * @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(a) ? f3 : _curry2(function (_b, _c) { return fn(a, _b, _c); }); - case 2: return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function (_a, _c) { return fn(_a, b, _c); @@ -470,7 +391,6 @@ }) : _curry1(function (_c) { return fn(a, b, _c); }); - default: return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function (_a, _b) { return fn(_a, _b, c); @@ -514,18 +434,13 @@ * @symb R.adjust(-1, f, [a, b]) = [a, f(b)] * @symb R.adjust(0, f, [a, b]) = [f(a), b] */ - var adjust = _curry3(function adjust(idx, fn, list) { var len = list.length; - if (idx >= len || idx < -len) { return list; } - var _idx = (len + idx) % len; - var _list = _concat(list); - _list[_idx] = fn(list[_idx]); return _list; }); @@ -565,32 +480,25 @@ * @param {Function} fn default ramda implementation * @return {Function} A function that dispatches on object in list position */ - function _dispatchable(methodNames, transducerCreator, fn) { return function () { if (arguments.length === 0) { return fn(); } - var obj = arguments[arguments.length - 1]; - if (!_isArray(obj)) { var idx = 0; - while (idx < methodNames.length) { if (typeof obj[methodNames[idx]] === 'function') { return obj[methodNames[idx]].apply(obj, Array.prototype.slice.call(arguments, 0, -1)); } - idx += 1; } - if (_isTransformer(obj)) { var transducer = transducerCreator.apply(null, Array.prototype.slice.call(arguments, 0, -1)); return transducer(obj); } } - return fn.apply(this, arguments); }; } @@ -616,26 +524,20 @@ 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(this.xf['@@transducer/step'](result, false)); } - return result; }; - function _xall(f) { return function (xf) { return new XAll(f, xf); @@ -666,44 +568,45 @@ * R.all(equals3)([3, 3, 3, 3]); //=> true * R.all(equals3)([3, 3, 1, 3]); //=> false */ - var all = _curry2(_dispatchable(['all'], _xall, function all(fn, list) { var idx = 0; - while (idx < list.length) { if (!fn(list[idx])) { return false; } - idx += 1; } - return true; })); + function _typeof(o) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { + return typeof o; + } : function (o) { + return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; + }, _typeof(o); + } + function _arrayFromIterator(iter) { var list = []; var next; - while (!(next = iter.next()).done) { list.push(next.value); } - return list; } function _includesWith(pred, x, list) { var idx = 0; var len = list.length; - while (idx < len) { if (pred(x, list[idx])) { return true; } - idx += 1; } - return false; } @@ -729,11 +632,9 @@ return a !== a && b !== b; } } - var _objectIs$1 = typeof Object.is === 'function' ? Object.is : _objectIs; var toString = Object.prototype.toString; - var _isArguments = function () { return toString.call(arguments) === '[object Arguments]' ? function _isArguments(x) { return toString.call(x) === '[object Arguments]'; @@ -742,29 +643,27 @@ }; }(); + // cover IE < 9 keys issues var hasEnumBug = !{ toString: null }.propertyIsEnumerable('toString'); - var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; // Safari bug - + var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; + // Safari bug var hasArgsEnumBug = function () { 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. @@ -783,40 +682,30 @@ * * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c'] */ - - var keys = typeof Object.keys === 'function' && !hasArgsEnumBug ? _curry1(function keys(obj) { return Object(obj) !== obj ? [] : Object.keys(obj); }) : _curry1(function keys(obj) { if (Object(obj) !== obj) { return []; } - var prop, nIdx; var ks = []; - var checkArgsLength = hasArgsEnumBug && _isArguments(obj); - for (prop in obj) { if (_has(prop, obj) && (!checkArgsLength || prop !== 'length')) { ks[ks.length] = prop; } } - if (hasEnumBug) { nIdx = nonEnumerableProps.length - 1; - while (nIdx >= 0) { prop = nonEnumerableProps[nIdx]; - if (_has(prop, obj) && !contains(ks, prop)) { ks[ks.length] = prop; } - nIdx -= 1; } } - return ks; }); @@ -845,8 +734,8 @@ * R.type(() => {}); //=> "Function" * R.type(async () => {}); //=> "AsyncFunction" * R.type(undefined); //=> "Undefined" + * R.type(BigInt(123)); //=> "BigInt" */ - var type = _curry1(function type(val) { return val === null ? 'Null' : val === undefined ? 'Undefined' : Object.prototype.toString.call(val).slice(8, -1); }); @@ -864,38 +753,30 @@ function _uniqContentEquals(aIterator, bIterator, stackA, stackB) { var a = _arrayFromIterator(aIterator); - var b = _arrayFromIterator(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* - + } + // if *a* array contains any element that is not included in *b* return !_includesWith(function (b, aItem) { return !_includesWith(eq, aItem, b); }, b, a); } - function _equals(a, b, stackA, stackB) { if (_objectIs$1(a, b)) { return true; } - var typeA = type(a); - if (typeA !== type(b)) { 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': @@ -903,61 +784,45 @@ if (typeof a.constructor === 'function' && _functionName(a.constructor) === 'Promise') { return a === b; } - break; - case 'Boolean': case 'Number': case 'String': if (!(_typeof(a) === _typeof(b) && _objectIs$1(a.valueOf(), b.valueOf()))) { return false; } - break; - case 'Date': if (!_objectIs$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': @@ -978,32 +843,24 @@ case 'Float64Array': case 'ArrayBuffer': break; - default: // Values of other types are only equal if identical. return false; } - var keysA = keys(a); - if (keysA.length !== keys(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(key, b) && _equals(b[key], a[key], extendedStackA, extendedStackB))) { return false; } - idx -= 1; } - return true; } @@ -1032,75 +889,61 @@ * const b = {}; b.v = b; * R.equals(a, b); //=> true */ - var equals = _curry2(function equals(a, b) { return _equals(a, b, [], []); }); function _indexOf(list, a, idx) { - var inf, item; // Array.prototype.indexOf doesn't exist below IE9 - + var inf, item; + // Array.prototype.indexOf doesn't exist below IE9 if (typeof list.indexOf === 'function') { switch (_typeof(a)) { case 'number': if (a === 0) { // manually crawl the list to distinguish between +0 and -0 inf = 1 / a; - while (idx < list.length) { item = list[idx]; - if (item === 0 && 1 / item === inf) { return idx; } - idx += 1; } - return -1; } else if (a !== a) { // NaN while (idx < list.length) { item = list[idx]; - if (typeof item === 'number' && item !== item) { return idx; } - idx += 1; } - return -1; - } // non-zero numbers can utilise Set - - + } + // non-zero numbers can utilise Set return list.indexOf(a, idx); - // all these types can utilise Set + // all these types can utilise Set case 'string': case 'boolean': case 'function': case 'undefined': return list.indexOf(a, idx); - case 'object': if (a === null) { // null can utilise Set return list.indexOf(a, idx); } - } - } // anything else not covered above, defer to R.equals - - + } + // anything else not covered above, defer to R.equals while (idx < list.length) { if (equals(list[idx], a)) { return idx; } - idx += 1; } - return -1; } @@ -1112,12 +955,10 @@ var idx = 0; var len = functor.length; var result = Array(len); - while (idx < len) { result[idx] = fn(functor[idx]); idx += 1; } - return result; } @@ -1133,7 +974,6 @@ var pad = function pad(n) { return (n < 10 ? '0' : '') + n; }; - var _toISOString = typeof Date.prototype.toISOString === 'function' ? function _toISOString(d) { return d.toISOString(); } : function _toISOString(d) { @@ -1149,12 +989,10 @@ function _arrayReduce(reducer, acc, list) { var index = 0; var length = list.length; - while (index < length) { acc = reducer(acc, list[index]); index += 1; } - return acc; } @@ -1162,15 +1000,12 @@ var idx = 0; var len = list.length; var result = []; - while (idx < len) { if (fn(list[idx])) { result[result.length] = list[idx]; } - idx += 1; } - return result; } @@ -1182,14 +1017,11 @@ this.xf = xf; this.f = f; } - XFilter.prototype['@@transducer/init'] = _xfBase.init; XFilter.prototype['@@transducer/result'] = _xfBase.result; - XFilter.prototype['@@transducer/step'] = function (result, input) { return this.f(input) ? this.xf['@@transducer/step'](result, input) : result; }; - function _xfilter(f) { return function (xf) { return new XFilter(f, xf); @@ -1224,15 +1056,14 @@ * * R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4} */ - var filter = _curry2(_dispatchable(['fantasy-land/filter', 'filter'], _xfilter, function (pred, filterable) { return _isObject(filterable) ? _arrayReduce(function (acc, key) { if (pred(filterable[key])) { acc[key] = filterable[key]; } - return acc; - }, {}, keys(filterable)) : // else + }, {}, keys(filterable)) : + // else _filter(pred, filterable); })); @@ -1260,7 +1091,6 @@ * * R.reject(isOdd, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4} */ - var reject = _curry2(function reject(pred, filterable) { return filter(_complement(pred), filterable); }); @@ -1269,57 +1099,44 @@ var recur = function recur(y) { var xs = seen.concat([x]); return _includes(y, xs) ? '' : _toString(y, xs); - }; // mapPairs :: (Object, [String]) -> [String] - + }; + // mapPairs :: (Object, [String]) -> [String] var mapPairs = function mapPairs(obj, keys) { return _map(function (k) { return _quote(k) + ': ' + recur(obj[k]); }, keys.slice().sort()); }; - switch (Object.prototype.toString.call(x)) { case '[object Arguments]': return '(function() { return arguments; }(' + _map(recur, x).join(', ') + '))'; - case '[object Array]': return '[' + _map(recur, x).concat(mapPairs(x, reject(function (k) { return /^\d+$/.test(k); }, keys(x)))).join(', ') + ']'; - case '[object Boolean]': return _typeof(x) === 'object' ? 'new Boolean(' + recur(x.valueOf()) + ')' : x.toString(); - case '[object Date]': return 'new Date(' + (isNaN(x.valueOf()) ? recur(NaN) : _quote(_toISOString(x))) + ')'; - case '[object Map]': return 'new Map(' + recur(Array.from(x)) + ')'; - case '[object Null]': return 'null'; - case '[object Number]': return _typeof(x) === 'object' ? 'new Number(' + recur(x.valueOf()) + ')' : 1 / x === -Infinity ? '-0' : x.toString(10); - case '[object Set]': return 'new Set(' + recur(Array.from(x).sort()) + ')'; - case '[object String]': return _typeof(x) === 'object' ? 'new String(' + recur(x.valueOf()) + ')' : _quote(x); - case '[object Undefined]': return 'undefined'; - default: if (typeof x.toString === 'function') { var repr = x.toString(); - if (repr !== '[object Object]') { return repr; } } - return '{' + mapPairs(x, keys(x)).join(', ') + '}'; } } @@ -1360,7 +1177,6 @@ * R.toString({foo: 1, bar: 2, baz: 3}); //=> '{"bar": 2, "baz": 3, "foo": 1}' * R.toString(new Date('2001-02-03T04:05:06Z')); //=> 'new Date("2001-02-03T04:05:06.000Z")' */ - var toString$1 = _curry1(function toString(val) { return _toString(val, []); }); @@ -1382,39 +1198,29 @@ * R.max(789, 123); //=> 789 * R.max('a', 'b'); //=> 'b' */ - var max = _curry2(function max(a, b) { if (a === b) { return b; } - function safeMax(x, y) { if (x > y !== y > x) { return y > x ? y : x; } - return undefined; } - var maxByValue = safeMax(a, b); - if (maxByValue !== undefined) { return maxByValue; } - var maxByType = safeMax(_typeof(a), _typeof(b)); - if (maxByType !== undefined) { return maxByType === _typeof(a) ? a : b; } - var stringA = toString$1(a); var maxByStringValue = safeMax(stringA, toString$1(b)); - if (maxByStringValue !== undefined) { return maxByStringValue === stringA ? a : b; } - return b; }); @@ -1422,14 +1228,11 @@ 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)); }; - var _xmap = function _xmap(f) { return function (xf) { return new XMap(f, xf); @@ -1471,20 +1274,17 @@ * @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 = _curry2(_dispatchable(['fantasy-land/map', 'map'], _xmap, function map(fn, functor) { switch (Object.prototype.toString.call(functor)) { case '[object Function]': return curryN(functor.length, function () { return fn.call(this, functor.apply(this, arguments)); }); - case '[object Object]': return _arrayReduce(function (acc, key) { acc[key] = fn(functor[key]); return acc; }, {}, keys(functor)); - default: return _map(fn, functor); } @@ -1506,37 +1306,10 @@ return Object.prototype.toString.call(x) === '[object String]'; } - /** - * Returns the nth element of the given list or string. If n is negative the - * element at index length + n is returned. - * - * @func - * @memberOf R - * @since v0.1.0 - * @category List - * @sig Number -> [a] -> a | Undefined - * @sig Number -> String -> String - * @param {Number} offset - * @param {*} list - * @return {*} - * @example - * - * const list = ['foo', 'bar', 'baz', 'quux']; - * R.nth(1, list); //=> 'bar' - * R.nth(-1, list); //=> 'quux' - * R.nth(-99, list); //=> undefined - * - * R.nth(2, 'abc'); //=> 'c' - * R.nth(3, 'abc'); //=> '' - * @symb R.nth(-1, [a, b, c]) = c - * @symb R.nth(0, [a, b, c]) = a - * @symb R.nth(1, [a, b, c]) = b - */ - - var nth = _curry2(function nth(offset, list) { + function _nth(offset, list) { var idx = offset < 0 ? list.length + offset : offset; return _isString(list) ? list.charAt(idx) : list[idx]; - }); + } /** * Returns a function that when supplied an object returns the indicated @@ -1564,8 +1337,7 @@ if (obj == null) { return; } - - return _isInteger(p) ? nth(p, obj) : obj[p]; + return _isInteger(p) ? _nth(p, obj) : obj[p]; }); /** @@ -1595,7 +1367,6 @@ * @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 = _curry2(function pluck(p, list) { return map(prop(p), list); }); @@ -1618,32 +1389,25 @@ * _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true * _isArrayLike({nodeType: 1, length: 1}) // => false */ - var _isArrayLike = _curry1(function isArrayLike(x) { if (_isArray(x)) { return true; } - if (!x) { return false; } - if (_typeof(x) !== 'object') { return false; } - if (_isString(x)) { return false; } - if (x.length === 0) { return true; } - if (x.length > 0) { return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1); } - return false; }); @@ -1653,27 +1417,21 @@ if (_isArrayLike(list)) { return arrayReduce(xf, acc, list); } - if (list == null) { return acc; } - if (typeof list['fantasy-land/reduce'] === 'function') { return methodReduce(xf, acc, list, 'fantasy-land/reduce'); } - if (list[symIterator] != null) { return iterableReduce(xf, acc, list[symIterator]()); } - if (typeof list.next === 'function') { return iterableReduce(xf, acc, list); } - if (typeof list.reduce === 'function') { return methodReduce(xf, acc, list, 'reduce'); } - throw new TypeError('reduce: list must be array or iterable'); }; } @@ -1681,18 +1439,14 @@ function _xArrayReduce(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); } @@ -1718,7 +1472,6 @@ * // logs {a: 2} * @symb R.bind(f, o)(a, b) = f.call(o, a, b) */ - var bind = _curry2(function bind(fn, thisObj) { return _arity(fn.length, function () { return fn.apply(thisObj, arguments); @@ -1727,43 +1480,33 @@ function _xIterableReduce(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 _xMethodReduce(xf, acc, obj, methodName) { return xf['@@transducer/result'](obj[methodName](bind(xf['@@transducer/step'], xf), acc)); } - var _xReduce = _createReduce(_xArrayReduce, _xMethodReduce, _xIterableReduce); 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); }; - function _xwrap(fn) { return new XWrap(fn); } @@ -1820,7 +1563,6 @@ * * @symb R.reduce(f, a, [b, c, d]) = f(f(f(a, b), c), d) */ - var reduce = _curry3(function (xf, acc, list) { return _xReduce(typeof xf === 'function' ? _xwrap(xf) : xf, acc, list); }); @@ -1850,20 +1592,16 @@ * isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false * isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true */ - var allPass = _curry1(function allPass(preds) { return curryN(reduce(max, 0, pluck('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; }); }); @@ -1887,7 +1625,6 @@ * const t = R.always('Tee'); * t(); //=> 'Tee' */ - var always = _curry1(function always(val) { return function () { return val; @@ -1914,7 +1651,6 @@ * R.and(false, true); //=> false * R.and(false, false); //=> false */ - var and = _curry2(function and(a, b) { return a && b; }); @@ -1924,26 +1660,20 @@ this.f = f; this.any = false; } - XAny.prototype['@@transducer/init'] = _xfBase.init; - XAny.prototype['@@transducer/result'] = function (result) { if (!this.any) { result = this.xf['@@transducer/step'](result, false); } - return this.xf['@@transducer/result'](result); }; - XAny.prototype['@@transducer/step'] = function (result, input) { if (this.f(input)) { this.any = true; result = _reduced(this.xf['@@transducer/step'](result, true)); } - return result; }; - function _xany(f) { return function (xf) { return new XAny(f, xf); @@ -1975,18 +1705,14 @@ * R.any(lessThan0)([1, 2]); //=> false * R.any(lessThan2)([1, 2]); //=> true */ - var any = _curry2(_dispatchable(['any'], _xany, function any(fn, list) { var idx = 0; - while (idx < list.length) { if (fn(list[idx])) { return true; } - idx += 1; } - return false; })); @@ -2016,39 +1742,31 @@ * isBlackCard({rank: 'Q', suit: '♠'}); //=> true * isBlackCard({rank: 'Q', suit: '♦'}); //=> false */ - var anyPass = _curry1(function anyPass(preds) { return curryN(reduce(max, 0, pluck('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; }); }); function _iterableReduce(reducer, acc, iter) { var step = iter.next(); - while (!step.done) { acc = reducer(acc, step.value); step = iter.next(); } - return acc; } - function _methodReduce(reducer, acc, obj, methodName) { return obj[methodName](reducer, acc); } - var _reduce = _createReduce(_arrayReduce, _methodReduce, _iterableReduce); /** @@ -2077,7 +1795,6 @@ * 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 = _curry2(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)); @@ -2090,12 +1807,10 @@ var idx = 0; var limit = list.length - (n - 1); var acc = new Array(limit >= 0 ? limit : 0); - while (idx < limit) { acc[idx] = Array.prototype.slice.call(list, idx, idx + n); idx += 1; } - return acc; } @@ -2105,33 +1820,26 @@ this.full = false; this.acc = new Array(n); } - XAperture.prototype['@@transducer/init'] = _xfBase.init; - XAperture.prototype['@@transducer/result'] = function (result) { this.acc = null; return this.xf['@@transducer/result'](result); }; - XAperture.prototype['@@transducer/step'] = function (result, input) { this.store(input); return this.full ? this.xf['@@transducer/step'](result, this.getCopy()) : result; }; - XAperture.prototype.store = function (input) { this.acc[this.pos] = input; this.pos += 1; - if (this.pos === this.acc.length) { this.pos = 0; this.full = true; } }; - XAperture.prototype.getCopy = function () { return _concat(Array.prototype.slice.call(this.acc, this.pos), Array.prototype.slice.call(this.acc, 0, this.pos)); }; - function _xaperture(n) { return function (xf) { return new XAperture(n, xf); @@ -2159,7 +1867,6 @@ * R.aperture(3, [1, 2, 3, 4, 5]); //=> [[1, 2, 3], [2, 3, 4], [3, 4, 5]] * R.aperture(7, [1, 2, 3, 4, 5]); //=> [] */ - var aperture = _curry2(_dispatchable([], _xaperture, _aperture)); /** @@ -2182,7 +1889,6 @@ * R.append('tests', []); //=> ['tests'] * R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']] */ - var append = _curry2(function append(el, list) { return _concat(list, [el]); }); @@ -2207,7 +1913,6 @@ * R.apply(Math.max, nums); //=> 42 * @symb R.apply(f, [a, b, c]) = f(a, b, c) */ - var apply = _curry2(function apply(fn, args) { return fn.apply(this, args); }); @@ -2229,29 +1934,27 @@ * * R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3] */ - var values = _curry1(function values(obj) { var props = keys(obj); var len = props.length; var vals = []; var idx = 0; - while (idx < len) { vals[idx] = obj[props[idx]]; idx += 1; } - return vals; }); + // Use custom mapValues function to avoid issues with specs that include a "map" key and R.map // delegating calls to .map - function mapValues(fn, obj) { return _isArray(obj) ? obj.map(fn) : keys(obj).reduce(function (acc, key) { acc[key] = fn(obj[key]); return acc; }, {}); } + /** * Given a spec object recursively mapping properties to functions, creates a * function producing an object of the same structure, by mapping each property @@ -2277,8 +1980,6 @@ * 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 = _curry1(function applySpec(spec) { spec = mapValues(function (v) { return typeof v == 'function' ? v : applySpec(v); @@ -2310,7 +2011,6 @@ * t42(R.identity); //=> 42 * t42(R.add(1)); //=> 43 */ - var applyTo = _curry2(function applyTo(x, f) { return f(x); }); @@ -2340,7 +2040,6 @@ * const peopleByYoungestFirst = R.sort(byAge, people); * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }] */ - var ascend = _curry3(function ascend(fn, a, b) { var aa = fn(a); var bb = fn(b); @@ -2359,20 +2058,16 @@ * @param {Object|Array} obj The object to clone * @return {Object|Array} A new object equivalent to the original except for the changed property. */ - function _assoc(prop, val, obj) { if (_isInteger(prop) && _isArray(obj)) { var arr = [].concat(obj); arr[prop] = val; return arr; } - var result = {}; - for (var p in obj) { result[p] = obj[p]; } - result[prop] = val; return result; } @@ -2394,7 +2089,6 @@ * R.isNil(0); //=> false * R.isNil([]); //=> false */ - var isNil = _curry1(function isNil(x) { return x == null; }); @@ -2423,19 +2117,15 @@ * // 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 = _curry3(function assocPath(path, val, obj) { if (path.length === 0) { return val; } - var idx = path[0]; - if (path.length > 1) { var nextObj = !isNil(obj) && _has(idx, obj) && _typeof(obj[idx]) === 'object' ? obj[idx] : _isInteger(path[1]) ? [] : {}; val = assocPath(Array.prototype.slice.call(path, 1), val, nextObj); } - return _assoc(idx, val, obj); }); @@ -2460,7 +2150,6 @@ * * R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3} */ - var assoc = _curry3(function assoc(prop, val, obj) { return assocPath([prop], val, obj); }); @@ -2495,64 +2184,52 @@ * @symb R.nAry(1, f)(a, b) = f(a) * @symb R.nAry(2, f)(a, b) = f(a, b) */ - var nAry = _curry2(function nAry(n, fn) { switch (n) { case 0: return function () { return fn.call(this); }; - case 1: return function (a0) { return fn.call(this, a0); }; - case 2: return function (a0, a1) { return fn.call(this, a0, a1); }; - case 3: return function (a0, a1, a2) { return fn.call(this, a0, a1, a2); }; - case 4: return function (a0, a1, a2, a3) { return fn.call(this, a0, a1, a2, a3); }; - case 5: return function (a0, a1, a2, a3, a4) { return fn.call(this, a0, a1, a2, a3, a4); }; - case 6: return function (a0, a1, a2, a3, a4, a5) { return fn.call(this, a0, a1, a2, a3, a4, a5); }; - case 7: return function (a0, a1, a2, a3, a4, a5, a6) { return fn.call(this, a0, a1, a2, a3, a4, a5, a6); }; - case 8: return function (a0, a1, a2, a3, a4, a5, a6, a7) { return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7); }; - case 9: return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7, a8); }; - case 10: return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }; - default: throw new Error('First argument to nAry must be a non-negative integer no greater than ten'); } @@ -2586,7 +2263,6 @@ * takesTwoArgs(1, 2, 3); //=> [1, 2, undefined] * @symb R.binary(f)(a, b, c) = f(a, b) */ - var binary = _curry1(function binary(fn) { return nAry(2, fn); }); @@ -2613,7 +2289,6 @@ * const 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 = _curry2(function liftN(arity, fn) { var lifted = curryN(arity, fn); return curryN(arity, function () { @@ -2643,7 +2318,6 @@ * * madd5([10, 20], [1], [2, 3], [4], [100, 200]); //=> [117, 217, 118, 218, 127, 227, 128, 228] */ - var lift = _curry1(function lift(fn) { return liftN(fn.length, fn); }); @@ -2679,7 +2353,6 @@ * R.both(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(false) * R.both([false, false, 'a'], [11]); //=> [false, false, 11] */ - var both = _curry2(function both(f, g) { return _isFunction(f) ? function _both() { return f.apply(this, arguments) && g.apply(this, arguments); @@ -2723,7 +2396,6 @@ * 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 = _curry1(function call(fn) { return fn.apply(this, Array.prototype.slice.call(arguments, 1)); }); @@ -2734,20 +2406,17 @@ * * @private */ - function _makeFlat(recursive) { return function flatt(list) { var value, jlen, j; var result = []; var idx = 0; var ilen = list.length; - while (idx < ilen) { if (_isArrayLike(list[idx])) { value = recursive ? flatt(list[idx]) : list[idx]; j = 0; jlen = value.length; - while (j < jlen) { result[result.length] = value[j]; j += 1; @@ -2755,10 +2424,8 @@ } else { result[result.length] = list[idx]; } - idx += 1; } - return result; }; } @@ -2773,30 +2440,23 @@ var tInit = '@@transducer/init'; var tStep = '@@transducer/step'; var tResult = '@@transducer/result'; - function XPreservingReduced(xf) { this.xf = xf; } - XPreservingReduced.prototype[tInit] = _xfBase.init; XPreservingReduced.prototype[tResult] = _xfBase.result; - XPreservingReduced.prototype[tStep] = function (result, input) { var ret = this.xf[tStep](result, input); return ret['@@transducer/reduced'] ? _forceReduced(ret) : ret; }; - function XFlatCat(xf) { this.xf = new XPreservingReduced(xf); } - XFlatCat.prototype[tInit] = _xfBase.init; XFlatCat.prototype[tResult] = _xfBase.result; - XFlatCat.prototype[tStep] = function (result, input) { return !_isArrayLike(input) ? _xArrayReduce(this.xf, result, [input]) : _xReduce(this.xf, result, input); }; - var _flatCat = function _xcat(xf) { return new XFlatCat(xf); }; @@ -2833,14 +2493,12 @@ * * R.chain(R.append, R.head)([1, 2, 3]); //=> [1, 2, 3, 1] */ - var chain = _curry2(_dispatchable(['fantasy-land/chain', 'chain'], _xchain, function chain(fn, monad) { if (typeof monad === 'function') { return function (x) { return fn(monad(x))(x); }; } - return _makeFlat(false)(map(fn, monad)); })); @@ -2864,12 +2522,10 @@ * R.clamp(1, 10, 15) // => 10 * R.clamp(1, 10, 4) // => 4 */ - var clamp = _curry3(function clamp(min, max, value) { if (min > max) { throw new Error('min must not be greater than max in clamp(min, max, value)'); } - return value < min ? min : value > max ? max : value; }); @@ -2885,46 +2541,36 @@ * @param {Boolean} deep Whether or not to perform deep cloning. * @return {*} The copied value. */ - function _clone(value, deep, map) { - map || (map = new _ObjectMap()); // this avoids the slower switch with a quick if decision removing some milliseconds in each run. + map || (map = new _ObjectMap()); + // this avoids the slower switch with a quick if decision removing some milliseconds in each run. if (_isPrimitive(value)) { return value; } - var copy = function copy(copiedValue) { // Check for circular and same references on the object graph and return its corresponding clone. var cachedCopy = map.get(value); - if (cachedCopy) { return cachedCopy; } - map.set(value, copiedValue); - for (var key in value) { if (Object.prototype.hasOwnProperty.call(value, key)) { copiedValue[key] = deep ? _clone(value[key], true, map) : value[key]; } } - return copiedValue; }; - switch (type(value)) { case 'Object': return copy(Object.create(Object.getPrototypeOf(value))); - case 'Array': - return copy([]); - + return copy(Array(value.length)); case 'Date': return new Date(value.valueOf()); - case 'RegExp': return _cloneRegExp(value); - case 'Int8Array': case 'Uint8Array': case 'Uint8ClampedArray': @@ -2937,45 +2583,34 @@ case 'BigInt64Array': case 'BigUint64Array': return value.slice(); - default: return value; } } - function _isPrimitive(param) { var type = _typeof(param); - return param == null || type != 'object' && type != 'function'; } - function _ObjectMap() { this.map = {}; this.length = 0; } - _ObjectMap.prototype.set = function (key, value) { var hashedKey = this.hash(key); var bucket = this.map[hashedKey]; - if (!bucket) { this.map[hashedKey] = bucket = []; } - bucket.push([key, value]); this.length += 1; }; - _ObjectMap.prototype.hash = function (key) { var hashedKey = []; - for (var value in key) { hashedKey.push(Object.prototype.toString.call(key[value])); } - return hashedKey.join(); }; - _ObjectMap.prototype.get = function (key) { /** * depending on the number of objects to be cloned is faster to just iterate over the items in the map just because the hash function is so costly, @@ -2983,32 +2618,25 @@ */ if (this.length <= 180) { for (var p in this.map) { - var _bucket = this.map[p]; - - for (var i = 0; i < _bucket.length; i += 1) { - var element = _bucket[i]; - + var bucket = this.map[p]; + for (var i = 0; i < bucket.length; i += 1) { + var element = bucket[i]; if (element[0] === key) { return element[1]; } } } - return; } - var hashedKey = this.hash(key); var bucket = this.map[hashedKey]; - if (!bucket) { return; } - - for (var _i = 0; _i < bucket.length; _i += 1) { - var _element = bucket[_i]; - - if (_element[0] === key) { - return _element[1]; + for (var i = 0; i < bucket.length; i += 1) { + var element = bucket[i]; + if (element[0] === key) { + return element[1]; } } }; @@ -3040,7 +2668,6 @@ * objects === objectsClone; //=> false * objects[0] === objectsClone[0]; //=> false */ - var clone = _curry1(function clone(value) { return value != null && typeof value.clone === 'function' ? value.clone() : _clone(value, true); }); @@ -3076,25 +2703,19 @@ * // {type: 'lunch', item: '🍕'} ], * // [ {type: 'dinner', item: '🍝'} ] ] */ - var collectBy = _curry2(function collectBy(fn, list) { var group = _reduce(function (o, x) { var tag = fn(x); - if (o[tag] === undefined) { o[tag] = []; } - o[tag].push(x); return o; }, {}, list); - var newList = []; - for (var tag in group) { newList.push(group[tag]); } - return newList; }); @@ -3121,7 +2742,6 @@ * const peopleByIncreasingAge = R.sort(byAge, people); * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }] */ - var comparator = _curry1(function comparator(pred) { return function (a, b) { return pred(a, b) ? -1 : pred(b, a) ? 1 : 0; @@ -3147,7 +2767,6 @@ * R.not(0); //=> true * R.not(1); //=> false */ - var not = _curry1(function not(a) { return !a; }); @@ -3174,7 +2793,6 @@ * R.isNil(7); //=> false * isNotNil(7); //=> true */ - var complement = lift(not); function _pipe(f, g) { @@ -3193,15 +2811,12 @@ * @param {String} methodname property to check for a custom implementation * @return {Object} Whatever the return value of the method is. */ - function _checkForMethod(methodname, fn) { return function () { var length = arguments.length; - if (length === 0) { return fn(); } - var obj = arguments[length - 1]; return _isArray(obj) || typeof obj[methodname] !== 'function' ? fn.apply(this, arguments) : obj[methodname].apply(obj, Array.prototype.slice.call(arguments, 0, length - 1)); }; @@ -3231,7 +2846,6 @@ * R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c'] * R.slice(0, 3, 'ramda'); //=> 'ram' */ - var slice = _curry3(_checkForMethod('slice', function slice(fromIndex, toIndex, list) { return Array.prototype.slice.call(list, fromIndex, toIndex); })); @@ -3263,7 +2877,6 @@ * R.tail('a'); //=> '' * R.tail(''); //=> '' */ - var tail = _curry1(_checkForMethod('tail', slice(1, Infinity))); /** @@ -3290,12 +2903,10 @@ * @symb R.pipe(f, g, h)(a, b) = h(g(f(a, b))) * @symb R.pipe(f, g, h)(a)(b) = h(g(f(a)))(b) */ - function pipe() { if (arguments.length === 0) { throw new Error('pipe requires at least one argument'); } - return _arity(arguments[0].length, reduce(_pipe, arguments[0], tail(arguments))); } @@ -3323,7 +2934,6 @@ * R.reverse('a'); //=> 'a' * R.reverse(''); //=> '' */ - var reverse = _curry1(function reverse(list) { return _isString(list) ? list.split('').reverse().join('') : Array.prototype.slice.call(list, 0).reverse(); }); @@ -3353,12 +2963,10 @@ * @symb R.compose(f, g, h)(a, b) = f(g(h(a, b))) * @symb R.compose(f, g, h)(a)(b) = f(g(h(a)))(b) */ - function compose() { if (arguments.length === 0) { throw new Error('compose requires at least one argument'); } - return pipe.apply(this, reverse(arguments)); } @@ -3383,8 +2991,9 @@ * R.head('abc'); //=> 'a' * R.head(''); //=> '' */ - - var head = nth(0); + var head = _curry1(function (list) { + return _nth(0, list); + }); function _identity(x) { return x; @@ -3409,7 +3018,6 @@ * R.identity(obj) === obj; //=> true * @symb R.identity(a) = a */ - var identity = _curry1(_identity); /** @@ -3436,12 +3044,10 @@ * f(3, 4); // -(3^4) + 1 * @symb R.pipeWith(f)([g, h, i])(...args) = f(i, f(h, g(...args))) */ - var pipeWith = _curry2(function pipeWith(xf, list) { if (list.length <= 0) { return identity; } - var headList = head(list); var tailList = tail(list); return _arity(headList.length, function () { @@ -3476,7 +3082,6 @@ * * @symb R.composeWith(f)([g, h, i])(...args) = f(g, f(h, i(...args))) */ - var composeWith = _curry2(function composeWith(xf, list) { return pipeWith.apply(this, [xf, reverse(list)]); }); @@ -3509,32 +3114,25 @@ * R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3] * R.concat([], []); //=> [] */ - var concat = _curry2(function concat(a, b) { if (_isArray(a)) { if (_isArray(b)) { return a.concat(b); } - throw new TypeError(toString$1(b) + ' is not an array'); } - if (_isString(a)) { if (_isString(b)) { return a + b; } - throw new TypeError(toString$1(b) + ' is not a string'); } - if (a != null && _isFunction(a['fantasy-land/concat'])) { return a['fantasy-land/concat'](b); } - if (a != null && _isFunction(a.concat)) { return a.concat(b); } - throw new TypeError(toString$1(a) + ' does not have a method named "concat" or "fantasy-land/concat"'); }); @@ -3569,19 +3167,16 @@ * fn(50); //=> 'nothing special happens at 50°C' * fn(100); //=> 'water boils at 100°C' */ - var cond = _curry1(function cond(pairs) { var arity = reduce(max, 0, map(function (pair) { return pair[0].length; }, pairs)); return _arity(arity, function () { var idx = 0; - while (idx < pairs.length) { if (pairs[idx][0].apply(this, arguments)) { return pairs[idx][1].apply(this, arguments); } - idx += 1; } }); @@ -3634,7 +3229,6 @@ * const h = R.curry((a, b, c = 2) => a + b + c); * h(1)(2)(7); //=> Error! (`3` is not a function!) */ - var curry = _curry1(function curry(fn) { return curryN(fn.length, fn); }); @@ -3674,47 +3268,35 @@ * // Add a dollop of Potato Chips * // Add a dollop of Ketchup */ - var constructN = _curry2(function constructN(n, Fn) { if (n > 10) { throw new Error('Constructor with greater than ten arguments'); } - if (n === 0) { return function () { return new Fn(); }; } - return curry(nAry(n, function ($0, $1, $2, $3, $4, $5, $6, $7, $8, $9) { switch (n) { case 1: return new Fn($0); - case 2: return new Fn($0, $1); - case 3: return new Fn($0, $1, $2); - case 4: return new Fn($0, $1, $2, $3); - case 5: return new Fn($0, $1, $2, $3, $4); - case 6: return new Fn($0, $1, $2, $3, $4, $5); - case 7: return new Fn($0, $1, $2, $3, $4, $5, $6); - case 8: return new Fn($0, $1, $2, $3, $4, $5, $6, $7); - case 9: return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8); - case 10: return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8, $9); } @@ -3753,7 +3335,6 @@ * const sightNewAnimal = R.compose(animalSighting, AnimalConstructor); * R.map(sightNewAnimal, animalTypes); //=> ["It's a Lion!", "It's a Tiger!", "It's a Bear!"] */ - var construct = _curry1(function construct(Fn) { return constructN(Fn.length, Fn); }); @@ -3786,7 +3367,6 @@ * * @symb R.converge(f, [g, h])(a, b) = f(g(a, b), h(a, b)) */ - var converge = _curry2(function converge(after, fns) { return curryN(reduce(max, 0, pluck('length', fns)), function () { var args = arguments; @@ -3814,7 +3394,6 @@ * R.count(even, [1, 2, 3, 4, 5]); // => 2 * R.map(R.count(even), [[1, 1, 1], [2, 3, 4, 5], [6]]); // => [0, 2, 1] */ - var count = curry(function (pred, list) { return _reduce(function (a, e) { return pred(e) ? a + 1 : a; @@ -3828,34 +3407,27 @@ this.xf = xf; this.inputs = {}; } - XReduceBy.prototype['@@transducer/init'] = _xfBase.init; - XReduceBy.prototype['@@transducer/result'] = function (result) { var key; - for (key in this.inputs) { if (_has(key, this.inputs)) { result = this.xf['@@transducer/step'](result, this.inputs[key]); - if (result['@@transducer/reduced']) { result = result['@@transducer/value']; break; } } } - this.inputs = null; return this.xf['@@transducer/result'](result); }; - XReduceBy.prototype['@@transducer/step'] = function (result, input) { var key = this.keyFn(input); this.inputs[key] = this.inputs[key] || [key, _clone(this.valueAcc, false)]; this.inputs[key][1] = this.valueFn(this.inputs[key][1], input); return result; }; - function _xreduceBy(valueFn, valueAcc, keyFn) { return function (xf) { return new XReduceBy(valueFn, valueAcc, keyFn, xf); @@ -3906,20 +3478,16 @@ * reduceBy(groupNames, [], toGrade, students) * //=> {"A": ["Dora"], "B": ["Abby", "Curt"], "F": ["Bart"]} */ - var reduceBy = _curryN(4, [], _dispatchable([], _xreduceBy, function reduceBy(valueFn, valueAcc, keyFn, list) { var xf = _xwrap(function (acc, elt) { var key = keyFn(elt); var value = valueFn(_has(key, acc) ? acc[key] : _clone(valueAcc, false), elt); - if (value && value['@@transducer/reduced']) { return _reduced(acc); } - acc[key] = value; return acc; }); - return _xReduce(xf, {}, list); })); @@ -3947,7 +3515,6 @@ * const letters = ['a', 'b', 'A', 'a', 'B', 'c']; * R.countBy(R.toLower)(letters); //=> {'a': 3, 'b': 2, 'c': 1} */ - var countBy = reduceBy(function (acc, elem) { return acc + 1; }, 0); @@ -3967,7 +3534,6 @@ * * R.dec(42); //=> 41 */ - var dec = add(-1); /** @@ -3993,7 +3559,6 @@ * // parseInt('string') results in NaN * defaultTo42(parseInt('string')); //=> 42 */ - var defaultTo = _curry2(function defaultTo(d, v) { return v == null || v !== v ? d : v; }); @@ -4023,7 +3588,6 @@ * const peopleByOldestFirst = R.sort(byAge, people); * //=> [{ name: 'Peter', age: 78 }, { name: 'Emma', age: 70 }, { name: 'Mikhail', age: 62 }] */ - var descend = _curry3(function descend(fn, a, b) { var aa = fn(a); var bb = fn(b); @@ -4034,23 +3598,25 @@ /* globals Set */ this._nativeSet = typeof Set === 'function' ? new Set() : null; this._items = {}; - } // until we figure out why jsdoc chokes on this + } + + // until we figure out why jsdoc chokes on this // @param item The item to add to the Set // @returns {boolean} true if the item did not exist prior, otherwise false // - - _Set.prototype.add = function (item) { return !hasOrAdd(item, true, this); - }; // + }; + + // // @param item The item to check for existence in the Set // @returns {boolean} true if the item exists in the Set, otherwise false // - - _Set.prototype.has = function (item) { return hasOrAdd(item, false, this); - }; // + }; + + // // Combines the logic for checking whether an item is a member of the set and // for adding a new item to the set. // @@ -4060,13 +3626,9 @@ // @param set The set instance to check or add to. // @return {boolean} true if the item already existed, otherwise false. // - - function hasOrAdd(item, shouldAdd, set) { var type = _typeof(item); - var prevSize, newSize; - switch (type) { case 'string': case 'number': @@ -4078,18 +3640,14 @@ if (shouldAdd) { set._items['-0'] = true; } - return false; - } - } // these types can all utilise the native Set - - + } + } + // these types can all utilise the native Set if (set._nativeSet !== null) { if (shouldAdd) { prevSize = set._nativeSet.size; - set._nativeSet.add(item); - newSize = set._nativeSet.size; return newSize === prevSize; } else { @@ -4101,7 +3659,6 @@ set._items[type] = {}; set._items[type][item] = true; } - return false; } else if (item in set._items[type]) { return true; @@ -4109,42 +3666,34 @@ if (shouldAdd) { set._items[type][item] = true; } - return false; } } - case 'boolean': // set._items['boolean'] holds a two element array // representing [ falseExists, trueExists ] if (type in set._items) { var bIdx = item ? 1 : 0; - if (set._items[type][bIdx]) { return true; } else { if (shouldAdd) { set._items[type][bIdx] = true; } - return false; } } else { if (shouldAdd) { set._items[type] = item ? [false, true] : [true, false]; } - return false; } - case 'function': // compare functions for reference equality if (set._nativeSet !== null) { if (shouldAdd) { prevSize = set._nativeSet.size; - set._nativeSet.add(item); - newSize = set._nativeSet.size; return newSize === prevSize; } else { @@ -4155,21 +3704,16 @@ if (shouldAdd) { set._items[type] = [item]; } - return false; } - if (!_includes(item, set._items[type])) { if (shouldAdd) { set._items[type].push(item); } - return false; } - return true; } - case 'undefined': if (set._items[type]) { return true; @@ -4177,50 +3721,39 @@ if (shouldAdd) { set._items[type] = true; } - return false; } - case 'object': if (item === null) { if (!set._items['null']) { if (shouldAdd) { set._items['null'] = true; } - return false; } - return true; } - /* falls through */ - default: // reduce the search size of heterogeneous sets by creating buckets // for each type. type = Object.prototype.toString.call(item); - if (!(type in set._items)) { if (shouldAdd) { set._items[type] = [item]; } - return false; - } // scan through all previously applied items - - + } + // scan through all previously applied items if (!_includes(item, set._items[type])) { if (shouldAdd) { set._items[type].push(item); } - return false; } - return true; } - } // A simple Set type that honours R.equals semantics + } /** * Finds the set (i.e. no duplicates) of all elements in the first list not @@ -4242,26 +3775,21 @@ * R.difference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5] * R.difference([{a: 1}, {b: 2}], [{a: 1}, {c: 3}]) //=> [{b: 2}] */ - var difference = _curry2(function difference(first, second) { var out = []; var idx = 0; var firstLen = first.length; var secondLen = second.length; var toFilterOut = new _Set(); - for (var i = 0; i < secondLen; i += 1) { toFilterOut.add(second[i]); } - while (idx < firstLen) { if (toFilterOut.add(first[idx])) { out[out.length] = first[idx]; } - idx += 1; } - return out; }); @@ -4290,20 +3818,16 @@ * R.differenceWith(R.equals, [1, 2, 3, 3, 3], []); //=> [1, 2, 3] * R.differenceWith(R.equals, [1, 2, 3, 3, 3], [1]); //=> [2, 3] */ - var differenceWith = _curry3(function differenceWith(pred, first, second) { var out = []; var idx = 0; var firstLen = first.length; - while (idx < firstLen) { if (!_includesWith(pred, first[idx], second) && !_includesWith(pred, first[idx], out)) { out.push(first[idx]); } - idx += 1; } - return out; }); @@ -4327,7 +3851,6 @@ * * R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8] */ - var remove = _curry3(function remove(start, count, list) { var result = Array.prototype.slice.call(list, 0); result.splice(start, count); @@ -4342,22 +3865,17 @@ * @param {Object|Array} obj The object to clone * @return {Object} A new object equivalent to the original but without the specified property */ - function _dissoc(prop, obj) { if (obj == null) { return obj; } - if (_isInteger(prop) && _isArray(obj)) { return remove(prop, 1, obj); } - var result = {}; - for (var p in obj) { result[p] = obj[p]; } - delete result[prop]; return result; } @@ -4372,20 +3890,17 @@ * @param {Object|Array} obj The object to clone * @return {Object|Array} A new object equivalent to the original. */ - function _shallowCloneObject(prop, obj) { if (_isInteger(prop) && _isArray(obj)) { return [].concat(obj); } - var result = {}; - for (var p in obj) { result[p] = obj[p]; } - return result; } + /** * Makes a shallow clone of an object, omitting the property at the given path. * Note that this copies and flattens prototype properties onto the new object @@ -4405,30 +3920,23 @@ * * R.dissocPath(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}} */ - - var dissocPath = _curry2(function dissocPath(path, obj) { if (obj == null) { return obj; } - switch (path.length) { case 0: return obj; - case 1: return _dissoc(path[0], obj); - default: var head = path[0]; var tail = Array.prototype.slice.call(path, 1); - if (obj[head] == null) { return _shallowCloneObject(head, obj); } else { return assoc(head, dissocPath(tail, obj[head]), obj); } - } }); @@ -4448,7 +3956,6 @@ * * R.dissoc('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3} */ - var dissoc = _curry2(function dissoc(prop, obj) { return dissocPath([prop], obj); }); @@ -4475,7 +3982,6 @@ * const reciprocal = R.divide(1); * reciprocal(4); //=> 0.25 */ - var divide = _curry2(function divide(a, b) { return a / b; }); @@ -4484,19 +3990,15 @@ this.xf = xf; this.n = n; } - XDrop.prototype['@@transducer/init'] = _xfBase.init; XDrop.prototype['@@transducer/result'] = _xfBase.result; - XDrop.prototype['@@transducer/step'] = function (result, input) { if (this.n > 0) { this.n -= 1; return result; } - return this.xf['@@transducer/step'](result, input); }; - function _xdrop(n) { return function (xf) { return new XDrop(n, xf); @@ -4527,7 +4029,6 @@ * R.drop(4, ['foo', 'bar', 'baz']); //=> [] * R.drop(3, 'ramda'); //=> 'da' */ - var drop = _curry2(_dispatchable(['drop'], _xdrop, function drop(n, xs) { return slice(Math.max(0, n), Infinity, xs); })); @@ -4537,16 +4038,13 @@ this.n = n; this.i = 0; } - XTake.prototype['@@transducer/init'] = _xfBase.init; XTake.prototype['@@transducer/result'] = _xfBase.result; - XTake.prototype['@@transducer/step'] = function (result, input) { this.i += 1; var ret = this.n === 0 ? result : this.xf['@@transducer/step'](result, input); return this.n >= 0 && this.i >= this.n ? _reduced(ret) : ret; }; - function _xtake(n) { return function (xf) { return new XTake(n, xf); @@ -4596,7 +4094,6 @@ * @symb R.take(1, [a, b]) = [a] * @symb R.take(2, [a, b]) = [a, b] */ - var take = _curry2(_dispatchable(['take'], _xtake, function take(n, xs) { return slice(0, n < 0 ? Infinity : n, xs); })); @@ -4609,39 +4106,31 @@ if (n <= 0) { return xf; } - this.xf = xf; this.pos = 0; this.full = false; this.acc = new Array(n); } - XDropLast.prototype['@@transducer/init'] = _xfBase.init; - XDropLast.prototype['@@transducer/result'] = function (result) { this.acc = null; return this.xf['@@transducer/result'](result); }; - XDropLast.prototype['@@transducer/step'] = function (result, input) { if (this.full) { result = this.xf['@@transducer/step'](result, this.acc[this.pos]); } - this.store(input); return result; }; - XDropLast.prototype.store = function (input) { this.acc[this.pos] = input; this.pos += 1; - if (this.pos === this.acc.length) { this.pos = 0; this.full = true; } }; - function _xdropLast(n) { return function (xf) { return new XDropLast(n, xf); @@ -4671,16 +4160,13 @@ * R.dropLast(4, ['foo', 'bar', 'baz']); //=> [] * R.dropLast(3, 'ramda'); //=> 'ra' */ - var dropLast$1 = _curry2(_dispatchable([], _xdropLast, dropLast)); function dropLastWhile(pred, xs) { var idx = xs.length - 1; - while (idx >= 0 && pred(xs[idx])) { idx -= 1; } - return slice(0, idx + 1, xs); } @@ -4689,29 +4175,23 @@ this.retained = []; this.xf = xf; } - XDropLastWhile.prototype['@@transducer/init'] = _xfBase.init; - XDropLastWhile.prototype['@@transducer/result'] = function (result) { this.retained = null; return this.xf['@@transducer/result'](result); }; - XDropLastWhile.prototype['@@transducer/step'] = function (result, input) { return this.f(input) ? this.retain(result, input) : this.flush(result, input); }; - XDropLastWhile.prototype.flush = function (result, input) { result = _xReduce(this.xf, result, this.retained); this.retained = []; return this.xf['@@transducer/step'](result, input); }; - XDropLastWhile.prototype.retain = function (result, input) { this.retained.push(input); return result; }; - function _xdropLastWhile(fn) { return function (xf) { return new XDropLastWhile(fn, xf); @@ -4745,7 +4225,6 @@ * * R.dropLastWhile(x => x !== 'd' , 'Ramda'); //=> 'Ramd' */ - var dropLastWhile$1 = _curry2(_dispatchable([], _xdropLastWhile, dropLastWhile)); function XDropRepeatsWith(pred, xf) { @@ -4754,23 +4233,18 @@ this.lastValue = undefined; this.seenFirstValue = false; } - XDropRepeatsWith.prototype['@@transducer/init'] = _xfBase.init; XDropRepeatsWith.prototype['@@transducer/result'] = _xfBase.result; - XDropRepeatsWith.prototype['@@transducer/step'] = function (result, input) { var sameAsLast = false; - if (!this.seenFirstValue) { this.seenFirstValue = true; } else if (this.pred(this.lastValue, input)) { sameAsLast = true; } - this.lastValue = input; return sameAsLast ? result : this.xf['@@transducer/step'](result, input); }; - function _xdropRepeatsWith(pred) { return function (xf) { return new XDropRepeatsWith(pred, xf); @@ -4797,8 +4271,9 @@ * R.last('abc'); //=> 'c' * R.last(''); //=> '' */ - - var last = nth(-1); + var last = _curry1(function (list) { + return _nth(-1, list); + }); /** * Returns a new list without any consecutively repeating elements. Equality is @@ -4821,24 +4296,19 @@ * const l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3]; * R.dropRepeatsWith(R.eqBy(Math.abs), l); //=> [1, 3, 4, -5, 3] */ - var dropRepeatsWith = _curry2(_dispatchable([], _xdropRepeatsWith, function dropRepeatsWith(pred, list) { var result = []; var idx = 1; var len = list.length; - if (len !== 0) { result[0] = list[0]; - while (idx < len) { if (!pred(last(result), list[idx])) { result[result.length] = list[idx]; } - idx += 1; } } - return result; })); @@ -4860,7 +4330,6 @@ * * R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); //=> [1, 2, 3, 4, 2] */ - var dropRepeats = _curry1(_dispatchable([], function () { return _xdropRepeatsWith(equals); }, dropRepeatsWith(equals))); @@ -4882,7 +4351,6 @@ * * R.eqBy(Math.abs, 5, -5); //=> true */ - var eqBy = _curry3(function eqBy(f, x, y) { return equals(f(x), f(y)); }); @@ -4907,7 +4375,6 @@ * * R.dropRepeatsBy(Math.abs, [1, -1, -1, 2, 3, -4, 4, 2, 2]); //=> [1, 2, 3, -4, 2] */ - var dropRepeatsBy = _curry2(function (fn, list) { return _dispatchable([], function () { return _xdropRepeatsWith(eqBy(fn)); @@ -4918,22 +4385,17 @@ this.xf = xf; this.f = f; } - XDropWhile.prototype['@@transducer/init'] = _xfBase.init; XDropWhile.prototype['@@transducer/result'] = _xfBase.result; - XDropWhile.prototype['@@transducer/step'] = function (result, input) { if (this.f) { if (this.f(input)) { return result; } - this.f = null; } - return this.xf['@@transducer/step'](result, input); }; - function _xdropWhile(f) { return function (xf) { return new XDropWhile(f, xf); @@ -4968,15 +4430,12 @@ * * R.dropWhile(x => x !== 'd' , 'Ramda'); //=> 'da' */ - var dropWhile = _curry2(_dispatchable(['dropWhile'], _xdropWhile, function dropWhile(pred, xs) { var idx = 0; var len = xs.length; - while (idx < len && pred(xs[idx])) { idx += 1; } - return slice(idx, Infinity, xs); })); @@ -5000,7 +4459,6 @@ * R.or(false, true); //=> true * R.or(false, false); //=> false */ - var or = _curry2(function or(a, b) { return a || b; }); @@ -5035,7 +4493,6 @@ * R.either(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(55) * R.either([false, false, 'a'], [11]) // => [11, 11, "a"] */ - var either = _curry2(function either(f, g) { return _isFunction(f) ? function _either() { return f.apply(this, arguments) || g.apply(this, arguments); @@ -5086,7 +4543,6 @@ * R.empty({x: 1, y: 2}); //=> {} * R.empty(Uint8Array.from('123')); //=> Uint8Array [] */ - var empty = _curry1(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(x) ? '' : _isObject(x) ? {} : _isArguments(x) ? function () { return arguments; @@ -5116,7 +4572,6 @@ * R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] * R.takeLast(3, 'ramda'); //=> 'mda' */ - var takeLast = _curry2(function takeLast(n, xs) { return drop(n >= 0 ? xs.length - n : 0, xs); }); @@ -5143,7 +4598,6 @@ * R.endsWith(['c'], ['a', 'b', 'c']) //=> true * R.endsWith(['b'], ['a', 'b', 'c']) //=> false */ - var endsWith = _curry2(function (suffix, list) { return equals(takeLast(suffix.length, list), suffix); }); @@ -5169,7 +4623,6 @@ * R.eqProps('a', o1, o2); //=> false * R.eqProps('c', o1, o2); //=> true */ - var eqProps = _curry3(function eqProps(prop, obj1, obj2) { return equals(obj1[prop], obj2[prop]); }); @@ -5201,21 +4654,17 @@ * }; * R.evolve(transformations, tomato); //=> {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123} */ - var evolve = _curry2(function evolve(transformations, object) { if (!_isObject(object) && !_isArray(object)) { return object; } - var result = object instanceof Array ? [] : {}; var transformation, key, type; - for (key in object) { transformation = transformations[key]; type = _typeof(transformation); result[key] = type === 'function' ? transformation(object[key]) : transformation && type === 'object' ? evolve(transformation, object[key]) : object[key]; } - return result; }); @@ -5224,26 +4673,20 @@ this.f = f; this.found = false; } - XFind.prototype['@@transducer/init'] = _xfBase.init; - XFind.prototype['@@transducer/result'] = function (result) { if (!this.found) { result = this.xf['@@transducer/step'](result, void 0); } - return this.xf['@@transducer/result'](result); }; - XFind.prototype['@@transducer/step'] = function (result, input) { if (this.f(input)) { this.found = true; result = _reduced(this.xf['@@transducer/step'](result, input)); } - return result; }; - function _xfind(f) { return function (xf) { return new XFind(f, xf); @@ -5274,16 +4717,13 @@ * R.find(R.propEq(2, 'a'))(xs); //=> {a: 2} * R.find(R.propEq(4, 'a'))(xs); //=> undefined */ - var find = _curry2(_dispatchable(['find'], _xfind, function find(fn, list) { var idx = 0; var len = list.length; - while (idx < len) { if (fn(list[idx])) { return list[idx]; } - idx += 1; } })); @@ -5294,28 +4734,21 @@ this.idx = -1; this.found = false; } - XFindIndex.prototype['@@transducer/init'] = _xfBase.init; - XFindIndex.prototype['@@transducer/result'] = function (result) { if (!this.found) { result = this.xf['@@transducer/step'](result, -1); } - return this.xf['@@transducer/result'](result); }; - XFindIndex.prototype['@@transducer/step'] = function (result, input) { this.idx += 1; - if (this.f(input)) { this.found = true; result = _reduced(this.xf['@@transducer/step'](result, this.idx)); } - return result; }; - function _xfindIndex(f) { return function (xf) { return new XFindIndex(f, xf); @@ -5344,19 +4777,15 @@ * R.findIndex(R.propEq(2, 'a'))(xs); //=> 1 * R.findIndex(R.propEq(4, 'a'))(xs); //=> -1 */ - var findIndex = _curry2(_dispatchable([], _xfindIndex, function findIndex(fn, list) { var idx = 0; var len = list.length; - while (idx < len) { if (fn(list[idx])) { return idx; } - idx += 1; } - return -1; })); @@ -5364,21 +4793,16 @@ this.xf = xf; this.f = f; } - XFindLast.prototype['@@transducer/init'] = _xfBase.init; - XFindLast.prototype['@@transducer/result'] = function (result) { return this.xf['@@transducer/result'](this.xf['@@transducer/step'](result, this.last)); }; - XFindLast.prototype['@@transducer/step'] = function (result, input) { if (this.f(input)) { this.last = input; } - return result; }; - function _xfindLast(f) { return function (xf) { return new XFindLast(f, xf); @@ -5407,15 +4831,12 @@ * R.findLast(R.propEq(1, 'a'))(xs); //=> {a: 1, b: 1} * R.findLast(R.propEq(4, 'a'))(xs); //=> undefined */ - var findLast = _curry2(_dispatchable([], _xfindLast, function findLast(fn, list) { var idx = list.length - 1; - while (idx >= 0) { if (fn(list[idx])) { return list[idx]; } - idx -= 1; } })); @@ -5426,23 +4847,17 @@ this.idx = -1; this.lastIdx = -1; } - XFindLastIndex.prototype['@@transducer/init'] = _xfBase.init; - XFindLastIndex.prototype['@@transducer/result'] = function (result) { return this.xf['@@transducer/result'](this.xf['@@transducer/step'](result, this.lastIdx)); }; - XFindLastIndex.prototype['@@transducer/step'] = function (result, input) { this.idx += 1; - if (this.f(input)) { this.lastIdx = this.idx; } - return result; }; - function _xfindLastIndex(f) { return function (xf) { return new XFindLastIndex(f, xf); @@ -5471,18 +4886,14 @@ * R.findLastIndex(R.propEq(1, 'a'))(xs); //=> 1 * R.findLastIndex(R.propEq(4, 'a'))(xs); //=> -1 */ - var findLastIndex = _curry2(_dispatchable([], _xfindLastIndex, function findLastIndex(fn, list) { var idx = list.length - 1; - while (idx >= 0) { if (fn(list[idx])) { return idx; } - idx -= 1; } - return -1; })); @@ -5503,7 +4914,6 @@ * R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]); * //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] */ - var flatten = _curry1(_makeFlat(true)); /** @@ -5526,7 +4936,6 @@ * R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3] * @symb R.flip(f)(a, b, c) = f(b, a, c) */ - var flip = _curry1(function flip(fn) { return curryN(fn.length, function (a, b) { var args = Array.prototype.slice.call(arguments, 0); @@ -5536,6 +4945,41 @@ }); }); + /** + * Takes the value of an expression and applies it to a function + * which is the left-to-right serial composition of the functions + * given in the second argument. + * + * The functions in the pipeline should be unary functions. + * + * `flow` is helps to avoid introducing an extra function with named arguments + * for computing the result of a function pipeline which depends on given initial values. + * Rather than defining a referential transparent function `f = (_x, _y) => R.pipe(g(_x), h(_y), …)` + * which is only later needed once `z = f(x, y)`, + * the introduction of `f`, `_x` and `_y` can be avoided: `z = flow(x, [g, h(y),…]` + * + * In some libraries this function is named `pipe`. + * + * @func + * @memberOf R + * @since v0.30.0 + * @category Function + * @sig a → [(a → b), …, (y → z)] → z + * @param {*} a The seed value + * @param {Array} pipeline functions composing the pipeline + * @return {*} z The result of applying the seed value to the function pipeline + * @see R.pipe + * @example + * R.flow(9, [Math.sqrt, R.negate, R.inc]), //=> -2 + * + * const defaultName = 'Jane Doe'; + * const savedName = R.flow(localStorage.get('name'), [R.when(R.isNil(defaultName)), R.match(/(.+)\s/), R.nth(0)]); + * const givenName = R.flow($givenNameInput.value, [R.trim, R.when(R.isEmpty, R.always(savedName))]) + */ + var flow = _curry2(function flow(seed, pipeline) { + return _reduce(applyTo, seed, pipeline); + }); + /** * Iterate over an input `list`, calling a provided function `fn` for each * element in the list. @@ -5570,16 +5014,13 @@ * // logs 8 * @symb R.forEach(f, [a, b, c]) = [a, b, c] */ - var forEach = _curry2(_checkForMethod('forEach', function forEach(fn, list) { var len = list.length; var idx = 0; - while (idx < len) { fn(list[idx]); idx += 1; } - return list; })); @@ -5605,17 +5046,14 @@ * // logs y:2 * @symb R.forEachObjIndexed(f, {x: a, y: b}) = {x: a, y: b} */ - var forEachObjIndexed = _curry2(function forEachObjIndexed(fn, obj) { var keyList = keys(obj); var idx = 0; - while (idx < keyList.length) { var key = keyList[idx]; fn(obj[key], key, obj); idx += 1; } - return obj; }); @@ -5635,16 +5073,13 @@ * * R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3} */ - var fromPairs = _curry1(function fromPairs(pairs) { var result = {}; var idx = 0; - while (idx < pairs.length) { result[pairs[idx][0]] = pairs[idx][1]; idx += 1; } - return result; }); @@ -5689,7 +5124,6 @@ * // 'F': [{name: 'Eddy', score: 58}] * // } */ - var groupBy = _curry2(_checkForMethod('groupBy', reduceBy(function (acc, item) { acc.push(item); return acc; @@ -5726,23 +5160,18 @@ * R.groupWith(R.eqBy(isVowel), 'aestiou') * //=> ['ae', 'st', 'iou'] */ - var groupWith = _curry2(function (fn, list) { var res = []; var idx = 0; var len = list.length; - while (idx < len) { var nextidx = idx + 1; - while (nextidx < len && fn(list[nextidx - 1], list[nextidx])) { nextidx += 1; } - res.push(list.slice(idx, nextidx)); idx = nextidx; } - return res; }); @@ -5767,7 +5196,6 @@ * R.gt('a', 'z'); //=> false * R.gt('z', 'a'); //=> true */ - var gt = _curry2(function gt(a, b) { return a > b; }); @@ -5793,7 +5221,6 @@ * R.gte('a', 'z'); //=> false * R.gte('z', 'a'); //=> true */ - var gte = _curry2(function gte(a, b) { return a >= b; }); @@ -5819,15 +5246,12 @@ * R.hasPath(['a', 'b'], {a: {c: 2}}); // => false * R.hasPath(['a', 'b'], {}); // => false */ - var hasPath = _curry2(function hasPath(_path, obj) { if (_path.length === 0 || isNil(obj)) { return false; } - var val = obj; var idx = 0; - while (idx < _path.length) { if (!isNil(val) && _has(_path[idx], val)) { val = val[_path[idx]]; @@ -5836,7 +5260,6 @@ return false; } } - return true; }); @@ -5864,7 +5287,6 @@ * pointHas('y'); //=> true * pointHas('z'); //=> false */ - var has = _curry2(function has(prop, obj) { return hasPath([prop], obj); }); @@ -5895,12 +5317,10 @@ * R.hasIn('width', square); //=> true * R.hasIn('area', square); //=> true */ - var hasIn = _curry2(function hasIn(prop, obj) { if (isNil(obj)) { return false; } - return prop in obj; }); @@ -5931,29 +5351,25 @@ * R.identical(0, -0); //=> false * R.identical(NaN, NaN); //=> true */ - var identical = function identical(a, b) { switch (arguments.length) { case 0: return identical; - case 1: return function () { return function unaryIdentical(_b) { switch (arguments.length) { case 0: return unaryIdentical; - default: return _objectIs$1(a, _b); } }; }(); - default: return _objectIs$1(a, b); } - }; // In order to support Cross-origin Window objects as arguments to identical, + }; /** * Creates a function that will process either the `onTrue` or the `onFalse` @@ -5982,7 +5398,6 @@ * incCount({ count: 1 }); //=> { count: 2 } * incCount({}); //=> { count: 1 } */ - var ifElse = _curry3(function ifElse(condition, onTrue, onFalse) { return curryN(Math.max(condition.length, onTrue.length, onFalse.length), function _ifElse() { return condition.apply(this, arguments) ? onTrue.apply(this, arguments) : onFalse.apply(this, arguments); @@ -6004,7 +5419,6 @@ * * R.inc(42); //=> 43 */ - var inc = add(1); /** @@ -6029,7 +5443,6 @@ * R.includes([42], [[42]]); //=> true * R.includes('ba', 'banana'); //=>true */ - var includes = _curry2(_includes); /** @@ -6056,7 +5469,6 @@ * R.indexBy(R.prop('id'), list); * //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}} */ - var indexBy = reduceBy(function (acc, elem) { return elem; }, null); @@ -6080,7 +5492,6 @@ * R.indexOf(3, [1,2,3,4]); //=> 2 * R.indexOf(10, [1,2,3,4]); //=> -1 */ - var indexOf = _curry2(function indexOf(target, xs) { return typeof xs.indexOf === 'function' && !_isArray(xs) ? xs.indexOf(target) : _indexOf(xs, target, 0); }); @@ -6109,7 +5520,6 @@ * R.init('a'); //=> '' * R.init(''); //=> '' */ - var init = slice(0, -1); /** @@ -6147,7 +5557,6 @@ * ); * //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}] */ - var innerJoin = _curry3(function innerJoin(pred, xs, ys) { return _filter(function (x) { return _includesWith(pred, x, ys); @@ -6173,7 +5582,6 @@ * * R.insert(2, 'x', [1,2,3,4]); //=> [1,2,'x',3,4] */ - var insert = _curry3(function insert(idx, elt, list) { idx = idx < list.length && idx >= 0 ? idx : list.length; var result = Array.prototype.slice.call(list, 0); @@ -6199,7 +5607,6 @@ * * R.insertAll(2, ['x','y','z'], [1,2,3,4]); //=> [1,2,'x','y','z',3,4] */ - var insertAll = _curry3(function insertAll(idx, elts, list) { idx = idx < list.length && idx >= 0 ? idx : list.length; return [].concat(Array.prototype.slice.call(list, 0, idx), elts, Array.prototype.slice.call(list, idx)); @@ -6210,14 +5617,11 @@ this.f = f; this.set = new _Set(); } - XUniqBy.prototype['@@transducer/init'] = _xfBase.init; XUniqBy.prototype['@@transducer/result'] = _xfBase.result; - XUniqBy.prototype['@@transducer/step'] = function (result, input) { return this.set.add(this.f(input)) ? this.xf['@@transducer/step'](result, input) : result; }; - function _xuniqBy(f) { return function (xf) { return new XUniqBy(f, xf); @@ -6244,24 +5648,19 @@ * * R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2]); //=> [-1, -5, 2, 10] */ - var uniqBy = _curry2(_dispatchable([], _xuniqBy, function (fn, list) { var set = new _Set(); var result = []; var idx = 0; var appliedItem, item; - while (idx < list.length) { item = list[idx]; appliedItem = fn(item); - if (set.add(appliedItem)) { result.push(item); } - idx += 1; } - return result; })); @@ -6282,7 +5681,6 @@ * R.uniq([1, '1']); //=> [1, '1'] * R.uniq([[42], [42]]); //=> [[42]] */ - var uniq = uniqBy(identity); /** @@ -6302,14 +5700,11 @@ * * R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3] */ - var intersection = _curry2(function intersection(list1, list2) { var toKeep = new _Set(); - for (var i = 0; i < list1.length; i += 1) { toKeep.add(list1[i]); } - return uniq(_filter(toKeep.has.bind(toKeep), list2)); }); @@ -6330,37 +5725,36 @@ * * R.intersperse('a', ['b', 'n', 'n', 's']); //=> ['b', 'a', 'n', 'a', 'n', 'a', 's'] */ - - var intersperse = _curry2(_checkForMethod('intersperse', function intersperse(separator, list) { - var out = []; - var idx = 0; + var intersperse = _curry2(_checkForMethod('intersperse', function _intersperse(separator, list) { var length = list.length; - + if (length === 0) { + return []; + } + var out = Array(length * 2 - 1); + var idx = 0; while (idx < length) { + var i = idx * 2; if (idx === length - 1) { - out.push(list[idx]); + out[i] = list[idx]; } else { - out.push(list[idx], separator); + out[i] = list[idx]; + out[i + 1] = separator; } - idx += 1; } - return out; })); + // Based on https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign function _objectAssign(target) { if (target == null) { throw new TypeError('Cannot convert undefined or null to object'); } - var output = Object(target); var idx = 1; var length = arguments.length; - while (idx < length) { var source = arguments[idx]; - if (source != null) { for (var nextKey in source) { if (_has(nextKey, source)) { @@ -6368,13 +5762,10 @@ } } } - idx += 1; } - return output; } - var _objectAssign$1 = typeof Object.assign === 'function' ? Object.assign : _objectAssign; /** @@ -6397,7 +5788,6 @@ * ); * matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]} */ - var objOf = _curry2(function objOf(key, val) { var obj = {}; obj[key] = val; @@ -6430,19 +5820,15 @@ if (_isTransformer(obj)) { return obj; } - if (_isArrayLike(obj)) { return _stepCatArray; } - if (typeof obj === 'string') { return _stepCatString; } - if (_typeof(obj) === 'object') { return _stepCatObject; } - throw new Error('Cannot create transformer for ' + obj); } @@ -6485,7 +5871,6 @@ * const intoArray = R.into([]); * intoArray(transducer, numbers); //=> [2, 3] */ - var into = _curry3(function into(acc, transducer, list) { var xf = transducer(_isTransformer(acc) ? acc : _stepCat(acc)); return _xReduce(xf, xf['@@transducer/init'](), list); @@ -6513,13 +5898,11 @@ * R.invert(raceResultsByFirstName); * //=> { 'alice': ['first', 'third'], 'jake':['second'] } */ - var invert = _curry1(function invert(obj) { var props = keys(obj); var len = props.length; var idx = 0; var out = {}; - while (idx < len) { var key = props[idx]; var val = obj[key]; @@ -6527,7 +5910,6 @@ list[list.length] = key; idx += 1; } - return out; }); @@ -6558,19 +5940,16 @@ * R.invertObj(raceResults); * //=> { 'alice': '0', 'jake':'1' } */ - var invertObj = _curry1(function invertObj(obj) { var props = keys(obj); var len = props.length; var idx = 0; var out = {}; - while (idx < len) { var key = props[idx]; out[obj[key]] = key; idx += 1; } - return out; }); @@ -6616,15 +5995,12 @@ * @symb R.invoker(1, 'method')(a, o) = o['method'](a) * @symb R.invoker(2, 'method')(a, b, o) = o['method'](a, b) */ - var invoker = _curry2(function invoker(arity, method) { return curryN(arity + 1, function () { var target = arguments[arity]; - if (target != null && _isFunction(target[method])) { return target[method].apply(target, Array.prototype.slice.call(arguments, 0, arity)); } - throw new TypeError(toString$1(target) + ' does not have a method named "' + method + '"'); }); }); @@ -6653,7 +6029,6 @@ * R.is(Object, 's'); //=> false * R.is(Number, {}); //=> false */ - var is = _curry2(function is(Ctor, val) { return val instanceof Ctor || val != null && (val.constructor === Ctor || Ctor.name === 'Object' && _typeof(val) === 'object'); }); @@ -6669,7 +6044,7 @@ * @sig a -> Boolean * @param {*} x * @return {Boolean} - * @see R.empty + * @see R.empty, R.isNotEmpty * @example * * R.isEmpty([1, 2, 3]); //=> false @@ -6680,11 +6055,36 @@ * R.isEmpty({length: 0}); //=> false * R.isEmpty(Uint8Array.from('')); //=> true */ - var isEmpty = _curry1(function isEmpty(x) { return x != null && equals(x, empty(x)); }); + /** + * Returns `false` if the given value is its type's empty value; `true` + * otherwise. + * + * @func + * @memberOf R + * @since v0.29.2 + * @category Logic + * @sig a -> Boolean + * @param {*} x + * @return {Boolean} + * @see R.empty, R.isEmpty + * @example + * + * R.isNotEmpty([1, 2, 3]); //=> true + * R.isNotEmpty([]); //=> false + * R.isNotEmpty(''); //=> false + * R.isNotEmpty(null); //=> true + * R.isNotEmpty({}); //=> false + * R.isNotEmpty({length: 0}); //=> true + * R.isNotEmpty(Uint8Array.from('')); //=> false + */ + var isNotEmpty = _curry1(function isNotEmpty(x) { + return !isEmpty(x); + }); + /** * Checks if the input value is not `null` and not `undefined`. * @@ -6702,7 +6102,6 @@ * R.isNotNil(0); //=> true * R.isNotNil([]); //=> true */ - var isNotNil = _curry1(function isNotNil(x) { return !isNil(x); }); @@ -6726,7 +6125,6 @@ * spacer(['a', 2, 3.4]); //=> 'a 2 3.4' * R.join('|', [1, 2, 3]); //=> '1|2|3' */ - var join = invoker(1, 'join'); /** @@ -6746,7 +6144,6 @@ * 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 = _curry1(function juxt(fns) { return converge(function () { return Array.prototype.slice.call(arguments, 0); @@ -6774,15 +6171,12 @@ * const f = new F(); * R.keysIn(f); //=> ['x', 'y'] */ - var keysIn = _curry1(function keysIn(obj) { var prop; var ks = []; - for (prop in obj) { ks[ks.length] = prop; } - return ks; }); @@ -6805,21 +6199,17 @@ * R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6 * R.lastIndexOf(10, [1,2,3,4]); //=> -1 */ - var lastIndexOf = _curry2(function lastIndexOf(target, xs) { if (typeof xs.lastIndexOf === 'function' && !_isArray(xs)) { return xs.lastIndexOf(target); } else { var idx = xs.length - 1; - while (idx >= 0) { if (equals(xs[idx], target)) { return idx; } - idx -= 1; } - return -1; } }); @@ -6843,7 +6233,6 @@ * R.length([]); //=> 0 * R.length([1, 2, 3]); //=> 3 */ - var length = _curry1(function length(list) { return list != null && _isNumber(list.length) ? list.length : NaN; }); @@ -6871,7 +6260,6 @@ * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} * R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2} */ - var lens = _curry2(function lens(getter, setter) { return function (toFunctorFn) { return function (target) { @@ -6904,7 +6292,6 @@ * @symb R.update(0, a, [b, c]) = [a, c] * @symb R.update(1, a, [b, c]) = [b, a] */ - var update = _curry3(function update(idx, x, list) { return adjust(idx, always(x), list); }); @@ -6929,78 +6316,27 @@ * R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c'] * R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c'] */ - var lensIndex = _curry1(function lensIndex(n) { - return lens(nth(n), update(n)); + return lens(function (val) { + return _nth(n, val); + }, update(n)); }); - /** - * Retrieves the values at given paths of an object. - * - * @func - * @memberOf R - * @since v0.27.1 - * @category Object - * @typedefn Idx = [String | Int | Symbol] - * @sig [Idx] -> {a} -> [a | Undefined] - * @param {Array} pathsArray The array of paths to be fetched. - * @param {Object} obj The object to retrieve the nested properties from. - * @return {Array} A list consisting of values at paths specified by "pathsArray". - * @see R.path - * @example - * - * R.paths([['a', 'b'], ['p', 0, 'q']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, 3] - * R.paths([['a', 'b'], ['p', 'r']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, undefined] - */ - - var paths = _curry2(function paths(pathsArray, obj) { - return pathsArray.map(function (paths) { - var val = obj; - var idx = 0; - var p; - - while (idx < paths.length) { - if (val == null) { - return; - } - - p = paths[idx]; - val = _isInteger(p) ? nth(p, val) : val[p]; - idx += 1; + function _path(pathAr, obj) { + var val = obj; + for (var i = 0; i < pathAr.length; i += 1) { + if (val == null) { + return undefined; } - - return val; - }); - }); - - /** - * Retrieves the value at a given path. The nodes of the path can be arbitrary strings or non-negative integers. - * For anything else, the value is unspecified. Integer paths are meant to index arrays, strings are meant for objects. - * - * @func - * @memberOf R - * @since v0.2.0 - * @category Object - * @typedefn Idx = String | Int | Symbol - * @sig [Idx] -> {a} -> a | Undefined - * @sig Idx = String | NonNegativeInt - * @param {Array} path The path to use. - * @param {Object} obj The object or array to retrieve the nested property from. - * @return {*} The data at `path`. - * @see R.prop, R.nth, R.assocPath, R.dissocPath - * @example - * - * R.path(['a', 'b'], {a: {b: 2}}); //=> 2 - * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined - * R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}}); //=> 1 - * R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}}); //=> 2 - * R.path([2], {'2': 2}); //=> 2 - * R.path([-2], {'-2': 'a'}); //=> undefined - */ - - var path = _curry2(function path(pathAr, obj) { - return paths([pathAr], obj)[0]; - }); + var p = pathAr[i]; + if (_isInteger(p)) { + val = _nth(p, val); + } else { + val = val[p]; + } + } + return val; + } /** * Returns a lens whose focus is the specified path. @@ -7028,7 +6364,9 @@ */ var lensPath = _curry1(function lensPath(p) { - return lens(path(p), assocPath(p)); + return lens(function (val) { + return _path(p, val); + }, assocPath(p)); }); /** @@ -7051,7 +6389,6 @@ * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} * R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2} */ - var lensProp = _curry1(function lensProp(k) { return lens(prop(k), assoc(k)); }); @@ -7077,7 +6414,6 @@ * R.lt('a', 'z'); //=> true * R.lt('z', 'a'); //=> false */ - var lt = _curry2(function lt(a, b) { return a < b; }); @@ -7103,7 +6439,6 @@ * R.lte('a', 'z'); //=> true * R.lte('z', 'a'); //=> false */ - var lte = _curry2(function lte(a, b) { return a <= b; }); @@ -7142,19 +6477,16 @@ * ] * ] */ - var mapAccum = _curry3(function mapAccum(fn, acc, list) { var idx = 0; var len = list.length; - var result = []; + var result = Array(len); var tuple = [acc]; - while (idx < len) { tuple = fn(tuple[0], list[idx]); result[idx] = tuple[1]; idx += 1; } - return [tuple[0], result]; }); @@ -7195,18 +6527,15 @@ * ] * ] */ - var mapAccumRight = _curry3(function mapAccumRight(fn, acc, list) { var idx = list.length - 1; - var result = []; + var result = Array(list.length); var tuple = [acc]; - while (idx >= 0) { tuple = fn(tuple[0], list[idx]); result[idx] = tuple[1]; idx -= 1; } - return [tuple[0], result]; }); @@ -7231,7 +6560,6 @@ * * R.mapObjIndexed(prependKeyAndDouble, xyz); //=> { x: 'x2', y: 'y4', z: 'z6' } */ - var mapObjIndexed = _curry2(function mapObjIndexed(fn, obj) { return _arrayReduce(function (acc, key) { acc[key] = fn(obj[key], key, obj); @@ -7260,7 +6588,6 @@ * R.match(/a/, 'b'); //=> [] * R.match(/a/, null); //=> TypeError: null does not have a method named "match" */ - var match = _curry2(function match(rx, str) { return str.match(rx) || []; }); @@ -7298,16 +6625,13 @@ * seventeenMod(4); //=> 1 * seventeenMod(10); //=> 7 */ - var mathMod = _curry2(function mathMod(m, p) { if (!_isInteger(m)) { return NaN; } - if (!_isInteger(p) || p < 1) { return NaN; } - return (m % p + p) % p; }); @@ -7335,7 +6659,6 @@ * R.reduce(R.maxBy(square), 0, [3, -5, 4, 1, -2]); //=> -5 * R.reduce(R.maxBy(square), 0, []); //=> 0 */ - var maxBy = _curry3(function maxBy(f, a, b) { var resultB = f(b); return max(f(a), resultB) === resultB ? b : a; @@ -7356,7 +6679,6 @@ * * R.sum([2,4,6,8,100,1]); //=> 121 */ - var sum = reduce(add, 0); /** @@ -7375,7 +6697,6 @@ * R.mean([2, 7, 9]); //=> 6 * R.mean([]); //=> NaN */ - var mean = _curry1(function mean(list) { return sum(list) / list.length; }); @@ -7397,14 +6718,11 @@ * R.median([7, 2, 10, 9]); //=> 8 * R.median([]); //=> NaN */ - var median = _curry1(function median(list) { var len = list.length; - if (len === 0) { return NaN; } - var width = 2 - len % 2; var idx = (len - width) / 2; return mean(Array.prototype.slice.call(list, 0).sort(function (a, b) { @@ -7450,16 +6768,13 @@ * withAge({birth: 1921, death: 1999}); * //=> {birth: 1921, death: 1999, age: 78} (returned from cache) */ - var memoizeWith = _curry2(function memoizeWith(keyGen, fn) { var cache = {}; return _arity(fn.length, function () { var key = keyGen.apply(this, arguments); - if (!_has(key, cache)) { cache[key] = fn.apply(this, arguments); } - return cache[key]; }); }); @@ -7483,7 +6798,6 @@ * R.mergeAll([{foo:1},{foo:2},{bar:2}]); //=> {foo:2,bar:2} * @symb R.mergeAll([{ x: 1 }, { y: 2 }, { z: 3 }]) = { x: 1, y: 2, z: 3 } */ - var mergeAll = _curry1(function mergeAll(list) { return _objectAssign$1.apply(null, [{}].concat(list)); }); @@ -7513,25 +6827,21 @@ * //=> { a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] } * @symb R.mergeWithKey(f, { x: 1, y: 2 }, { y: 5, z: 3 }) = { x: 1, y: f('y', 2, 5), z: 3 } */ - var mergeWithKey = _curry3(function mergeWithKey(fn, l, r) { var result = {}; var k; l = l || {}; r = r || {}; - for (k in l) { if (_has(k, l)) { result[k] = _has(k, r) ? fn(k, l[k], r[k]) : l[k]; } } - for (k in r) { if (_has(k, r) && !_has(k, result)) { result[k] = r[k]; } } - return result; }); @@ -7563,7 +6873,6 @@ * { b: true, c: { thing: 'bar', values: [15, 35] }}); * //=> { a: true, b: true, c: { thing: 'bar', values: [10, 20, 15, 35] }} */ - var mergeDeepWithKey = _curry3(function mergeDeepWithKey(fn, lObj, rObj) { return mergeWithKey(function (k, lVal, rVal) { if (_isObject(lVal) && _isObject(rVal)) { @@ -7595,7 +6904,6 @@ * { age: 40, contact: { email: 'baa@example.com' }}); * //=> { name: 'fred', age: 10, contact: { email: 'moo@example.com' }} */ - var mergeDeepLeft = _curry2(function mergeDeepLeft(lObj, rObj) { return mergeDeepWithKey(function (k, lVal, rVal) { return lVal; @@ -7623,7 +6931,6 @@ * { age: 40, contact: { email: 'baa@example.com' }}); * //=> { name: 'fred', age: 40, contact: { email: 'baa@example.com' }} */ - var mergeDeepRight = _curry2(function mergeDeepRight(lObj, rObj) { return mergeDeepWithKey(function (k, lVal, rVal) { return rVal; @@ -7657,7 +6964,6 @@ * { b: true, c: { values: [15, 35] }}); * //=> { a: true, b: true, c: { values: [10, 20, 15, 35] }} */ - var mergeDeepWith = _curry3(function mergeDeepWith(fn, lObj, rObj) { return mergeDeepWithKey(function (k, lVal, rVal) { return fn(lVal, rVal); @@ -7687,7 +6993,6 @@ * resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2} * @symb R.mergeLeft(a, b) = {...b, ...a} */ - var mergeLeft = _curry2(function mergeLeft(l, r) { return _objectAssign$1({}, r, l); }); @@ -7715,7 +7020,6 @@ * withDefaults({y: 2}); //=> {x: 0, y: 2} * @symb R.mergeRight(a, b) = {...a, ...b} */ - var mergeRight = _curry2(function mergeRight(l, r) { return _objectAssign$1({}, l, r); }); @@ -7743,7 +7047,6 @@ * { b: true, values: [15, 35] }); * //=> { a: true, b: true, values: [10, 20, 15, 35] } */ - var mergeWith = _curry3(function mergeWith(fn, l, r) { return mergeWithKey(function (_, _l, _r) { return fn(_l, _r); @@ -7767,39 +7070,29 @@ * R.min(789, 123); //=> 123 * R.min('a', 'b'); //=> 'a' */ - var min = _curry2(function min(a, b) { if (a === b) { return a; } - function safeMin(x, y) { if (x < y !== y < x) { return y < x ? y : x; } - return undefined; } - var minByValue = safeMin(a, b); - if (minByValue !== undefined) { return minByValue; } - var minByType = safeMin(_typeof(a), _typeof(b)); - if (minByType !== undefined) { return minByType === _typeof(a) ? a : b; } - var stringA = toString$1(a); var minByStringValue = safeMin(stringA, toString$1(b)); - if (minByStringValue !== undefined) { return minByStringValue === stringA ? a : b; } - return a; }); @@ -7827,7 +7120,6 @@ * R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]); //=> 1 * R.reduce(R.minBy(square), Infinity, []); //=> Infinity */ - var minBy = _curry3(function minBy(f, a, b) { var resultB = f(b); return min(f(a), resultB) === resultB ? b : a; @@ -7845,20 +7137,16 @@ * @param {Object|Array} obj The object to clone * @return {Object|Array} A new object equivalent to the original except for the changed property. */ - function _modify(prop, fn, obj) { if (_isInteger(prop) && _isArray(obj)) { var arr = [].concat(obj); arr[prop] = fn(arr[prop]); return arr; } - var result = {}; - for (var p in obj) { result[p] = obj[p]; } - result[prop] = fn(result[prop]); return result; } @@ -7889,32 +7177,24 @@ * const person = {name: 'James', addresses: [{ zipCode: '90216' }]}; * R.modifyPath(['addresses', 0, 'zipCode'], R.reverse, person); //=> {name: 'James', addresses: [{ zipCode: '61209' }]} */ - var modifyPath = _curry3(function modifyPath(path, fn, object) { if (!_isObject(object) && !_isArray(object)) { return object; } - if (path.length === 0) { return fn(object); } - var idx = path[0]; - if (!_has(idx, object)) { return object; } - if (path.length === 1) { return _modify(idx, fn, object); } - var val = modifyPath(Array.prototype.slice.call(path, 1), fn, object[idx]); - if (val === object[idx]) { return object; } - return _assoc(idx, val, object); }); @@ -7940,7 +7220,6 @@ * R.modify('age', R.add(1), person); //=> {name: 'James', age: 21, pets: ['dog', 'cat']} * R.modify('pets', R.append('turtle'), person); //=> {name: 'James', age: 20, pets: ['dog', 'cat', 'turtle']} */ - var modify = _curry3(function modify(prop, fn, object) { return modifyPath([prop], fn, object); }); @@ -7970,7 +7249,6 @@ * isOdd(42); //=> 0 * isOdd(21); //=> 1 */ - var modulo = _curry2(function modulo(a, b) { return a % b; }); @@ -7993,7 +7271,6 @@ * R.move(0, 2, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['b', 'c', 'a', 'd', 'e', 'f'] * R.move(-1, 0, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['f', 'a', 'b', 'c', 'd', 'e'] list rotation */ - var move = _curry3(function (from, to, list) { var length = list.length; var result = list.slice(); @@ -8023,12 +7300,12 @@ * triple(4); //=> 12 * R.multiply(2, 5); //=> 10 */ - var multiply = _curry2(function multiply(a, b) { return a * b; }); var _this = undefined; + /** * Takes a function `f` and an object, and returns a function `g`. * When applied, `g` returns the result of applying `f` to the object @@ -8057,7 +7334,6 @@ * sayHelloToMs({ firstName: 'Jane', lastName: 'Jones' }); //=> 'Hello, Ms. Jane Jones!' * @symb R.partialObject(f, { a, b })({ c, d }) = f({ a, b, c, d }) */ - var partialObject = _curry2(function (f, o) { return function (props) { return f.call(_this, mergeDeepRight(o, props)); @@ -8078,7 +7354,6 @@ * * R.negate(42); //=> -42 */ - var negate = _curry1(function negate(n) { return -n; }); @@ -8108,11 +7383,38 @@ * R.none(isEven, [1, 3, 5, 7, 9, 11]); //=> true * R.none(isOdd, [1, 3, 5, 7, 8, 11]); //=> false */ - var none = _curry2(function none(fn, input) { return all(_complement(fn), input); }); + /** + * Returns the nth element of the given list or string. If n is negative the + * element at index length + n is returned. + * + * @func + * @memberOf R + * @since v0.1.0 + * @category List + * @sig Number -> [a] -> a | Undefined + * @sig Number -> String -> String + * @param {Number} offset + * @param {*} list + * @return {*} + * @example + * + * const list = ['foo', 'bar', 'baz', 'quux']; + * R.nth(1, list); //=> 'bar' + * R.nth(-1, list); //=> 'quux' + * R.nth(-99, list); //=> undefined + * + * R.nth(2, 'abc'); //=> 'c' + * R.nth(3, 'abc'); //=> '' + * @symb R.nth(-1, [a, b, c]) = c + * @symb R.nth(0, [a, b, c]) = a + * @symb R.nth(1, [a, b, c]) = b + */ + var nth = _curry2(_nth); + /** * Returns a function which returns its nth argument. * @@ -8131,11 +7433,10 @@ * @symb R.nthArg(0)(a, b, c) = a * @symb R.nthArg(1)(a, b, c) = b */ - var nthArg = _curry1(function nthArg(n) { var arity = n < 0 ? 1 : n + 1; return curryN(arity, function () { - return nth(n, arguments); + return _nth(n, arguments); }); }); @@ -8166,7 +7467,6 @@ * * @symb R.o(f, g, x) = f(g(x)) */ - var o = _curry3(function o(f, g, x) { return f(g(x)); }); @@ -8196,7 +7496,6 @@ * R.of(Array, [42]); //=> [[42]] * R.of(Maybe, 42); //=> Maybe.Just(42) */ - var of = _curry2(function of(Ctor, val) { return typeof Ctor['fantasy-land/of'] === 'function' ? Ctor['fantasy-land/of'](val) : typeof Ctor.of === 'function' ? Ctor.of(val) : [val]; }); @@ -8217,24 +7516,20 @@ * * R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3} */ - var omit = _curry2(function omit(names, obj) { var result = {}; var index = {}; var idx = 0; var len = names.length; - while (idx < len) { index[names[idx]] = 1; idx += 1; } - for (var prop in obj) { if (!index.hasOwnProperty(prop)) { result[prop] = obj[prop]; } } - return result; }); @@ -8263,7 +7558,6 @@ * containsInsensitive('o', 'FOO'); //=> true * @symb R.on(f, g, a, b) = f(g(a), g(b)) */ - var on = _curryN(4, [], function on(f, g, a, b) { return f(g(a), g(b)); }); @@ -8287,7 +7581,6 @@ * addOneOnce(10); //=> 11 * addOneOnce(addOneOnce(50)); //=> 11 */ - var once = _curry1(function once(fn) { var called = false; var result; @@ -8295,7 +7588,6 @@ if (called) { return result; } - called = true; result = fn.apply(this, arguments); return result; @@ -8336,15 +7628,13 @@ * ); * recoverFromFailure(12345).then(console.log); */ - var otherwise = _curry2(function otherwise(f, p) { _assertPromise('otherwise', p); - return p.then(null, f); }); + // `Identity` is a functor that holds a single value, where `map` simply // transforms the held value with the provided function. - var Identity = function Identity(x) { return { value: x, @@ -8353,6 +7643,7 @@ } }; }; + /** * Returns the result of "setting" the portion of the given data structure * focused by the given lens to the result of applying the given function to @@ -8375,8 +7666,6 @@ * * R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz'] */ - - var over = _curry3(function over(lens, f, x) { // The value returned by the getter function is first transformed with `f`, // then set as the value of an `Identity`. This is then mapped over with the @@ -8402,7 +7691,6 @@ * * R.pair('foo', 'bar'); //=> ['foo', 'bar'] */ - var pair = _curry2(function pair(fst, snd) { return [fst, snd]; }); @@ -8443,7 +7731,6 @@ * sayHelloToMs('Jane', 'Jones'); //=> 'Hello, Ms. Jane Jones!' * @symb R.partial(f, [a, b])(c, d) = f(a, b, c, d) */ - var partial = _createPartialApplicator(_concat); /** @@ -8467,38 +7754,98 @@ * * const greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']); * - * greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!' - * @symb R.partialRight(f, [a, b])(c, d) = f(c, d, a, b) + * greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!' + * @symb R.partialRight(f, [a, b])(c, d) = f(c, d, a, b) + */ + var partialRight = _createPartialApplicator(flip(_concat)); + + /** + * Takes a predicate and a list or other `Filterable` object and returns the + * pair of filterable objects of the same type of elements which do and do not + * satisfy, the predicate, respectively. Filterable objects include plain objects or any object + * that has a filter method such as `Array`. + * + * @func + * @memberOf R + * @since v0.1.4 + * @category List + * @sig Filterable f => (a -> Boolean) -> f a -> [f a, f a] + * @param {Function} pred A predicate to determine which side the element belongs to. + * @param {Array} filterable the list (or other filterable) to partition. + * @return {Array} An array, containing first the subset of elements that satisfy the + * predicate, and second the subset of elements that do not satisfy. + * @see R.filter, R.reject + * @example + * + * R.partition(R.includes('s'), ['sss', 'ttt', 'foo', 'bars']); + * // => [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ] + * + * R.partition(R.includes('s'), { a: 'sss', b: 'ttt', foo: 'bars' }); + * // => [ { a: 'sss', foo: 'bars' }, { b: 'ttt' } ] + */ + var partition = juxt([filter, reject]); + + /** + * Retrieves the value at a given path. The nodes of the path can be arbitrary strings or non-negative integers. + * For anything else, the value is unspecified. Integer paths are meant to index arrays, strings are meant for objects. + * + * @func + * @memberOf R + * @since v0.2.0 + * @category Object + * @typedefn Idx = String | Int | Symbol + * @sig [Idx] -> {a} -> a | Undefined + * @sig Idx = String | NonNegativeInt + * @param {Array} path The path to use. + * @param {Object} obj The object or array to retrieve the nested property from. + * @return {*} The data at `path`. + * @see R.prop, R.nth, R.assocPath, R.dissocPath + * @example + * + * R.path(['a', 'b'], {a: {b: 2}}); //=> 2 + * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined + * R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}}); //=> 1 + * R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}}); //=> 2 + * R.path([2], {'2': 2}); //=> 2 + * R.path([-2], {'-2': 'a'}); //=> undefined */ - var partialRight = _createPartialApplicator(flip(_concat)); + var path = _curry2(_path); /** - * Takes a predicate and a list or other `Filterable` object and returns the - * pair of filterable objects of the same type of elements which do and do not - * satisfy, the predicate, respectively. Filterable objects include plain objects or any object - * that has a filter method such as `Array`. + * Retrieves the values at given paths of an object. * * @func * @memberOf R - * @since v0.1.4 - * @category List - * @sig Filterable f => (a -> Boolean) -> f a -> [f a, f a] - * @param {Function} pred A predicate to determine which side the element belongs to. - * @param {Array} filterable the list (or other filterable) to partition. - * @return {Array} An array, containing first the subset of elements that satisfy the - * predicate, and second the subset of elements that do not satisfy. - * @see R.filter, R.reject + * @since v0.27.1 + * @category Object + * @typedefn Idx = [String | Int | Symbol] + * @sig [Idx] -> {a} -> [a | Undefined] + * @param {Array} pathsArray The array of paths to be fetched. + * @param {Object} obj The object to retrieve the nested properties from. + * @return {Array} A list consisting of values at paths specified by "pathsArray". + * @see R.path * @example * - * R.partition(R.includes('s'), ['sss', 'ttt', 'foo', 'bars']); - * // => [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ] - * - * R.partition(R.includes('s'), { a: 'sss', b: 'ttt', foo: 'bars' }); - * // => [ { a: 'sss', foo: 'bars' }, { b: 'ttt' } ] + * R.paths([['a', 'b'], ['p', 0, 'q']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, 3] + * R.paths([['a', 'b'], ['p', 'r']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, undefined] */ - - var partition = juxt([filter, reject]); + var paths = _curry2(function paths(pathsArray, obj) { + return pathsArray.map(function (paths) { + var val = obj; + var idx = 0; + var p; + while (idx < paths.length) { + if (val == null) { + return; + } + p = paths[idx]; + val = _isInteger(p) ? _nth(p, val) : val[p]; + idx += 1; + } + return val; + }); + }); /** * Determines whether a nested path on an object has a specific value, in @@ -8525,9 +7872,8 @@ * const isFamous = R.pathEq(90210, ['address', 'zipCode']); * R.filter(isFamous, users); //=> [ user1 ] */ - - var pathEq = _curry3(function pathEq(val, _path, obj) { - return equals(path(_path, obj), val); + var pathEq = _curry3(function pathEq(val, pathAr, obj) { + return equals(_path(pathAr, obj), val); }); /** @@ -8549,9 +7895,8 @@ * R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2 * R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A" */ - var pathOr = _curry3(function pathOr(d, p, obj) { - return defaultTo(d, path(p, obj)); + return defaultTo(d, _path(p, obj)); }); /** @@ -8574,9 +7919,8 @@ * R.pathSatisfies(y => y > 0, ['x', 'y'], {x: {y: 2}}); //=> true * R.pathSatisfies(R.is(Object), [], {x: {y: 2}}); //=> true */ - var pathSatisfies = _curry3(function pathSatisfies(pred, propPath, obj) { - return pred(path(propPath, obj)); + return pred(_path(propPath, obj)); }); /** @@ -8597,19 +7941,15 @@ * R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4} * R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1} */ - var pick = _curry2(function pick(names, obj) { var result = {}; var idx = 0; - while (idx < names.length) { if (names[idx] in obj) { result[names[idx]] = obj[names[idx]]; } - idx += 1; } - return result; }); @@ -8631,18 +7971,15 @@ * R.pickAll(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4} * R.pickAll(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined} */ - var pickAll = _curry2(function pickAll(names, obj) { var result = {}; var idx = 0; var len = names.length; - while (idx < len) { var name = names[idx]; result[name] = obj[name]; idx += 1; } - return result; }); @@ -8666,16 +8003,13 @@ * const isUpperCase = (val, key) => key.toUpperCase() === key; * R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4} */ - var pickBy = _curry2(function pickBy(test, obj) { var result = {}; - for (var prop in obj) { if (test(obj[prop], prop, obj)) { result[prop] = obj[prop]; } } - return result; }); @@ -8696,7 +8030,6 @@ * * R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum'] */ - var prepend = _curry2(function prepend(el, list) { return _concat([el], list); }); @@ -8716,7 +8049,6 @@ * * R.product([2,4,6,8,100,1]); //=> 38400 */ - var product = reduce(multiply, 1); /** @@ -8748,17 +8080,14 @@ * R.useWith(Math.pow, [R.dec, R.inc])(3)(4); //=> 32 * @symb R.useWith(f, [g, h])(a, b) = f(g(a), h(b)) */ - var useWith = _curry2(function useWith(fn, transformers) { return curryN(transformers.length, function () { var args = []; var idx = 0; - while (idx < transformers.length) { args.push(transformers[idx].call(this, arguments[idx])); idx += 1; } - return fn.apply(this, args.concat(Array.prototype.slice.call(arguments, transformers.length))); }); }); @@ -8783,7 +8112,6 @@ * const kids = [abby, fred]; * R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}] */ - var project = useWith(_map, [pickAll, identity]); // passing `identity` gives correct arity function _promap(f, g, profunctor) { @@ -8797,14 +8125,11 @@ this.f = f; this.g = g; } - XPromap.prototype['@@transducer/init'] = _xfBase.init; XPromap.prototype['@@transducer/result'] = _xfBase.result; - XPromap.prototype['@@transducer/step'] = function (result, input) { return this.xf['@@transducer/step'](result, _promap(this.f, this.g, input)); }; - function _xpromap(f, g) { return function (xf) { return new XPromap(f, g, xf); @@ -8840,7 +8165,6 @@ * @symb R.promap(f, g, h) = x => g(h(f(x))) * @symb R.promap(f, g, profunctor) = profunctor.promap(f, g) */ - var promap = _curry3(_dispatchable(['fantasy-land/promap', 'promap'], _xpromap, _promap)); /** @@ -8870,7 +8194,6 @@ * const hasBrownHair = R.propEq('brown', 'hair'); * R.filter(hasBrownHair, kids); //=> [fred, rusty] */ - var propEq = _curry3(function propEq(val, name, obj) { return equals(val, prop(name, obj)); }); @@ -8895,7 +8218,6 @@ * R.propIs(Number, 'x', {x: 'foo'}); //=> false * R.propIs(Number, 'x', {}); //=> false */ - var propIs = _curry3(function propIs(type, name, obj) { return is(type, prop(name, obj)); }); @@ -8927,7 +8249,6 @@ * favorite(alice); //=> undefined * favoriteWithDefault(alice); //=> 'Ramda' */ - var propOr = _curry3(function propOr(val, p, obj) { return defaultTo(val, prop(p, obj)); }); @@ -8951,7 +8272,6 @@ * * R.propSatisfies(x => x > 0, 'x', {x: 1, y: 2}); //=> true */ - var propSatisfies = _curry3(function propSatisfies(pred, name, obj) { return pred(prop(name, obj)); }); @@ -8977,10 +8297,9 @@ * const fullName = R.compose(R.join(' '), R.props(['first', 'last'])); * fullName({last: 'Bullet-Tooth', age: 33, first: 'Tony'}); //=> 'Tony Bullet-Tooth' */ - var props = _curry2(function props(ps, obj) { return ps.map(function (p) { - return path([p], obj); + return prop(p, obj); }); }); @@ -9000,20 +8319,17 @@ * R.range(1, 5); //=> [1, 2, 3, 4] * R.range(50, 53); //=> [50, 51, 52] */ - var range = _curry2(function range(from, to) { if (!(_isNumber(from) && _isNumber(to))) { throw new TypeError('Both arguments to range must be numbers'); } - - var result = []; - var n = from; - - while (n < to) { - result.push(n); - n += 1; + var result = Array(from < to ? to - from : 0); + var finish = from < 0 ? to + Math.abs(from) : to - from; + var idx = 0; + while (idx < finish) { + result[idx] = idx + from; + idx += 1; } - return result; }); @@ -9066,21 +8382,16 @@ * * @symb R.reduceRight(f, a, [b, c, d]) = f(b, f(c, f(d, a))) */ - var reduceRight = _curry3(function reduceRight(fn, acc, list) { var idx = list.length - 1; - while (idx >= 0) { acc = fn(list[idx], acc); - if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } - idx -= 1; } - return acc; }); @@ -9114,12 +8425,10 @@ * const ys = [2, 4, 6] * R.reduceWhile(isOdd, R.add, 111, ys); //=> 111 */ - var reduceWhile = _curryN(4, [], function _reduceWhile(pred, fn, a, list) { var xf = _xwrap(function (acc, x) { return pred(acc, x) ? fn(acc, x) : _reduced(acc); }); - return _xReduce(xf, a, list); }); @@ -9150,7 +8459,6 @@ * [], * [1, 2, 3, 4, 5]) // [1, 2, 3] */ - var reduced = _curry1(_reduced); /** @@ -9176,23 +8484,17 @@ * @symb R.times(f, 1) = [f(0)] * @symb R.times(f, 2) = [f(0), f(1)] */ - var times = _curry2(function times(fn, n) { var len = Number(n); - var idx = 0; - var list; - if (len < 0 || isNaN(len)) { throw new RangeError('n must be a non-negative number'); } - - list = []; - + var idx = 0; + var list = Array(len); while (idx < len) { - list.push(fn(idx)); + list[idx] = fn(idx); idx += 1; } - return list; }); @@ -9219,7 +8521,6 @@ * @symb R.repeat(a, 1) = [a] * @symb R.repeat(a, 2) = [a, a] */ - var repeat = _curry2(function repeat(value, n) { return times(always(value), n); }); @@ -9248,35 +8549,28 @@ * // Use the "g" (global) flag to replace all occurrences: * R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar' */ - var replace = _curry3(function replace(regex, replacement, str) { return str.replace(regex, replacement); }); var tInit$1 = '@@transducer/init'; var tStep$1 = '@@transducer/step'; - function XScan(reducer, acc, xf) { this.xf = xf; this.f = reducer; this.acc = acc; } - XScan.prototype[tInit$1] = function () { return this.xf[tStep$1](this.xf[tInit$1](), this.acc); }; - XScan.prototype['@@transducer/result'] = _xfBase.result; - XScan.prototype[tStep$1] = function (result, input) { if (result['@@transducer/reduced']) { return result; } - this.acc = this.f(this.acc, input); return this.xf[tStep$1](result, this.acc); }; - var _xscan = _curry3(function _xscan(reducer, acc, xf) { return new XScan(reducer, acc, xf); }); @@ -9304,18 +8598,16 @@ * const factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24] * @symb R.scan(f, a, [b, c]) = [a, f(a, b), f(f(a, b), c)] */ - var scan = _curry3(_dispatchable([], _xscan, function scan(fn, acc, list) { var idx = 0; var len = list.length; - var result = [acc]; - + var result = Array(len + 1); + result[0] = acc; while (idx < len) { acc = fn(acc, list[idx]); result[idx + 1] = acc; idx += 1; } - return result; })); @@ -9345,7 +8637,6 @@ * R.sequence(R.of(Array), Just([1, 2, 3])); //=> [Just(1), Just(2), Just(3)] * R.sequence(R.of(Array), Nothing()); //=> [Nothing()] */ - var sequence = _curry2(function sequence(F, traversable) { var of = typeof F['fantasy-land/of'] === 'function' ? F['fantasy-land/of'] : typeof F.of === 'function' ? F.of : F; var TypeRep = { @@ -9378,7 +8669,6 @@ * R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} * R.set(xLens, 8, {x: 1, y: 2}); //=> {x: 8, y: 2} */ - var set = _curry3(function set(lens, v, x) { return over(lens, always(v), x); }); @@ -9404,7 +8694,6 @@ * const diff = function(a, b) { return a - b; }; * R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7] */ - var sort = _curry2(function sort(comparator, list) { return Array.prototype.slice.call(list, 0).sort(comparator); }); @@ -9442,7 +8731,6 @@ * const people = [clara, bob, alice]; * sortByNameCaseInsensitive(people); //=> [alice, bob, clara] */ - var sortBy = _curry2(function sortBy(fn, list) { return Array.prototype.slice.call(list, 0).sort(function (a, b) { var aa = fn(a); @@ -9484,17 +8772,14 @@ * ]); * ageNameSort(people); //=> [alice, clara, bob] */ - var sortWith = _curry2(function sortWith(fns, list) { return Array.prototype.slice.call(list, 0).sort(function (a, b) { var result = 0; var i = 0; - while (result === 0 && i < fns.length) { result = fns[i](a, b); i += 1; } - return result; }); }); @@ -9519,7 +8804,6 @@ * * R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd'] */ - var split = invoker(1, 'split'); /** @@ -9540,7 +8824,6 @@ * R.splitAt(5, 'hello world'); //=> ['hello', ' world'] * R.splitAt(-1, 'foobar'); //=> ['fooba', 'r'] */ - var splitAt = _curry2(function splitAt(index, array) { return [slice(0, index, array), slice(index, length(array), array)]; }); @@ -9562,19 +8845,15 @@ * R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]); //=> [[1, 2, 3], [4, 5, 6], [7]] * R.splitEvery(3, 'foobarbaz'); //=> ['foo', 'bar', 'baz'] */ - var splitEvery = _curry2(function splitEvery(n, list) { if (n <= 0) { throw new Error('First argument to splitEvery must be a positive integer'); } - var result = []; var idx = 0; - while (idx < list.length) { result.push(slice(idx, idx += n, list)); } - return result; }); @@ -9597,17 +8876,14 @@ * * R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]] */ - var splitWhen = _curry2(function splitWhen(pred, list) { var idx = 0; var len = list.length; var prefix = []; - while (idx < len && !pred(list[idx])) { prefix.push(list[idx]); idx += 1; } - return [prefix, Array.prototype.slice.call(list, idx)]; }); @@ -9616,7 +8892,7 @@ * * @func * @memberOf R - * @since v0.26.1 + * @since v0.28.0 * @category List * @sig (a -> Boolean) -> [a] -> [[a]] * @param {Function} pred The predicate that determines where the array is split. @@ -9626,22 +8902,18 @@ * * R.splitWhenever(R.equals(2), [1, 2, 3, 2, 4, 5, 2, 6, 7]); //=> [[1], [3], [4, 5], [6, 7]] */ - var splitWhenever = _curryN(2, [], function splitWhenever(pred, list) { var acc = []; var curr = []; - for (var i = 0; i < list.length; i = i + 1) { if (!pred(list[i])) { curr.push(list[i]); } - if ((i < list.length - 1 && pred(list[i + 1]) || i === list.length - 1) && curr.length > 0) { acc.push(curr); curr = []; } } - return acc; }); @@ -9667,7 +8939,6 @@ * R.startsWith(['a'], ['a', 'b', 'c']) //=> true * R.startsWith(['b'], ['a', 'b', 'c']) //=> false */ - var startsWith = _curry2(function (prefix, list) { return equals(take(prefix.length, list), prefix); }); @@ -9695,7 +8966,6 @@ * complementaryAngle(30); //=> 60 * complementaryAngle(72); //=> 18 */ - var subtract = _curry2(function subtract(a, b) { return Number(a) - Number(b); }); @@ -9703,16 +8973,13 @@ var swapObject = function swapObject(indexA, indexB, o) { var copy = clone(o); var properties = Object.getOwnPropertyNames(copy); - if (properties.includes(indexA) && properties.includes(indexB)) { var tmp = copy[indexA]; copy[indexA] = copy[indexB]; copy[indexB] = tmp; } - return copy; }; - var swapList = function swapList(indexA, indexB, list) { var length = list.length; var result = list.slice(); @@ -9720,27 +8987,23 @@ var positiveIndexB = indexB < 0 ? length + indexB : indexB; var positiveMin = Math.min(positiveIndexA, positiveIndexB); var positiveMax = Math.max(positiveIndexA, positiveIndexB); - if (positiveIndexA < 0 || positiveIndexA > length) { return result; } - if (positiveIndexB < 0 || positiveIndexB > length) { return result; } - if (positiveIndexA === positiveIndexB) { return result; } - result = [].concat(result.slice(0, positiveMin)).concat([result[positiveMax]]).concat(result.slice(positiveMin + 1, positiveMax)).concat([result[positiveMin]]).concat(result.slice(positiveMax + 1, length)); return result; }; - var swapString = function swapString(indexA, indexB, s) { var result = swapList(indexA, indexB, s); return _isArray(result) ? result.join('') : result; }; + /** * Swap an item, at index `indexA` with another item, at index `indexB`, in an object or a list of elements. * A new result will be created containing the new elements order. @@ -9761,8 +9024,6 @@ * R.swap('a', 'b', {a: 1, b: 2}); //=> {a: 2, b: 1} * R.swap(0, 2, 'foo'); //=> 'oof' */ - - var swap = _curry3(function (indexA, indexB, o) { if (_isArray(o)) { return swapList(indexA, indexB, o); @@ -9791,7 +9052,6 @@ * R.symmetricDifference([1,2,3,4], [7,6,5,4,3]); //=> [1,2,7,6,5] * R.symmetricDifference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5,1,2] */ - var symmetricDifference = _curry2(function symmetricDifference(list1, list2) { return concat(difference(list1, list2), difference(list2, list1)); }); @@ -9818,7 +9078,6 @@ * const l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}]; * R.symmetricDifferenceWith(eqA, l1, l2); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}] */ - var symmetricDifferenceWith = _curry3(function symmetricDifferenceWith(pred, list1, list2) { return concat(differenceWith(pred, list1, list2), differenceWith(pred, list2, list1)); }); @@ -9848,14 +9107,11 @@ * * R.takeLastWhile(x => x !== 'R' , 'Ramda'); //=> 'amda' */ - var takeLastWhile = _curry2(function takeLastWhile(fn, xs) { var idx = xs.length - 1; - while (idx >= 0 && fn(xs[idx])) { idx -= 1; } - return slice(idx + 1, Infinity, xs); }); @@ -9863,14 +9119,11 @@ this.xf = xf; this.f = f; } - XTakeWhile.prototype['@@transducer/init'] = _xfBase.init; XTakeWhile.prototype['@@transducer/result'] = _xfBase.result; - XTakeWhile.prototype['@@transducer/step'] = function (result, input) { return this.f(input) ? this.xf['@@transducer/step'](result, input) : _reduced(result); }; - function _xtakeWhile(f) { return function (xf) { return new XTakeWhile(f, xf); @@ -9906,15 +9159,12 @@ * * R.takeWhile(x => x !== 'd' , 'Ramda'); //=> 'Ram' */ - var takeWhile = _curry2(_dispatchable(['takeWhile'], _xtakeWhile, function takeWhile(fn, xs) { var idx = 0; var len = xs.length; - while (idx < len && fn(xs[idx])) { idx += 1; } - return slice(0, idx, xs); })); @@ -9922,15 +9172,12 @@ this.xf = xf; this.f = f; } - XTap.prototype['@@transducer/init'] = _xfBase.init; XTap.prototype['@@transducer/result'] = _xfBase.result; - XTap.prototype['@@transducer/step'] = function (result, input) { this.f(input); return this.xf['@@transducer/step'](result, input); }; - function _xtap(f) { return function (xf) { return new XTap(f, xf); @@ -9957,7 +9204,6 @@ * // logs 'x is 100' * @symb R.tap(f, a) = (f(a), a) */ - var tap = _curry2(_dispatchable([], _xtap, function tap(fn, x) { fn(x); return x; @@ -9984,12 +9230,10 @@ * R.test(/^x/, 'xyz'); //=> true * R.test(/^y/, 'xyz'); //=> false */ - var test = _curry2(function test(pattern, str) { if (!_isRegExp(pattern)) { throw new TypeError('‘test’ requires a value of type RegExp as its first argument; received ' + toString$1(pattern)); } - return _cloneRegExp(pattern).test(str); }); @@ -10023,10 +9267,8 @@ * * getMemberName('bob@gmail.com').then(console.log); */ - var andThen = _curry2(function andThen(f, p) { _assertPromise('andThen', p); - return p.then(f); }); @@ -10045,7 +9287,6 @@ * * R.toLower('XYZ'); //=> 'xyz' */ - var toLower = invoker(0, 'toLowerCase'); /** @@ -10066,16 +9307,13 @@ * * R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]] */ - var toPairs = _curry1(function toPairs(obj) { var pairs = []; - for (var prop in obj) { if (_has(prop, obj)) { pairs[pairs.length] = [prop, obj[prop]]; } } - return pairs; }); @@ -10100,14 +9338,11 @@ * const f = new F(); * R.toPairsIn(f); //=> [['x','X'], ['y','Y']] */ - var toPairsIn = _curry1(function toPairsIn(obj) { var pairs = []; - for (var prop in obj) { pairs[pairs.length] = [prop, obj[prop]]; } - return pairs; }); @@ -10126,7 +9361,6 @@ * * R.toUpper('abc'); //=> 'ABC' */ - var toUpper = invoker(0, 'toUpperCase'); /** @@ -10176,7 +9410,6 @@ * const firstOddTransducer = R.compose(R.filter(isOdd), R.take(1)); * R.transduce(firstOddTransducer, R.flip(R.append), [], R.range(0, 100)); //=> [1] */ - var transduce = curryN(4, function transduce(xf, fn, acc, list) { return _xReduce(xf(typeof fn === 'function' ? _xwrap(fn) : fn), acc, list); }); @@ -10205,27 +9438,21 @@ * @symb R.transpose([[a, b], [c, d]]) = [[a, c], [b, d]] * @symb R.transpose([[a, b], [c]]) = [[a, c], [b]] */ - var transpose = _curry1(function transpose(outerlist) { var i = 0; var result = []; - while (i < outerlist.length) { var innerlist = outerlist[i]; var j = 0; - while (j < innerlist.length) { if (typeof result[j] === 'undefined') { result[j] = []; } - result[j].push(innerlist[j]); j += 1; } - i += 1; } - return result; }); @@ -10262,7 +9489,6 @@ * R.traverse(Maybe, safeDiv(10), Right(0)); //=> Nothing * R.traverse(Maybe, safeDiv(10), Left("X")); //=> Just(Left("X")) */ - var traverse = _curry3(function traverse(F, f, traversable) { var of = typeof F['fantasy-land/of'] === 'function' ? F['fantasy-land/of'] : typeof F.of === 'function' ? F.of : F; var TypeRep = { @@ -10289,7 +9515,6 @@ * R.trim(' xyz '); //=> 'xyz' * R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z'] */ - var trim = !hasProtoTrim || ws.trim() || !zeroWidth.trim() ? _curry1(function trim(str) { var beginRx = new RegExp('^[' + ws + '][' + ws + ']*'); var endRx = new RegExp('[' + ws + '][' + ws + ']*$'); @@ -10322,7 +9547,6 @@ * R.tryCatch(R.times(R.identity), R.always([]))('s') // => [] * R.tryCatch(() => { throw 'this is not a valid value'}, (err, value)=>({error : err, value }))('bar') // => {'error': 'this is not a valid value', 'value': 'bar'} */ - var tryCatch = _curry2(function _tryCatch(tryer, catcher) { return _arity(tryer.length, function () { try { @@ -10357,7 +9581,6 @@ * R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]' * @symb R.unapply(f)(a, b) = f([a, b]) */ - var unapply = _curry1(function unapply(fn) { return function () { return fn(Array.prototype.slice.call(arguments, 0)); @@ -10392,7 +9615,6 @@ * takesOneArg(1, 2); //=> [1, undefined] * @symb R.unary(f)(a, b, c) = f(a) */ - var unary = _curry1(function unary(fn) { return nAry(1, fn); }); @@ -10419,21 +9641,18 @@ * const uncurriedAddFour = R.uncurryN(4, addFour); * uncurriedAddFour(1, 2, 3, 4); //=> 10 */ - var uncurryN = _curry2(function uncurryN(depth, fn) { return curryN(depth, function () { var currentDepth = 1; var value = fn; var idx = 0; var endIdx; - while (currentDepth <= depth && typeof value === 'function') { endIdx = currentDepth === depth ? arguments.length : idx + value.length; value = value.apply(this, Array.prototype.slice.call(arguments, idx, endIdx)); currentDepth += 1; idx = endIdx; } - return value; }); }); @@ -10463,16 +9682,13 @@ * R.unfold(f, 10); //=> [-10, -20, -30, -40, -50] * @symb R.unfold(f, x) = [f(x)[0], f(f(x)[1])[0], f(f(f(x)[1])[1])[0], ...] */ - var unfold = _curry2(function unfold(fn, seed) { var pair = fn(seed); var result = []; - while (pair && pair.length) { result[result.length] = pair[0]; pair = fn(pair[1]); } - return result; }); @@ -10493,7 +9709,6 @@ * * R.union([1, 2, 3], [2, 3, 4]); //=> [1, 2, 3, 4] */ - var union = _curry2(compose(uniq, _concat)); function XUniqWith(pred, xf) { @@ -10501,10 +9716,8 @@ this.pred = pred; this.items = []; } - XUniqWith.prototype['@@transducer/init'] = _xfBase.init; XUniqWith.prototype['@@transducer/result'] = _xfBase.result; - XUniqWith.prototype['@@transducer/step'] = function (result, input) { if (_includesWith(this.pred, input, this.items)) { return result; @@ -10513,7 +9726,6 @@ return this.xf['@@transducer/step'](result, input); } }; - function _xuniqWith(pred) { return function (xf) { return new XUniqWith(pred, xf); @@ -10544,23 +9756,18 @@ * R.uniqWith(strEq)([1, '1', 1]); //=> [1] * R.uniqWith(strEq)(['1', 1, 1]); //=> ['1'] */ - var uniqWith = _curry2(_dispatchable([], _xuniqWith, function (pred, list) { var idx = 0; var len = list.length; var result = []; var item; - while (idx < len) { item = list[idx]; - if (!_includesWith(pred, item, result)) { result[result.length] = item; } - idx += 1; } - return result; })); @@ -10587,7 +9794,6 @@ * const l2 = [{a: 1}, {a: 4}]; * R.unionWith(R.eqBy(R.prop('a')), l1, l2); //=> [{a: 1}, {a: 2}, {a: 4}] */ - var unionWith = _curry3(function unionWith(pred, list1, list2) { return uniqWith(pred, _concat(list1, list2)); }); @@ -10616,7 +9822,6 @@ * safeInc(null); //=> null * safeInc(1); //=> 2 */ - var unless = _curry3(function unless(pred, whenFalseFn, x) { return pred(x) ? x : whenFalseFn(x); }); @@ -10638,7 +9843,6 @@ * R.unnest([1, [2], [[3]]]); //=> [1, 2, [3]] * R.unnest([[1, 2], [3, 4], [5, 6]]); //=> [1, 2, 3, 4, 5, 6] */ - var unnest = chain(_identity); /** @@ -10660,14 +9864,11 @@ * * R.until(R.gt(R.__, 100), R.multiply(2))(1) // => 128 */ - var until = _curry3(function until(pred, fn, init) { var val = init; - while (!pred(val)) { val = fn(val); } - return val; }); @@ -10681,9 +9882,9 @@ * @since v0.28.0 * @category Object * @sig String -> {k: [v]} -> [{k: v}] - * @param {String} key The key to determine which property of the object should be unwind - * @param {Object} object The object containing list under property named as key which is to unwind - * @return {List} A new list of object containing the value of input key having list replaced by each element in the object. + * @param {String} key The key to determine which property of the object should be unwound. + * @param {Object} object The object containing the list to unwind at the property named by the key. + * @return {List} A list of new objects, each having the given key associated to an item from the unwound list. * @example * * R.unwind('hobbies', { @@ -10701,9 +9902,8 @@ // If key is not in object or key is not as a list in object if (!(key in object && _isArray(object[key]))) { return [object]; - } // Map over object[key] which is a list and assoc each element with key - - + } + // Map over object[key] which is a list and assoc each element with key return _map(function (item) { return _assoc(key, item, object); }, object[key]); @@ -10730,18 +9930,16 @@ * const f = new F(); * R.valuesIn(f); //=> ['X', 'Y'] */ - var valuesIn = _curry1(function valuesIn(obj) { var prop; var vs = []; - for (prop in obj) { vs[vs.length] = obj[prop]; } - return vs; }); + // `Const` is a functor that effectively ignores the function given to `map`. var Const = function Const(x) { return { value: x, @@ -10750,6 +9948,7 @@ } }; }; + /** * Returns a "view" of the given data structure, determined by the given lens. * The lens's focus determines which portion of the data structure is visible. @@ -10771,8 +9970,6 @@ * R.view(xLens, {x: 1, y: 2}); //=> 1 * R.view(xLens, {x: 4, y: 2}); //=> 4 */ - - var view = _curry2(function view(lens, x) { // Using `Const` effectively ignores the setter function of the `lens`, // leaving the value returned by the getter function unmodified. @@ -10807,7 +10004,6 @@ * truncate('12345'); //=> '12345' * truncate('0123456789ABC'); //=> '0123456789…' */ - var when = _curry3(function when(pred, whenTrueFn, x) { return pred(x) ? whenTrueFn(x) : x; }); @@ -10847,14 +10043,12 @@ * pred({a: 'foo', b: 'xxx', x: 10, y: 19}); //=> false * pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> false */ - var where = _curry2(function where(spec, testObj) { for (var prop in spec) { if (_has(prop, spec) && !spec[prop](testObj[prop])) { return false; } } - return true; }); @@ -10892,14 +10086,12 @@ * pred({a: 'foo', b: 'bar', x: 10, y: 20}); //=> true * pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> true */ - var whereAny = _curry2(function whereAny(spec, testObj) { for (var prop in spec) { if (_has(prop, spec) && spec[prop](testObj[prop])) { return true; } } - return false; }); @@ -10931,7 +10123,6 @@ * pred({a: 1, b: 2, c: 3}); //=> true * pred({a: 1, b: 1}); //=> false */ - var whereEq = _curry2(function whereEq(spec, testObj) { return where(map(equals, spec), testObj); }); @@ -10955,14 +10146,11 @@ * * R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4] */ - var without = _curry2(function without(xs, list) { var toRemove = new _Set(); - for (var i = 0; i < xs.length; i += 1) { toRemove.add(xs[i]); } - return reject(toRemove.has.bind(toRemove), list); }); @@ -10987,7 +10175,6 @@ * R.xor(false, true); //=> true * R.xor(false, false); //=> false */ - var xor = _curry2(function xor(a, b) { return Boolean(!a ^ !b); }); @@ -11010,26 +10197,21 @@ * R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] * @symb R.xprod([a, b], [c, d]) = [[a, c], [a, d], [b, c], [b, d]] */ - var xprod = _curry2(function xprod(a, b) { // = xprodWith(prepend); (takes about 3 times as long...) - var idx = 0; + var i = 0; var ilen = a.length; var j; var jlen = b.length; - var result = []; - - while (idx < ilen) { + var result = Array(ilen * jlen); + while (i < ilen) { j = 0; - while (j < jlen) { - result[result.length] = [a[idx], b[j]]; + result[i * jlen + j] = [a[i], b[j]]; j += 1; } - - idx += 1; + i += 1; } - return result; }); @@ -11052,17 +10234,14 @@ * R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']] * @symb R.zip([a, b, c], [d, e, f]) = [[a, d], [b, e], [c, f]] */ - var zip = _curry2(function zip(a, b) { - var rv = []; - var idx = 0; var len = Math.min(a.length, b.length); - + var rv = Array(len); + var idx = 0; while (idx < len) { rv[idx] = [a[idx], b[idx]]; idx += 1; } - return rv; }); @@ -11083,17 +10262,14 @@ * * R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3} */ - var zipObj = _curry2(function zipObj(keys, values) { var idx = 0; var len = Math.min(keys.length, values.length); var out = {}; - while (idx < len) { out[keys[idx]] = values[idx]; idx += 1; } - return out; }); @@ -11121,17 +10297,14 @@ * //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')] * @symb R.zipWith(fn, [a, b, c], [d, e, f]) = [fn(a, d), fn(b, e), fn(c, f)] */ - var zipWith = _curry3(function zipWith(fn, a, b) { - var rv = []; - var idx = 0; var len = Math.min(a.length, b.length); - + var rv = Array(len); + var idx = 0; while (idx < len) { rv[idx] = fn(a[idx], b[idx]); idx += 1; } - return rv; }); @@ -11153,7 +10326,6 @@ * R.thunkify(R.identity)(42)(); //=> 42 * R.thunkify((a, b) => a + b)(25, 17)(); //=> 42 */ - var thunkify = _curry1(function thunkify(fn) { return curryN(fn.length, function createThunk() { var fnArgs = arguments; @@ -11165,7 +10337,7 @@ exports.F = F; exports.T = T; - exports.__ = __; + exports.__ = _placeholder; exports.add = add; exports.addIndex = addIndex; exports.addIndexRight = addIndexRight; @@ -11236,6 +10408,7 @@ exports.findLastIndex = findLastIndex; exports.flatten = flatten; exports.flip = flip; + exports.flow = flow; exports.forEach = forEach; exports.forEachObjIndexed = forEachObjIndexed; exports.fromPairs = fromPairs; @@ -11267,6 +10440,7 @@ exports.is = is; exports.isEmpty = isEmpty; exports.isNil = isNil; + exports.isNotEmpty = isNotEmpty; exports.isNotNil = isNotNil; exports.join = join; exports.juxt = juxt; diff --git a/docs/index.html b/docs/index.html index 4262ec1..999e635 100644 --- a/docs/index.html +++ b/docs/index.html @@ -14,13 +14,13 @@ Ramda - v0.29.1 + v0.30.0
Returns List - A new list of object containing the value of input key having list replaced by each element in the object. + A list of new objects, each having the given key associated to an item from the unwound list.
@@ -17064,7 +17203,7 @@

-
R.unwind('hobbies', { +
R.unwind('hobbies', { name: 'alice', hobbies: ['Golf', 'Hacking'], colors: ['red', 'green'], @@ -17080,7 +17219,7 @@

update List - +

@@ -17135,7 +17274,7 @@

adjust. -
R.update(1, '_', ['a', 'b', 'c']); //=> ['a', '_', 'c'] +
R.update(1, '_', ['a', 'b', 'c']); //=> ['a', '_', 'c'] R.update(-1, '_', ['a', 'b', 'c']); //=> ['a', 'b', '_']
@@ -17144,7 +17283,7 @@

useWith Function - +

@@ -17199,7 +17338,7 @@

converge. -
R.useWith(Math.pow, [R.identity, R.identity])(3, 4); //=> 81 +
R.useWith(Math.pow, [R.identity, R.identity])(3, 4); //=> 81 R.useWith(Math.pow, [R.identity, R.identity])(3)(4); //=> 81 R.useWith(Math.pow, [R.dec, R.inc])(3, 4); //=> 32 R.useWith(Math.pow, [R.dec, R.inc])(3)(4); //=> 32
@@ -17210,7 +17349,7 @@

values Object - +

@@ -17254,7 +17393,7 @@

toPairs. -
R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3]
+
R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3]
@@ -17262,7 +17401,7 @@

valuesIn Object - +

@@ -17306,7 +17445,7 @@

keysIn. -
const F = function() { this.x = 'X'; }; +
const F = function() { this.x = 'X'; }; F.prototype.y = 'Y'; const f = new F(); R.valuesIn(f); //=> ['X', 'Y']
@@ -17317,7 +17456,7 @@

view Object - +

@@ -17369,7 +17508,7 @@

lensPath. -
const xLens = R.lensProp('x'); +
const xLens = R.lensProp('x'); R.view(xLens, {x: 1, y: 2}); //=> 1 R.view(xLens, {x: 4, y: 2}); //=> 4
@@ -17380,7 +17519,7 @@

when Logic - +

@@ -17441,7 +17580,7 @@

cond. -
// truncate :: String -> String +
// truncate :: String -> String const truncate = R.when( R.propSatisfies(R.gt(R.__, 10), 'length'), R.pipe(R.take(10), R.append('…'), R.join('')) @@ -17455,7 +17594,7 @@

where Object - +

@@ -17507,7 +17646,7 @@

whereEq. -
// pred :: Object -> Boolean +
// pred :: Object -> Boolean const pred = R.where({ a: R.equals('foo'), b: R.complement(R.equals('bar')), @@ -17527,7 +17666,7 @@

whereAny Object - +

@@ -17578,7 +17717,7 @@

where. -
// pred :: Object -> Boolean +
// pred :: Object -> Boolean const pred = R.whereAny({ a: R.equals('foo'), b: R.complement(R.equals('xxx')), @@ -17598,7 +17737,7 @@

whereEq Object - +

@@ -17649,7 +17788,7 @@

where. -
// pred :: Object -> Boolean +
// pred :: Object -> Boolean const pred = R.whereEq({a: 1, b: 2}); pred({a: 1}); //=> false @@ -17663,7 +17802,7 @@

without List - +

@@ -17714,7 +17853,7 @@

remove. -
R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4]
+
R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4]

@@ -17722,7 +17861,7 @@

xor Logic - +

@@ -17770,7 +17909,7 @@

and. -
R.xor(true, true); //=> false +
R.xor(true, true); //=> false R.xor(true, false); //=> true R.xor(false, true); //=> true R.xor(false, false); //=> false
@@ -17781,7 +17920,7 @@

xprod List - +

@@ -17826,7 +17965,7 @@

-
R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
+
R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]

@@ -17834,7 +17973,7 @@

zip List - +

@@ -17880,7 +18019,7 @@

-
R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]
+
R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]

@@ -17888,7 +18027,7 @@

zipObj List - +

@@ -17933,7 +18072,7 @@

-
R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}
+
R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}

@@ -17941,7 +18080,7 @@

zipWith List - +

@@ -17994,7 +18133,7 @@

-
const f = (x, y) => { +
const f = (x, y) => { // ... }; R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']); diff --git a/index.html b/index.html index 96bb1dd..9a079bf 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,4 @@ -Ramda Documentation

Ramda

+Ramda Documentation

Ramda

A practical functional library for JavaScript programmers.

Build Status npm module @@ -6,20 +6,20 @@ nest badge Gitter

Why Ramda?

-

-

There are already several excellent libraries with a functional flavor. Typically, they are meant to be general-purpose toolkits, suitable for working in multiple paradigms. Ramda has a more focused goal. We wanted a library designed specifically for a functional programming style, one that makes it easy to create functional pipelines, one that never mutates user data.

+

There are already several excellent libraries with a functional flavor. Typically, they are meant to be general-purpose toolkits, suitable for working in multiple paradigms. Ramda has a more focused goal. We wanted a library designed specifically for a functional programming style, one that makes it easy to create functional pipelines, one that never mutates user data.

What's Different?

The primary distinguishing features of Ramda are:

    -
  • Ramda emphasizes a purer functional style. Immutability and side-effect free functions -are at the heart of its design philosophy. This can help you get the job done with simple, +

  • Ramda emphasizes a purer functional style. Immutability and side-effect free functions +are at the heart of its design philosophy. This can help you get the job done with simple, elegant code.

  • -
  • Ramda functions are automatically curried. This allows you to easily build up new functions +

  • Ramda functions are automatically curried. This allows you to easily build up new functions from old ones simply by not supplying the final parameters.

  • -
  • The parameters to Ramda functions are arranged to make it convenient for currying. The data +

  • The parameters to Ramda functions are arranged to make it convenient for currying. The data to be operated on is generally supplied last.

@@ -36,13 +36,13 @@

Introductions

Philosophy

Using Ramda should feel much like just using JavaScript. It is practical, functional JavaScript. We're not introducing -lambda expressions in strings, we're not borrowing consed +lambda expressions in strings, we're not borrowing consed lists, we're not porting over all of the Clojure functions.

Our basic data structures are plain JavaScript objects, and our usual collections are JavaScript arrays. We also keep other native features of JavaScript, such as functions as objects with properties.

-

Functional programming is in good part about immutable objects and +

Functional programming is in good part about immutable objects and side-effect free functions. While Ramda does not enforce this, it enables such style to be as frictionless as possible.

We aim for an implementation both clean and elegant, but the API is king. @@ -91,15 +91,15 @@

Partial Builds

It is possible to build Ramda with a subset of the functionality to reduce its file size. Ramda's build system supports this with command line flags. For example if you're using R.compose, R.reduce, and R.filter you can create a partial build with:

npm run --silent partial-build compose reduce filter > dist/ramda.custom.js
 
-

This requires having Node/io.js installed and ramda's dependencies installed (just use npm install before running partial build).

+

This requires having Node/io.js installed and ramda's dependencies installed (just use npm install before running partial build).

Documentation

Please review the API documentation.

Also available is our Cookbook of functions built from Ramda that you may find useful.

The Name

-

Ok, so we like sheep. That's all. It's a short name, not already -taken. It could as easily have been eweda, but then we would be -forced to say eweda lamb!, and no one wants that. For non-English -speakers, lambs are baby sheep, ewes are female sheep, and rams are male +

Ok, so we like sheep. That's all. It's a short name, not already +taken. It could as easily have been eweda, but then we would be +forced to say eweda lamb!, and no one wants that. For non-English +speakers, lambs are baby sheep, ewes are female sheep, and rams are male sheep. So perhaps ramda is a grown-up lambda... but probably not.

Running The Test Suite

Console:

@@ -157,7 +157,7 @@

Funding

If you wish to donate to Ramda please see our Open Collective page. Thank you!

Acknowledgements

Thanks to J. C. Phillipps for the Ramda logo. -Ramda logo artwork © 2014 J. C. Phillipps. Licensed Creative Commons +Ramda logo artwork © 2014 J. C. Phillipps. Licensed Creative Commons CC BY-NC-SA 3.0.