diff --git a/es/index.js b/es/index.js index 388bcc1..cb58653 100644 --- a/es/index.js +++ b/es/index.js @@ -1,6 +1,43 @@ -import curryN from 'ramda/es/curryN'; - // Utility +var slice = Array.prototype.slice; +var concat = Array.prototype.concat; + +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } + +/** + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. + */ +function curryN(n, func) { + return function() { + var curargs = slice.call(arguments); + + if (curargs.length >= n) { + return func.apply(null, curargs); + } + + return curryN(n - curargs.length, function() { + return func.apply(null, concat.call(curargs, slice.call(arguments))); + }); + } +} + +function curry(func) { + return curryN(func.length, func); +} + function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -366,6 +403,7 @@ flyd.transduce = curryN(2, function(xform, source) { * a(2)(4) // => 6 */ flyd.curryN = curryN; +flyd.curry = curry; /** * Returns a new stream identical to the original except every diff --git a/examples/drag-and-drop/build.js b/examples/drag-and-drop/build.js index cd3980d..310f131 100644 --- a/examples/drag-and-drop/build.js +++ b/examples/drag-and-drop/build.js @@ -1,205 +1,46 @@ var draganddrop = (function () { 'use strict'; -function _arity(n, fn) { - /* eslint-disable no-unused-vars */ - switch (n) { - case 0: - return function () { - return fn.apply(this, arguments); - }; - case 1: - return function (a0) { - return fn.apply(this, arguments); - }; - case 2: - return function (a0, a1) { - return fn.apply(this, arguments); - }; - case 3: - return function (a0, a1, a2) { - return fn.apply(this, arguments); - }; - case 4: - return function (a0, a1, a2, a3) { - return fn.apply(this, arguments); - }; - case 5: - return function (a0, a1, a2, a3, a4) { - return fn.apply(this, arguments); - }; - case 6: - return function (a0, a1, a2, a3, a4, a5) { - return fn.apply(this, arguments); - }; - case 7: - return function (a0, a1, a2, a3, a4, a5, a6) { - return fn.apply(this, arguments); - }; - case 8: - return function (a0, a1, a2, a3, a4, a5, a6, a7) { - return fn.apply(this, arguments); - }; - case 9: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { - return fn.apply(this, arguments); - }; - case 10: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { - return fn.apply(this, arguments); - }; - default: - throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); - } -} -var _arity_1 = _arity; - -function _isPlaceholder(a) { - return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; -} -var _isPlaceholder_1 = _isPlaceholder; - -/** - * Optimized internal one-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curry1(fn) { - return function f1(a) { - if (arguments.length === 0 || _isPlaceholder_1(a)) { - return f1; - } else { - return fn.apply(this, arguments); +// Utility +var slice = Array.prototype.slice; +var concat = Array.prototype.concat; + +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } + +/** + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. + */ +function curryN(n, func) { + return function() { + var curargs = slice.call(arguments); + + if (curargs.length >= n) { + return func.apply(null, curargs); } - }; -} -var _curry1_1 = _curry1; - -/** - * Optimized internal two-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - -function _curry2(fn) { - return function f2(a, b) { - switch (arguments.length) { - case 0: - return f2; - case 1: - return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { - return fn(a, _b); - }); - default: - return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { - return fn(_a, b); - }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { - return fn(a, _b); - }) : fn(a, b); - } - }; + return curryN(n - curargs.length, function() { + return func.apply(null, concat.call(curargs, slice.call(arguments))); + }); + } } -var _curry2_1 = _curry2; -/** - * Internal curryN function. - * - * @private - * @category Function - * @param {Number} length The arity of the curried function. - * @param {Array} received An array of arguments received thus far. - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curryN(length, received, fn) { - return function () { - var combined = []; - var argsIdx = 0; - var left = length; - var combinedIdx = 0; - while (combinedIdx < received.length || argsIdx < arguments.length) { - var result; - if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { - result = received[combinedIdx]; - } else { - result = arguments[argsIdx]; - argsIdx += 1; - } - combined[combinedIdx] = result; - if (!_isPlaceholder_1(result)) { - left -= 1; - } - combinedIdx += 1; - } - return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); - }; +function curry(func) { + return curryN(func.length, func); } -var _curryN_1 = _curryN; -/** - * Returns a curried equivalent of the provided function, with the specified - * arity. The curried function has two unusual capabilities. First, its - * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the - * following are equivalent: - * - * - `g(1)(2)(3)` - * - `g(1)(2, 3)` - * - `g(1, 2)(3)` - * - `g(1, 2, 3)` - * - * Secondly, the special placeholder value [`R.__`](#__) may be used to specify - * "gaps", allowing partial application of any combination of arguments, - * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), - * the following are equivalent: - * - * - `g(1, 2, 3)` - * - `g(_, 2, 3)(1)` - * - `g(_, _, 3)(1)(2)` - * - `g(_, _, 3)(1, 2)` - * - `g(_, 2)(1)(3)` - * - `g(_, 2)(1, 3)` - * - `g(_, 2)(_, 3)(1)` - * - * @func - * @memberOf R - * @since v0.5.0 - * @category Function - * @sig Number -> (* -> a) -> (* -> a) - * @param {Number} length The arity for the returned function. - * @param {Function} fn The function to curry. - * @return {Function} A new, curried function. - * @see R.curry - * @example - * - * var sumArgs = (...args) => R.sum(args); - * - * var curriedAddFourNumbers = R.curryN(4, sumArgs); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); - * g(4); //=> 10 - */ - - -var curryN = /*#__PURE__*/_curry2_1(function curryN(length, fn) { - if (length === 1) { - return _curry1_1(fn); - } - return _arity_1(length, _curryN_1(length, [], fn)); -}); -var curryN_1 = curryN; - -// Utility function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -266,7 +107,7 @@ flyd.stream['fantasy-land/of'] = flyd.stream.of = flyd.stream; * return n1() > n2() ? n1() : n2(); * }, [n1, n2]); */ -flyd.combine = curryN_1(2, combine); +flyd.combine = curryN(2, combine); function combine(fn, streams) { var i, s, deps, depEndStreams; var endStream = createDependentStream([], trueFn); @@ -386,7 +227,7 @@ flyd.endsOn = function(endS, s) { function map(f, s) { return combine(function(s, self) { self(f(s.val)); }, [s]); } -flyd.map = curryN_1(2, map); +flyd.map = curryN(2, map); /** * Chain a stream @@ -409,7 +250,7 @@ flyd.map = curryN_1(2, map); * return flyd.stream(findUsers(filter)); * }, filter); */ -flyd.chain = curryN_1(2, chain); +flyd.chain = curryN(2, chain); /** * Apply a stream @@ -435,7 +276,7 @@ flyd.chain = curryN_1(2, chain); * .pipe(ap(n2)); * added_pipe() // 3 */ -flyd.ap = curryN_1(2, ap); +flyd.ap = curryN(2, ap); /** * Listen to stream events @@ -451,7 +292,7 @@ flyd.ap = curryN_1(2, ap); * @param {stream} stream - the stream * @return {stream} an empty stream (can be ended) */ -flyd.on = curryN_1(2, function(f, s) { +flyd.on = curryN(2, function(f, s) { return combine(function(s) { f(s.val); }, [s]); }); @@ -473,7 +314,7 @@ flyd.on = curryN_1(2, function(f, s) { * numbers(2)(3)(5); * sum(); // 10 */ -flyd.scan = curryN_1(3, function(f, acc, s) { +flyd.scan = curryN(3, function(f, acc, s) { var ns = combine(function(s, self) { self(acc = f(acc, s.val)); }, [s]); @@ -499,7 +340,7 @@ flyd.scan = curryN_1(3, function(f, acc, s) { * button2Elm.addEventListener(btn2Clicks); * var allClicks = flyd.merge(btn1Clicks, btn2Clicks); */ -flyd.merge = curryN_1(2, function(s1, s2) { +flyd.merge = curryN(2, function(s1, s2) { var s = flyd.immediate(combine(function(s1, s2, self, changed) { if (changed[0]) { self(changed[0]()); @@ -536,7 +377,7 @@ flyd.merge = curryN_1(2, function(s1, s2) { * s1(1)(1)(2)(3)(3)(3)(4); * results; // => [2, 4, 6, 8] */ -flyd.transduce = curryN_1(2, function(xform, source) { +flyd.transduce = curryN(2, function(xform, source) { xform = xform(new StreamTransformer()); return combine(function(source, self) { var res = xform['@@transducer/step'](undefined, source.val); @@ -564,7 +405,8 @@ flyd.transduce = curryN_1(2, function(xform, source) { * var a = flyd.curryN(2, add); * a(2)(4) // => 6 */ -flyd.curryN = curryN_1; +flyd.curryN = curryN; +flyd.curry = curry; /** * Returns a new stream identical to the original except every diff --git a/examples/multiple-clicks/build.js b/examples/multiple-clicks/build.js index 3cc1dc4..f9413c3 100644 --- a/examples/multiple-clicks/build.js +++ b/examples/multiple-clicks/build.js @@ -1,205 +1,46 @@ var multipleclicks = (function () { 'use strict'; -function _arity(n, fn) { - /* eslint-disable no-unused-vars */ - switch (n) { - case 0: - return function () { - return fn.apply(this, arguments); - }; - case 1: - return function (a0) { - return fn.apply(this, arguments); - }; - case 2: - return function (a0, a1) { - return fn.apply(this, arguments); - }; - case 3: - return function (a0, a1, a2) { - return fn.apply(this, arguments); - }; - case 4: - return function (a0, a1, a2, a3) { - return fn.apply(this, arguments); - }; - case 5: - return function (a0, a1, a2, a3, a4) { - return fn.apply(this, arguments); - }; - case 6: - return function (a0, a1, a2, a3, a4, a5) { - return fn.apply(this, arguments); - }; - case 7: - return function (a0, a1, a2, a3, a4, a5, a6) { - return fn.apply(this, arguments); - }; - case 8: - return function (a0, a1, a2, a3, a4, a5, a6, a7) { - return fn.apply(this, arguments); - }; - case 9: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { - return fn.apply(this, arguments); - }; - case 10: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { - return fn.apply(this, arguments); - }; - default: - throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); - } -} -var _arity_1 = _arity; - -function _isPlaceholder(a) { - return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; -} -var _isPlaceholder_1 = _isPlaceholder; - -/** - * Optimized internal one-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curry1(fn) { - return function f1(a) { - if (arguments.length === 0 || _isPlaceholder_1(a)) { - return f1; - } else { - return fn.apply(this, arguments); +// Utility +var slice = Array.prototype.slice; +var concat = Array.prototype.concat; + +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } + +/** + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. + */ +function curryN(n, func) { + return function() { + var curargs = slice.call(arguments); + + if (curargs.length >= n) { + return func.apply(null, curargs); } - }; -} -var _curry1_1 = _curry1; - -/** - * Optimized internal two-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - -function _curry2(fn) { - return function f2(a, b) { - switch (arguments.length) { - case 0: - return f2; - case 1: - return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { - return fn(a, _b); - }); - default: - return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { - return fn(_a, b); - }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { - return fn(a, _b); - }) : fn(a, b); - } - }; + return curryN(n - curargs.length, function() { + return func.apply(null, concat.call(curargs, slice.call(arguments))); + }); + } } -var _curry2_1 = _curry2; -/** - * Internal curryN function. - * - * @private - * @category Function - * @param {Number} length The arity of the curried function. - * @param {Array} received An array of arguments received thus far. - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curryN(length, received, fn) { - return function () { - var combined = []; - var argsIdx = 0; - var left = length; - var combinedIdx = 0; - while (combinedIdx < received.length || argsIdx < arguments.length) { - var result; - if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { - result = received[combinedIdx]; - } else { - result = arguments[argsIdx]; - argsIdx += 1; - } - combined[combinedIdx] = result; - if (!_isPlaceholder_1(result)) { - left -= 1; - } - combinedIdx += 1; - } - return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); - }; +function curry(func) { + return curryN(func.length, func); } -var _curryN_1 = _curryN; - -/** - * Returns a curried equivalent of the provided function, with the specified - * arity. The curried function has two unusual capabilities. First, its - * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the - * following are equivalent: - * - * - `g(1)(2)(3)` - * - `g(1)(2, 3)` - * - `g(1, 2)(3)` - * - `g(1, 2, 3)` - * - * Secondly, the special placeholder value [`R.__`](#__) may be used to specify - * "gaps", allowing partial application of any combination of arguments, - * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), - * the following are equivalent: - * - * - `g(1, 2, 3)` - * - `g(_, 2, 3)(1)` - * - `g(_, _, 3)(1)(2)` - * - `g(_, _, 3)(1, 2)` - * - `g(_, 2)(1)(3)` - * - `g(_, 2)(1, 3)` - * - `g(_, 2)(_, 3)(1)` - * - * @func - * @memberOf R - * @since v0.5.0 - * @category Function - * @sig Number -> (* -> a) -> (* -> a) - * @param {Number} length The arity for the returned function. - * @param {Function} fn The function to curry. - * @return {Function} A new, curried function. - * @see R.curry - * @example - * - * var sumArgs = (...args) => R.sum(args); - * - * var curriedAddFourNumbers = R.curryN(4, sumArgs); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); - * g(4); //=> 10 - */ - - -var curryN = /*#__PURE__*/_curry2_1(function curryN(length, fn) { - if (length === 1) { - return _curry1_1(fn); - } - return _arity_1(length, _curryN_1(length, [], fn)); -}); -var curryN_1 = curryN; -// Utility function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -266,7 +107,7 @@ flyd.stream['fantasy-land/of'] = flyd.stream.of = flyd.stream; * return n1() > n2() ? n1() : n2(); * }, [n1, n2]); */ -flyd.combine = curryN_1(2, combine); +flyd.combine = curryN(2, combine); function combine(fn, streams) { var i, s, deps, depEndStreams; var endStream = createDependentStream([], trueFn); @@ -386,7 +227,7 @@ flyd.endsOn = function(endS, s) { function map(f, s) { return combine(function(s, self) { self(f(s.val)); }, [s]); } -flyd.map = curryN_1(2, map); +flyd.map = curryN(2, map); /** * Chain a stream @@ -409,7 +250,7 @@ flyd.map = curryN_1(2, map); * return flyd.stream(findUsers(filter)); * }, filter); */ -flyd.chain = curryN_1(2, chain); +flyd.chain = curryN(2, chain); /** * Apply a stream @@ -435,7 +276,7 @@ flyd.chain = curryN_1(2, chain); * .pipe(ap(n2)); * added_pipe() // 3 */ -flyd.ap = curryN_1(2, ap); +flyd.ap = curryN(2, ap); /** * Listen to stream events @@ -451,7 +292,7 @@ flyd.ap = curryN_1(2, ap); * @param {stream} stream - the stream * @return {stream} an empty stream (can be ended) */ -flyd.on = curryN_1(2, function(f, s) { +flyd.on = curryN(2, function(f, s) { return combine(function(s) { f(s.val); }, [s]); }); @@ -473,7 +314,7 @@ flyd.on = curryN_1(2, function(f, s) { * numbers(2)(3)(5); * sum(); // 10 */ -flyd.scan = curryN_1(3, function(f, acc, s) { +flyd.scan = curryN(3, function(f, acc, s) { var ns = combine(function(s, self) { self(acc = f(acc, s.val)); }, [s]); @@ -499,7 +340,7 @@ flyd.scan = curryN_1(3, function(f, acc, s) { * button2Elm.addEventListener(btn2Clicks); * var allClicks = flyd.merge(btn1Clicks, btn2Clicks); */ -flyd.merge = curryN_1(2, function(s1, s2) { +flyd.merge = curryN(2, function(s1, s2) { var s = flyd.immediate(combine(function(s1, s2, self, changed) { if (changed[0]) { self(changed[0]()); @@ -536,7 +377,7 @@ flyd.merge = curryN_1(2, function(s1, s2) { * s1(1)(1)(2)(3)(3)(3)(4); * results; // => [2, 4, 6, 8] */ -flyd.transduce = curryN_1(2, function(xform, source) { +flyd.transduce = curryN(2, function(xform, source) { xform = xform(new StreamTransformer()); return combine(function(source, self) { var res = xform['@@transducer/step'](undefined, source.val); @@ -564,7 +405,8 @@ flyd.transduce = curryN_1(2, function(xform, source) { * var a = flyd.curryN(2, add); * a(2)(4) // => 6 */ -flyd.curryN = curryN_1; +flyd.curryN = curryN; +flyd.curry = curry; /** * Returns a new stream identical to the original except every diff --git a/examples/ramda-transducer/build.js b/examples/ramda-transducer/build.js index 950ce36..1aa8a91 100644 --- a/examples/ramda-transducer/build.js +++ b/examples/ramda-transducer/build.js @@ -1,53 +1,6 @@ var ramdatransducer = (function () { 'use strict'; -function _isPlaceholder(a) { - return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; -} - -/** - * Optimized internal one-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ -function _curry1(fn) { - return function f1(a) { - if (arguments.length === 0 || _isPlaceholder(a)) { - return f1; - } else { - return fn.apply(this, arguments); - } - }; -} - -/** - * Returns a function that always returns the given value. Note that for - * non-primitives the value returned is a reference to the original value. - * - * This function is known as `const`, `constant`, or `K` (for K combinator) in - * other languages and libraries. - * - * @func - * @memberOf R - * @since v0.1.0 - * @category Function - * @sig a -> (* -> a) - * @param {*} val The value to wrap in a function - * @return {Function} A Function :: * -> val. - * @example - * - * var t = R.always('Tee'); - * t(); //=> 'Tee' - */ -var always = /*#__PURE__*/_curry1(function always(val) { - return function () { - return val; - }; -}); - /** * A function that always returns `false`. Any passed in parameters are ignored. * @@ -58,12 +11,14 @@ var always = /*#__PURE__*/_curry1(function always(val) { * @sig * -> Boolean * @param {*} * @return {Boolean} - * @see R.always, R.T + * @see R.T * @example * * R.F(); //=> false */ -var F = /*#__PURE__*/always(false); +var F = function () { + return false; +}; /** * A function that always returns `true`. Any passed in parameters are ignored. @@ -75,12 +30,14 @@ var F = /*#__PURE__*/always(false); * @sig * -> Boolean * @param {*} * @return {Boolean} - * @see R.always, R.F + * @see R.F * @example * * R.T(); //=> true */ -var T = /*#__PURE__*/always(true); +var T = function () { + return true; +}; /** * A special placeholder value used to specify "gaps" within curried functions, @@ -99,16 +56,42 @@ var T = /*#__PURE__*/always(true); * - `g(_, 2)(1, 3)` * - `g(_, 2)(_, 3)(1)` * + * @name __ * @constant * @memberOf R * @since v0.6.0 * @category Function * @example * - * var greet = R.replace('{name}', R.__, 'Hello, {name}!'); + * const greet = R.replace('{name}', R.__, 'Hello, {name}!'); * greet('Alice'); //=> 'Hello, Alice!' */ -var __ = { '@@functional/placeholder': true }; +var __ = { + '@@functional/placeholder': true +}; + +function _isPlaceholder(a) { + return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; +} + +/** + * Optimized internal one-arity curry function. + * + * @private + * @category Function + * @param {Function} fn The function to curry. + * @return {Function} The curried function. + */ + +function _curry1(fn) { + return function f1(a) { + if (arguments.length === 0 || _isPlaceholder(a)) { + return f1; + } else { + return fn.apply(this, arguments); + } + }; +} /** * Optimized internal two-arity curry function. @@ -118,15 +101,18 @@ var __ = { '@@functional/placeholder': true }; * @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); @@ -154,7 +140,10 @@ function _curry2(fn) { * R.add(2, 3); //=> 5 * R.add(7)(10); //=> 17 */ -var add = /*#__PURE__*/_curry2(function add(a, b) { + +var add = +/*#__PURE__*/ +_curry2(function add(a, b) { return Number(a) + Number(b); }); @@ -176,17 +165,20 @@ function _concat(set1, set2) { var len1 = set1.length; var len2 = set2.length; var result = []; - idx = 0; + while (idx < len1) { result[result.length] = set1[idx]; idx += 1; } + idx = 0; + while (idx < len2) { result[result.length] = set2[idx]; idx += 1; } + return result; } @@ -197,46 +189,57 @@ function _arity(n, fn) { 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'); } @@ -252,26 +255,33 @@ function _arity(n, fn) { * @param {Function} fn The function to curry. * @return {Function} The curried function. */ + function _curryN(length, received, fn) { return function () { var combined = []; var argsIdx = 0; var left = length; var combinedIdx = 0; + while (combinedIdx < received.length || argsIdx < arguments.length) { var result; + if (combinedIdx < received.length && (!_isPlaceholder(received[combinedIdx]) || argsIdx >= arguments.length)) { result = received[combinedIdx]; } else { result = arguments[argsIdx]; argsIdx += 1; } + combined[combinedIdx] = result; + if (!_isPlaceholder(result)) { left -= 1; } + combinedIdx += 1; } + return left <= 0 ? fn.apply(this, combined) : _arity(left, _curryN(length, combined, fn)); }; } @@ -311,17 +321,21 @@ function _curryN(length, received, fn) { * @see R.curry * @example * - * var sumArgs = (...args) => R.sum(args); + * const sumArgs = (...args) => R.sum(args); * - * var curriedAddFourNumbers = R.curryN(4, sumArgs); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); + * const curriedAddFourNumbers = R.curryN(4, sumArgs); + * const f = curriedAddFourNumbers(1, 2); + * const g = f(3); * g(4); //=> 10 */ -var curryN = /*#__PURE__*/_curry2(function curryN(length, fn) { + +var curryN = +/*#__PURE__*/ +_curry2(function curryN(length, fn) { if (length === 1) { return _curry1(fn); } + return _arity(length, _curryN(length, [], fn)); }); @@ -340,26 +354,31 @@ var curryN = /*#__PURE__*/_curry2(function curryN(length, fn) { * @since v0.15.0 * @category Function * @category List - * @sig ((a ... -> b) ... -> [a] -> *) -> (a ..., Int, [a] -> b) ... -> [a] -> *) + * @sig ((a ... -> b) ... -> [a] -> *) -> ((a ..., Int, [a] -> b) ... -> [a] -> *) * @param {Function} fn A list iteration function that does not pass index or list to its callback * @return {Function} An altered list iteration function that passes (item, index, list) to its callback * @example * - * var mapIndexed = R.addIndex(R.map); + * const mapIndexed = R.addIndex(R.map); * 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 = /*#__PURE__*/_curry1(function addIndex(fn) { + +var addIndex = +/*#__PURE__*/ +_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); }); }); @@ -372,15 +391,18 @@ var addIndex = /*#__PURE__*/_curry1(function addIndex(fn) { * @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); @@ -389,6 +411,7 @@ function _curry3(fn) { }) : _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); @@ -416,9 +439,9 @@ function _curry3(fn) { * @memberOf R * @since v0.14.0 * @category List - * @sig (a -> a) -> Number -> [a] -> [a] - * @param {Function} fn The function to apply. + * @sig Number -> (a -> a) -> [a] -> [a] * @param {Number} idx The index. + * @param {Function} fn The function to apply. * @param {Array|Arguments} list An array-like object whose value * at the supplied index will be replaced. * @return {Array} A copy of the supplied array-like object with @@ -427,18 +450,25 @@ function _curry3(fn) { * @see R.update * @example * - * R.adjust(R.add(10), 1, [1, 2, 3]); //=> [1, 12, 3] - * R.adjust(R.add(10))(1)([1, 2, 3]); //=> [1, 12, 3] - * @symb R.adjust(f, -1, [a, b]) = [a, f(b)] - * @symb R.adjust(f, 0, [a, b]) = [f(a), b] + * R.adjust(1, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'B', 'c', 'd'] + * R.adjust(-1, R.toUpper, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c', 'D'] + * @symb R.adjust(-1, f, [a, b]) = [a, f(b)] + * @symb R.adjust(0, f, [a, b]) = [f(a), b] */ -var adjust = /*#__PURE__*/_curry3(function adjust(fn, idx, list) { + +var adjust = +/*#__PURE__*/ +_curry3(function adjust(idx, fn, list) { if (idx >= list.length || idx < -list.length) { return list; } + var start = idx < 0 ? list.length : 0; + var _idx = start + idx; + var _list = _concat(list); + _list[_idx] = fn(list[_idx]); return _list; }); @@ -460,7 +490,7 @@ var _isArray = Array.isArray || function _isArray(val) { }; function _isTransformer(obj) { - return typeof obj['@@transducer/step'] === 'function'; + return obj != null && typeof obj['@@transducer/step'] === 'function'; } /** @@ -477,26 +507,33 @@ function _isTransformer(obj) { * @param {Function} fn default ramda implementation * @return {Function} A function that dispatches on object in list position */ + function _dispatchable(methodNames, xf, fn) { return function () { if (arguments.length === 0) { return fn(); } + var args = Array.prototype.slice.call(arguments, 0); var obj = args.pop(); + if (!_isArray(obj)) { var idx = 0; + while (idx < methodNames.length) { if (typeof obj[methodNames[idx]] === 'function') { return obj[methodNames[idx]].apply(obj, args); } + idx += 1; } + if (_isTransformer(obj)) { var transducer = xf.apply(null, args); return transducer(obj); } } + return fn.apply(this, arguments); }; } @@ -517,31 +554,40 @@ var _xfBase = { } }; -var XAll = /*#__PURE__*/function () { +var XAll = +/*#__PURE__*/ +function () { function XAll(f, xf) { this.xf = xf; this.f = f; this.all = true; } + XAll.prototype['@@transducer/init'] = _xfBase.init; + XAll.prototype['@@transducer/result'] = function (result) { if (this.all) { result = this.xf['@@transducer/step'](result, true); } + return this.xf['@@transducer/result'](result); }; + XAll.prototype['@@transducer/step'] = function (result, input) { if (!this.f(input)) { this.all = false; result = _reduced(this.xf['@@transducer/step'](result, false)); } + return result; }; return XAll; }(); -var _xall = /*#__PURE__*/_curry2(function _xall(f, xf) { +var _xall = +/*#__PURE__*/ +_curry2(function _xall(f, xf) { return new XAll(f, xf); }); @@ -565,18 +611,26 @@ var _xall = /*#__PURE__*/_curry2(function _xall(f, xf) { * @see R.any, R.none, R.transduce * @example * - * var equals3 = R.equals(3); + * const equals3 = R.equals(3); * R.all(equals3)([3, 3, 3, 3]); //=> true * R.all(equals3)([3, 3, 1, 3]); //=> false */ -var all = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['all'], _xall, function all(fn, list) { + +var all = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable(['all'], _xall, function all(fn, list) { var idx = 0; + while (idx < list.length) { if (!fn(list[idx])) { return false; } + idx += 1; } + return true; })); @@ -597,7 +651,10 @@ var all = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['all'], _xall, funct * R.max(789, 123); //=> 789 * R.max('a', 'b'); //=> 'b' */ -var max = /*#__PURE__*/_curry2(function max(a, b) { + +var max = +/*#__PURE__*/ +_curry2(function max(a, b) { return b > a ? b : a; }); @@ -605,10 +662,12 @@ function _map(fn, functor) { var idx = 0; var len = functor.length; var result = Array(len); + while (idx < len) { result[idx] = fn(functor[idx]); idx += 1; } + return result; } @@ -633,41 +692,56 @@ function _isString(x) { * _isArrayLike({length: 10}); //=> false * _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true */ -var _isArrayLike = /*#__PURE__*/_curry1(function isArrayLike(x) { + +var _isArrayLike = +/*#__PURE__*/ +_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.nodeType === 1) { return !!x.length; } + if (x.length === 0) { return true; } + if (x.length > 0) { return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1); } + return false; }); -var XWrap = /*#__PURE__*/function () { +var XWrap = +/*#__PURE__*/ +function () { function XWrap(fn) { this.f = fn; } + XWrap.prototype['@@transducer/init'] = function () { throw new Error('init not implemented on XWrap'); }; + XWrap.prototype['@@transducer/result'] = function (acc) { return acc; }; + XWrap.prototype['@@transducer/step'] = function (acc, x) { return this.f(acc, x); }; @@ -696,12 +770,15 @@ function _xwrap(fn) { * @see R.partial * @example * - * var log = R.bind(console.log, console); + * const log = R.bind(console.log, console); * R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3} * // logs {a: 2} * @symb R.bind(f, o)(a, b) = f.call(o, a, b) */ -var bind = /*#__PURE__*/_curry2(function bind(fn, thisObj) { + +var bind = +/*#__PURE__*/ +_curry2(function bind(fn, thisObj) { return _arity(fn.length, function () { return fn.apply(thisObj, arguments); }); @@ -710,27 +787,35 @@ var bind = /*#__PURE__*/_curry2(function bind(fn, thisObj) { function _arrayReduce(xf, acc, list) { var idx = 0; var len = list.length; + while (idx < len) { acc = xf['@@transducer/step'](acc, list[idx]); + if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } + idx += 1; } + return xf['@@transducer/result'](acc); } function _iterableReduce(xf, acc, iter) { var step = iter.next(); + while (!step.done) { acc = xf['@@transducer/step'](acc, step.value); + if (acc && acc['@@transducer/reduced']) { acc = acc['@@transducer/value']; break; } + step = iter.next(); } + return xf['@@transducer/result'](acc); } @@ -739,23 +824,27 @@ function _methodReduce(xf, acc, obj, methodName) { } var symIterator = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator'; - function _reduce(fn, acc, list) { if (typeof fn === 'function') { fn = _xwrap(fn); } + if (_isArrayLike(list)) { return _arrayReduce(fn, acc, list); } + if (typeof list['fantasy-land/reduce'] === 'function') { return _methodReduce(fn, acc, list, 'fantasy-land/reduce'); } + if (list[symIterator] != null) { return _iterableReduce(fn, acc, list[symIterator]()); } + if (typeof list.next === 'function') { return _iterableReduce(fn, acc, list); } + if (typeof list.reduce === 'function') { return _methodReduce(fn, acc, list, 'reduce'); } @@ -763,13 +852,17 @@ function _reduce(fn, acc, list) { throw new TypeError('reduce: list must be array or iterable'); } -var XMap = /*#__PURE__*/function () { +var XMap = +/*#__PURE__*/ +function () { function XMap(f, xf) { this.xf = xf; this.f = f; } + XMap.prototype['@@transducer/init'] = _xfBase.init; XMap.prototype['@@transducer/result'] = _xfBase.result; + XMap.prototype['@@transducer/step'] = function (result, input) { return this.xf['@@transducer/step'](result, this.f(input)); }; @@ -777,7 +870,9 @@ var XMap = /*#__PURE__*/function () { return XMap; }(); -var _xmap = /*#__PURE__*/_curry2(function _xmap(f, xf) { +var _xmap = +/*#__PURE__*/ +_curry2(function _xmap(f, xf) { return new XMap(f, xf); }); @@ -786,34 +881,44 @@ function _has(prop, obj) { } var toString = Object.prototype.toString; -var _isArguments = function () { + +var _isArguments = +/*#__PURE__*/ +function () { return toString.call(arguments) === '[object Arguments]' ? function _isArguments(x) { return toString.call(x) === '[object Arguments]'; } : function _isArguments(x) { return _has('callee', x); }; -}; +}(); -// cover IE < 9 keys issues -var hasEnumBug = ! /*#__PURE__*/{ toString: null }.propertyIsEnumerable('toString'); -var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; -// Safari bug -var hasArgsEnumBug = /*#__PURE__*/function () { +var hasEnumBug = ! +/*#__PURE__*/ +{ + toString: null +}.propertyIsEnumerable('toString'); +var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; // Safari bug + +var hasArgsEnumBug = +/*#__PURE__*/ +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. @@ -832,33 +937,46 @@ var contains = function contains(list, item) { * * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c'] */ -var _keys = typeof Object.keys === 'function' && !hasArgsEnumBug ? function keys(obj) { + + +var keys = typeof Object.keys === 'function' && !hasArgsEnumBug ? +/*#__PURE__*/ +_curry1(function keys(obj) { return Object(obj) !== obj ? [] : Object.keys(obj); -} : function keys(obj) { +}) : +/*#__PURE__*/ +_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; -}; -var keys = /*#__PURE__*/_curry1(_keys); +}); /** * Takes a function and @@ -886,7 +1004,7 @@ var keys = /*#__PURE__*/_curry1(_keys); * @see R.transduce, R.addIndex * @example * - * var double = x => x * 2; + * const double = x => x * 2; * * R.map(double, [1, 2, 3]); //=> [2, 4, 6] * @@ -895,22 +1013,116 @@ var keys = /*#__PURE__*/_curry1(_keys); * @symb R.map(f, { x: a, y: b }) = { x: f(a), y: f(b) } * @symb R.map(f, functor_o) = functor_o.map(f) */ -var map = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['fantasy-land/map', 'map'], _xmap, function map(fn, functor) { + +var map = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_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 _reduce(function (acc, key) { acc[key] = fn(functor[key]); return acc; }, {}, keys(functor)); + default: return _map(fn, functor); } })); +/** + * Determine if the passed argument is an integer. + * + * @private + * @param {*} n + * @category Type + * @return {Boolean} + */ +var _isInteger = Number.isInteger || function _isInteger(n) { + return n << 0 === n; +}; + +/** + * 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 = +/*#__PURE__*/ +_curry2(function nth(offset, list) { + var idx = offset < 0 ? list.length + offset : offset; + return _isString(list) ? list.charAt(idx) : list[idx]; +}); + +/** + * Retrieves the values at given paths of an object. + * + * @func + * @memberOf R + * @since v0.27.1 + * @category Object + * @typedefn Idx = [String | Int] + * @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 = +/*#__PURE__*/ +_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; + }); +}); + /** * Retrieve the value at a given path. * @@ -923,23 +1135,19 @@ var map = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['fantasy-land/map', * @param {Array} path The path to use. * @param {Object} obj The object to retrieve the nested property from. * @return {*} The data at `path`. - * @see R.prop + * @see R.prop, R.nth * @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 */ -var path = /*#__PURE__*/_curry2(function path(paths, obj) { - var val = obj; - var idx = 0; - while (idx < paths.length) { - if (val == null) { - return; - } - val = val[paths[idx]]; - idx += 1; - } - return val; + +var path = +/*#__PURE__*/ +_curry2(function path(pathAr, obj) { + return paths([pathAr], obj)[0]; }); /** @@ -950,18 +1158,23 @@ var path = /*#__PURE__*/_curry2(function path(paths, obj) { * @memberOf R * @since v0.1.0 * @category Object - * @sig s -> {s: a} -> a | Undefined - * @param {String} p The property name + * @typedefn Idx = String | Int + * @sig Idx -> {s: a} -> a | Undefined + * @param {String|Number} p The property name or array index * @param {Object} obj The object to query * @return {*} The value at `obj.p`. - * @see R.path + * @see R.path, R.nth * @example * * R.prop('x', {x: 100}); //=> 100 * R.prop('x', {}); //=> undefined + * R.prop(0, [100]); //=> 100 + * R.compose(R.inc, R.prop('x'))({ x: 3 }) //=> 4 */ -var prop = /*#__PURE__*/_curry2(function prop(p, obj) { +var prop = +/*#__PURE__*/ +_curry2(function prop(p, obj) { return path([p], obj); }); @@ -984,13 +1197,18 @@ var prop = /*#__PURE__*/_curry2(function prop(p, obj) { * @see R.props * @example * - * R.pluck('a')([{a: 1}, {a: 2}]); //=> [1, 2] - * R.pluck(0)([[1, 2], [3, 4]]); //=> [1, 3] + * var getAges = R.pluck('age'); + * getAges([{name: 'fred', age: 29}, {name: 'wilma', age: 27}]); //=> [29, 27] + * + * R.pluck(0, [[1, 2], [3, 4]]); //=> [1, 3] * R.pluck('val', {a: {val: 3}, b: {val: 5}}); //=> {a: 3, b: 5} * @symb R.pluck('x', [{x: 1, y: 2}, {x: 3, y: 4}, {x: 5, y: 6}]) = [1, 3, 5] * @symb R.pluck(0, [[1, 2], [3, 4], [5, 6]]) = [1, 3, 5] */ -var pluck = /*#__PURE__*/_curry2(function pluck(p, list) { + +var pluck = +/*#__PURE__*/ +_curry2(function pluck(p, list) { return map(prop(p), list); }); @@ -1040,7 +1258,10 @@ var pluck = /*#__PURE__*/_curry2(function pluck(p, list) { * * @symb R.reduce(f, a, [b, c, d]) = f(f(f(a, b), c), d) */ -var reduce = /*#__PURE__*/_curry3(_reduce); + +var reduce = +/*#__PURE__*/ +_curry3(_reduce); /** * Takes a list of predicates and returns a predicate that returns true for a @@ -1060,27 +1281,61 @@ var reduce = /*#__PURE__*/_curry3(_reduce); * @see R.anyPass * @example * - * var isQueen = R.propEq('rank', 'Q'); - * var isSpade = R.propEq('suit', '♠︎'); - * var isQueenOfSpades = R.allPass([isQueen, isSpade]); + * const isQueen = R.propEq('rank', 'Q'); + * const isSpade = R.propEq('suit', '♠︎'); + * const isQueenOfSpades = R.allPass([isQueen, isSpade]); * * isQueenOfSpades({rank: 'Q', suit: '♣︎'}); //=> false * isQueenOfSpades({rank: 'Q', suit: '♠︎'}); //=> true */ -var allPass = /*#__PURE__*/_curry1(function allPass(preds) { + +var allPass = +/*#__PURE__*/ +_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; }); }); +/** + * Returns a function that always returns the given value. Note that for + * non-primitives the value returned is a reference to the original value. + * + * This function is known as `const`, `constant`, or `K` (for K combinator) in + * other languages and libraries. + * + * @func + * @memberOf R + * @since v0.1.0 + * @category Function + * @sig a -> (* -> a) + * @param {*} val The value to wrap in a function + * @return {Function} A Function :: * -> val. + * @example + * + * const t = R.always('Tee'); + * t(); //=> 'Tee' + */ + +var always = +/*#__PURE__*/ +_curry1(function always(val) { + return function () { + return val; + }; +}); + /** * Returns `true` if both arguments are `true`; `false` otherwise. * @@ -1092,7 +1347,7 @@ var allPass = /*#__PURE__*/_curry1(function allPass(preds) { * @param {Any} a * @param {Any} b * @return {Any} the first argument if it is falsy, otherwise the second argument. - * @see R.both + * @see R.both, R.xor * @example * * R.and(true, true); //=> true @@ -1100,40 +1355,52 @@ var allPass = /*#__PURE__*/_curry1(function allPass(preds) { * R.and(false, true); //=> false * R.and(false, false); //=> false */ -var and = /*#__PURE__*/_curry2(function and(a, b) { + +var and = +/*#__PURE__*/ +_curry2(function and(a, b) { return a && b; }); -var XAny = /*#__PURE__*/function () { +var XAny = +/*#__PURE__*/ +function () { function XAny(f, xf) { this.xf = xf; 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; }; return XAny; }(); -var _xany = /*#__PURE__*/_curry2(function _xany(f, xf) { +var _xany = +/*#__PURE__*/ +_curry2(function _xany(f, xf) { return new XAny(f, xf); }); /** - * Returns `true` if at least one of elements of the list match the predicate, + * Returns `true` if at least one of the elements of the list match the predicate, * `false` otherwise. * * Dispatches to the `any` method of the second argument, if present. @@ -1152,19 +1419,27 @@ var _xany = /*#__PURE__*/_curry2(function _xany(f, xf) { * @see R.all, R.none, R.transduce * @example * - * var lessThan0 = R.flip(R.lt)(0); - * var lessThan2 = R.flip(R.lt)(2); + * const lessThan0 = R.flip(R.lt)(0); + * const lessThan2 = R.flip(R.lt)(2); * R.any(lessThan0)([1, 2]); //=> false * R.any(lessThan2)([1, 2]); //=> true */ -var any = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['any'], _xany, function any(fn, list) { + +var any = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable(['any'], _xany, function any(fn, list) { var idx = 0; + while (idx < list.length) { if (fn(list[idx])) { return true; } + idx += 1; } + return false; })); @@ -1186,24 +1461,30 @@ var any = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['any'], _xany, funct * @see R.allPass * @example * - * var isClub = R.propEq('suit', '♣'); - * var isSpade = R.propEq('suit', '♠'); - * var isBlackCard = R.anyPass([isClub, isSpade]); + * const isClub = R.propEq('suit', '♣'); + * const isSpade = R.propEq('suit', '♠'); + * const isBlackCard = R.anyPass([isClub, isSpade]); * * isBlackCard({rank: '10', suit: '♣'}); //=> true * isBlackCard({rank: 'Q', suit: '♠'}); //=> true * isBlackCard({rank: 'Q', suit: '♦'}); //=> false */ -var anyPass = /*#__PURE__*/_curry1(function anyPass(preds) { + +var anyPass = +/*#__PURE__*/ +_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; }); }); @@ -1220,7 +1501,7 @@ var anyPass = /*#__PURE__*/_curry1(function anyPass(preds) { * @category Function * @sig [a -> b] -> [a] -> [b] * @sig Apply f => f (a -> b) -> f a -> f b - * @sig (a -> b -> c) -> (a -> b) -> (a -> c) + * @sig (r -> a -> b) -> (r -> a) -> (r -> b) * @param {*} applyF * @param {*} applyX * @return {*} @@ -1234,12 +1515,13 @@ var anyPass = /*#__PURE__*/_curry1(function anyPass(preds) { * R.ap(R.concat, R.toUpper)('Ramda') //=> 'RamdaRAMDA' * @symb R.ap([f, g], [a, b]) = [f(a), f(b), g(a), g(b)] */ -var ap = /*#__PURE__*/_curry2(function ap(applyF, applyX) { + +var ap = +/*#__PURE__*/ +_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)); - } : - // else - _reduce(function (acc, f) { + } : _reduce(function (acc, f) { return _concat(acc, map(f, applyX)); }, [], applyF); }); @@ -1248,37 +1530,47 @@ function _aperture(n, list) { 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; } -var XAperture = /*#__PURE__*/function () { +var XAperture = +/*#__PURE__*/ +function () { function XAperture(n, xf) { this.xf = xf; this.pos = 0; 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)); }; @@ -1286,7 +1578,9 @@ var XAperture = /*#__PURE__*/function () { return XAperture; }(); -var _xaperture = /*#__PURE__*/_curry2(function _xaperture(n, xf) { +var _xaperture = +/*#__PURE__*/ +_curry2(function _xaperture(n, xf) { return new XAperture(n, xf); }); @@ -1311,7 +1605,12 @@ var _xaperture = /*#__PURE__*/_curry2(function _xaperture(n, xf) { * 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 = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xaperture, _aperture)); + +var aperture = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable([], _xaperture, _aperture)); /** * Returns a new list containing the contents of the given list, followed by @@ -1333,7 +1632,10 @@ var aperture = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xaperture, * R.append('tests', []); //=> ['tests'] * R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']] */ -var append = /*#__PURE__*/_curry2(function append(el, list) { + +var append = +/*#__PURE__*/ +_curry2(function append(el, list) { return _concat(list, [el]); }); @@ -1353,11 +1655,14 @@ var append = /*#__PURE__*/_curry2(function append(el, list) { * @see R.call, R.unapply * @example * - * var nums = [1, 2, 3, -99, 42, 6, 7]; + * const nums = [1, 2, 3, -99, 42, 6, 7]; * R.apply(Math.max, nums); //=> 42 * @symb R.apply(f, [a, b, c]) = f(a, b, c) */ -var apply = /*#__PURE__*/_curry2(function apply(fn, args) { + +var apply = +/*#__PURE__*/ +_curry2(function apply(fn, args) { return fn.apply(this, args); }); @@ -1378,18 +1683,31 @@ var apply = /*#__PURE__*/_curry2(function apply(fn, args) { * * R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3] */ -var values = /*#__PURE__*/_curry1(function values(obj) { + +var values = +/*#__PURE__*/ +_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; }); +// delegating calls to .map + +function mapValues(fn, obj) { + return 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 @@ -1408,45 +1726,52 @@ var values = /*#__PURE__*/_curry1(function values(obj) { * @see R.converge, R.juxt * @example * - * var getMetrics = R.applySpec({ + * const getMetrics = R.applySpec({ * sum: R.add, * nested: { mul: R.multiply } * }); * getMetrics(2, 4); // => { sum: 6, nested: { mul: 8 } } * @symb R.applySpec({ x: f, y: { z: g } })(a, b) = { x: f(a, b), y: { z: g(a, b) } } */ -var applySpec = /*#__PURE__*/_curry1(function applySpec(spec) { - spec = map(function (v) { + + +var applySpec = +/*#__PURE__*/ +_curry1(function applySpec(spec) { + spec = mapValues(function (v) { return typeof v == 'function' ? v : applySpec(v); }, spec); return curryN(reduce(max, 0, pluck('length', values(spec))), function () { var args = arguments; - return map(function (f) { + return mapValues(function (f) { return apply(f, args); }, spec); }); }); /** -* Takes a value and applies a function to it. -* -* This function is also known as the `thrush` combinator. -* -* @func -* @memberOf R + * Takes a value and applies a function to it. + * + * This function is also known as the `thrush` combinator. + * + * @func + * @memberOf R * @since v0.25.0 -* @category Function -* @sig a -> (a -> b) -> b -* @param {*} x The value -* @param {Function} f The function to apply -* @return {*} The result of applying `f` to `x` -* @example -* -* var t42 = R.applyTo(42); -* t42(R.identity); //=> 42 -* t42(R.add(1)); //=> 43 -*/ -var applyTo = /*#__PURE__*/_curry2(function applyTo(x, f) { + * @category Function + * @sig a -> (a -> b) -> b + * @param {*} x The value + * @param {Function} f The function to apply + * @return {*} The result of applying `f` to `x` + * @example + * + * const t42 = R.applyTo(42); + * t42(R.identity); //=> 42 + * t42(R.add(1)); //=> 43 + */ + +var applyTo = +/*#__PURE__*/ +_curry2(function applyTo(x, f) { return f(x); }); @@ -1466,13 +1791,19 @@ var applyTo = /*#__PURE__*/_curry2(function applyTo(x, f) { * @see R.descend * @example * - * var byAge = R.ascend(R.prop('age')); - * var people = [ - * // ... + * const byAge = R.ascend(R.prop('age')); + * const people = [ + * { name: 'Emma', age: 70 }, + * { name: 'Peter', age: 78 }, + * { name: 'Mikhail', age: 62 }, * ]; - * var peopleByYoungestFirst = R.sort(byAge, people); + * const peopleByYoungestFirst = R.sort(byAge, people); + * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }] */ -var ascend = /*#__PURE__*/_curry3(function ascend(fn, a, b) { + +var ascend = +/*#__PURE__*/ +_curry3(function ascend(fn, a, b) { var aa = fn(a); var bb = fn(b); return aa < bb ? -1 : aa > bb ? 1 : 0; @@ -1493,32 +1824,25 @@ var ascend = /*#__PURE__*/_curry3(function ascend(fn, a, b) { * @param {*} val The new value * @param {Object} obj The object to clone * @return {Object} A new object equivalent to the original except for the changed property. - * @see R.dissoc + * @see R.dissoc, R.pick * @example * * R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3} */ -var assoc = /*#__PURE__*/_curry3(function assoc(prop, val, obj) { + +var assoc = +/*#__PURE__*/ +_curry3(function assoc(prop, val, obj) { var result = {}; + for (var p in obj) { result[p] = obj[p]; } + result[prop] = val; return result; }); -/** - * Determine if the passed argument is an integer. - * - * @private - * @param {*} n - * @category Type - * @return {Boolean} - */ -var _isInteger = Number.isInteger || function _isInteger(n) { - return n << 0 === n; -}; - /** * Checks if the input value is `null` or `undefined`. * @@ -1536,7 +1860,10 @@ var _isInteger = Number.isInteger || function _isInteger(n) { * R.isNil(0); //=> false * R.isNil([]); //=> false */ -var isNil = /*#__PURE__*/_curry1(function isNil(x) { + +var isNil = +/*#__PURE__*/ +_curry1(function isNil(x) { return x == null; }); @@ -1564,15 +1891,21 @@ var isNil = /*#__PURE__*/_curry1(function isNil(x) { * // Any missing or non-object keys in path will be overridden * R.assocPath(['a', 'b', 'c'], 42, {a: 5}); //=> {a: {b: {c: 42}}} */ -var assocPath = /*#__PURE__*/_curry3(function assocPath(path, val, obj) { + +var assocPath = +/*#__PURE__*/ +_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) ? obj[idx] : _isInteger(path[1]) ? [] : {}; val = assocPath(Array.prototype.slice.call(path, 1), val, nextObj); } + if (_isInteger(idx) && _isArray(obj)) { var arr = [].concat(obj); arr[idx] = val; @@ -1599,12 +1932,12 @@ var assocPath = /*#__PURE__*/_curry3(function assocPath(path, val, obj) { * @see R.binary, R.unary * @example * - * var takesTwoArgs = (a, b) => [a, b]; + * const takesTwoArgs = (a, b) => [a, b]; * * takesTwoArgs.length; //=> 2 * takesTwoArgs(1, 2); //=> [1, 2] * - * var takesOneArg = R.nAry(1, takesTwoArgs); + * const takesOneArg = R.nAry(1, takesTwoArgs); * takesOneArg.length; //=> 1 * // Only `n` arguments are passed to the wrapped function * takesOneArg(1, 2); //=> [1, undefined] @@ -1612,52 +1945,66 @@ var assocPath = /*#__PURE__*/_curry3(function assocPath(path, val, obj) { * @symb R.nAry(1, f)(a, b) = f(a) * @symb R.nAry(2, f)(a, b) = f(a, b) */ -var nAry = /*#__PURE__*/_curry2(function nAry(n, fn) { + +var nAry = +/*#__PURE__*/ +_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'); } @@ -1679,24 +2026,28 @@ var nAry = /*#__PURE__*/_curry2(function nAry(n, fn) { * @see R.nAry, R.unary * @example * - * var takesThreeArgs = function(a, b, c) { + * const takesThreeArgs = function(a, b, c) { * return [a, b, c]; * }; * takesThreeArgs.length; //=> 3 * takesThreeArgs(1, 2, 3); //=> [1, 2, 3] * - * var takesTwoArgs = R.binary(takesThreeArgs); + * const takesTwoArgs = R.binary(takesThreeArgs); * takesTwoArgs.length; //=> 2 * // Only 2 arguments are passed to the wrapped function * takesTwoArgs(1, 2, 3); //=> [1, 2, undefined] * @symb R.binary(f)(a, b, c) = f(a, b) */ -var binary = /*#__PURE__*/_curry1(function binary(fn) { + +var binary = +/*#__PURE__*/ +_curry1(function binary(fn) { return nAry(2, fn); }); function _isFunction(x) { - return Object.prototype.toString.call(x) === '[object Function]'; + var type = Object.prototype.toString.call(x); + return type === '[object Function]' || type === '[object AsyncFunction]' || type === '[object GeneratorFunction]' || type === '[object AsyncGeneratorFunction]'; } /** @@ -1713,10 +2064,13 @@ function _isFunction(x) { * @see R.lift, R.ap * @example * - * var madd3 = R.liftN(3, (...args) => R.sum(args)); + * 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 = /*#__PURE__*/_curry2(function liftN(arity, fn) { + +var liftN = +/*#__PURE__*/ +_curry2(function liftN(arity, fn) { var lifted = curryN(arity, fn); return curryN(arity, function () { return _reduce(ap, map(lifted, arguments[0]), Array.prototype.slice.call(arguments, 1)); @@ -1737,15 +2091,18 @@ var liftN = /*#__PURE__*/_curry2(function liftN(arity, fn) { * @see R.liftN * @example * - * var madd3 = R.lift((a, b, c) => a + b + c); + * const madd3 = R.lift((a, b, c) => a + b + c); * * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] * - * var madd5 = R.lift((a, b, c, d, e) => a + b + c + d + e); + * const madd5 = R.lift((a, b, c, d, e) => a + b + c + d + e); * * madd5([1,2], [3], [4, 5], [6], [7, 8]); //=> [21, 22, 22, 23, 22, 23, 23, 24] */ -var lift = /*#__PURE__*/_curry1(function lift(fn) { + +var lift = +/*#__PURE__*/ +_curry1(function lift(fn) { return liftN(fn.length, fn); }); @@ -1771,13 +2128,19 @@ var lift = /*#__PURE__*/_curry1(function lift(fn) { * @see R.and * @example * - * var gt10 = R.gt(R.__, 10) - * var lt20 = R.lt(R.__, 20) - * var f = R.both(gt10, lt20); + * const gt10 = R.gt(R.__, 10) + * const lt20 = R.lt(R.__, 20) + * const f = R.both(gt10, lt20); * f(15); //=> true * f(30); //=> false + * + * R.both(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(false) + * R.both([false, false, 'a'], [11]); //=> [false, false, 11] */ -var both = /*#__PURE__*/_curry2(function both(f, g) { + +var both = +/*#__PURE__*/ +_curry2(function both(f, g) { return _isFunction(f) ? function _both() { return f.apply(this, arguments) && g.apply(this, arguments); } : lift(and)(f, g); @@ -1814,17 +2177,20 @@ var both = /*#__PURE__*/_curry2(function both(f, g) { * @sig (* -> a) -> (* -> a) * @param {Function} fn The function to curry. * @return {Function} A new, curried function. - * @see R.curryN + * @see R.curryN, R.partial * @example * - * var addFourNumbers = (a, b, c, d) => a + b + c + d; + * const addFourNumbers = (a, b, c, d) => a + b + c + d; * - * var curriedAddFourNumbers = R.curry(addFourNumbers); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); + * const curriedAddFourNumbers = R.curry(addFourNumbers); + * const f = curriedAddFourNumbers(1, 2); + * const g = f(3); * g(4); //=> 10 */ -var curry = /*#__PURE__*/_curry1(function curry(fn) { + +var curry = +/*#__PURE__*/ +_curry1(function curry(fn) { return curryN(fn.length, fn); }); @@ -1848,11 +2214,11 @@ var curry = /*#__PURE__*/_curry1(function curry(fn) { * * R.call(R.add, 1, 2); //=> 3 * - * var indentN = R.pipe(R.repeat(' '), + * const indentN = R.pipe(R.repeat(' '), * R.join(''), * R.replace(/^(?!$)/gm)); * - * var format = R.converge(R.call, [ + * const format = R.converge(R.call, [ * R.pipe(R.prop('indent'), indentN), * R.prop('value') * ]); @@ -1860,7 +2226,10 @@ var curry = /*#__PURE__*/_curry1(function curry(fn) { * format({indent: 2, value: 'foo\nbar\nbaz\n'}); //=> ' foo\n bar\n baz\n' * @symb R.call(f, a, b) = f(a, b) */ -var call = /*#__PURE__*/curry(function call(fn) { + +var call = +/*#__PURE__*/ +curry(function call(fn) { return fn.apply(this, Array.prototype.slice.call(arguments, 1)); }); @@ -1870,6 +2239,7 @@ var call = /*#__PURE__*/curry(function call(fn) { * * @private */ + function _makeFlat(recursive) { return function flatt(list) { var value, jlen, j; @@ -1882,6 +2252,7 @@ function _makeFlat(recursive) { value = recursive ? flatt(list[idx]) : list[idx]; j = 0; jlen = value.length; + while (j < jlen) { result[result.length] = value[j]; j += 1; @@ -1889,8 +2260,10 @@ function _makeFlat(recursive) { } else { result[result.length] = list[idx]; } + idx += 1; } + return result; }; } @@ -1928,17 +2301,23 @@ var _flatCat = function _xcat(xf) { }; }; -var _xchain = /*#__PURE__*/_curry2(function _xchain(f, xf) { +var _xchain = +/*#__PURE__*/ +_curry2(function _xchain(f, xf) { return map(f, _flatCat(xf)); }); /** * `chain` maps a function over a list and concatenates the results. `chain` - * is also known as `flatMap` in some libraries + * is also known as `flatMap` in some libraries. * * Dispatches to the `chain` method of the second argument, if present, * according to the [FantasyLand Chain spec](https://github.com/fantasyland/fantasy-land#chain). * + * If second argument is a function, `chain(f, g)(x)` is equivalent to `f(g(x), x)`. + * + * Acts as a transducer if a transformer is given in list position. + * * @func * @memberOf R * @since v0.3.0 @@ -1949,17 +2328,23 @@ var _xchain = /*#__PURE__*/_curry2(function _xchain(f, xf) { * @return {Array} The result of flat-mapping `list` with `fn` * @example * - * var duplicate = n => [n, n]; + * const duplicate = n => [n, n]; * R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3] * * R.chain(R.append, R.head)([1, 2, 3]); //=> [1, 2, 3, 1] */ -var chain = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['fantasy-land/chain', 'chain'], _xchain, function chain(fn, monad) { + +var chain = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_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)); })); @@ -1983,15 +2368,19 @@ var chain = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['fantasy-land/chai * R.clamp(1, 10, 15) // => 10 * R.clamp(1, 10, 4) // => 4 */ -var clamp = /*#__PURE__*/_curry3(function clamp(min, max, value) { + +var clamp = +/*#__PURE__*/ +_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; }); function _cloneRegExp(pattern) { - return new RegExp(pattern.source, (pattern.global ? 'g' : '') + (pattern.ignoreCase ? 'i' : '') + (pattern.multiline ? 'm' : '') + (pattern.sticky ? 'y' : '') + (pattern.unicode ? 'u' : '')); + return new RegExp(pattern.source, (pattern.global ? 'g' : '') + (pattern.ignoreCase ? 'i' : '') + (pattern.multiline ? 'm' : '') + (pattern.sticky ? 'y' : '') + (pattern.unicode ? 'u' : '')); } /** @@ -2019,7 +2408,10 @@ function _cloneRegExp(pattern) { * R.type(() => {}); //=> "Function" * R.type(undefined); //=> "Undefined" */ -var type = /*#__PURE__*/_curry1(function type(val) { + +var type = +/*#__PURE__*/ +_curry1(function type(val) { return val === null ? 'Null' : val === undefined ? 'Undefined' : Object.prototype.toString.call(val).slice(8, -1); }); @@ -2033,32 +2425,43 @@ var type = /*#__PURE__*/_curry1(function type(val) { * @param {Boolean} deep Whether or not to perform deep cloning. * @return {*} The copied value. */ + function _clone(value, refFrom, refTo, deep) { var copy = function copy(copiedValue) { var len = refFrom.length; var idx = 0; + while (idx < len) { if (value === refFrom[idx]) { return refTo[idx]; } + idx += 1; } + refFrom[idx + 1] = value; refTo[idx + 1] = copiedValue; + for (var key in value) { copiedValue[key] = deep ? _clone(value[key], refFrom, refTo, true) : value[key]; } + return copiedValue; }; + switch (type(value)) { case 'Object': return copy({}); + case 'Array': return copy([]); + case 'Date': return new Date(value.valueOf()); + case 'RegExp': return _cloneRegExp(value); + default: return value; } @@ -2080,12 +2483,15 @@ function _clone(value, refFrom, refTo, deep) { * @return {*} A deeply cloned copy of `val` * @example * - * var objects = [{}, {}, {}]; - * var objectsClone = R.clone(objects); + * const objects = [{}, {}, {}]; + * const objectsClone = R.clone(objects); * objects === objectsClone; //=> false * objects[0] === objectsClone[0]; //=> false */ -var clone = /*#__PURE__*/_curry1(function clone(value) { + +var clone = +/*#__PURE__*/ +_curry1(function clone(value) { return value != null && typeof value.clone === 'function' ? value.clone() : _clone(value, [], [], true); }); @@ -2103,13 +2509,19 @@ var clone = /*#__PURE__*/_curry1(function clone(value) { * @return {Function} A Function :: a -> b -> Int that returns `-1` if a < b, `1` if b < a, otherwise `0` * @example * - * var byAge = R.comparator((a, b) => a.age < b.age); - * var people = [ - * // ... + * const byAge = R.comparator((a, b) => a.age < b.age); + * const people = [ + * { name: 'Emma', age: 70 }, + * { name: 'Peter', age: 78 }, + * { name: 'Mikhail', age: 62 }, * ]; - * var peopleByIncreasingAge = R.sort(byAge, people); + * const peopleByIncreasingAge = R.sort(byAge, people); + * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }] */ -var comparator = /*#__PURE__*/_curry1(function comparator(pred) { + +var comparator = +/*#__PURE__*/ +_curry1(function comparator(pred) { return function (a, b) { return pred(a, b) ? -1 : pred(b, a) ? 1 : 0; }; @@ -2134,7 +2546,10 @@ var comparator = /*#__PURE__*/_curry1(function comparator(pred) { * R.not(0); //=> true * R.not(1); //=> false */ -var not = /*#__PURE__*/_curry1(function not(a) { + +var not = +/*#__PURE__*/ +_curry1(function not(a) { return !a; }); @@ -2154,13 +2569,16 @@ var not = /*#__PURE__*/_curry1(function not(a) { * @see R.not * @example * - * var isNotNil = R.complement(R.isNil); + * const isNotNil = R.complement(R.isNil); * isNil(null); //=> true * isNotNil(null); //=> false * isNil(7); //=> false * isNotNil(7); //=> true */ -var complement = /*#__PURE__*/lift(not); + +var complement = +/*#__PURE__*/ +lift(not); function _pipe(f, g) { return function () { @@ -2178,12 +2596,15 @@ function _pipe(f, g) { * @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)); }; @@ -2213,7 +2634,12 @@ function _checkForMethod(methodname, fn) { * R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c'] * R.slice(0, 3, 'ramda'); //=> 'ram' */ -var slice = /*#__PURE__*/_curry3( /*#__PURE__*/_checkForMethod('slice', function slice(fromIndex, toIndex, list) { + +var slice = +/*#__PURE__*/ +_curry3( +/*#__PURE__*/ +_checkForMethod('slice', function slice(fromIndex, toIndex, list) { return Array.prototype.slice.call(list, fromIndex, toIndex); })); @@ -2244,11 +2670,18 @@ var slice = /*#__PURE__*/_curry3( /*#__PURE__*/_checkForMethod('slice', function * R.tail('a'); //=> '' * R.tail(''); //=> '' */ -var tail = /*#__PURE__*/_curry1( /*#__PURE__*/_checkForMethod('tail', /*#__PURE__*/slice(1, Infinity))); + +var tail = +/*#__PURE__*/ +_curry1( +/*#__PURE__*/ +_checkForMethod('tail', +/*#__PURE__*/ +slice(1, Infinity))); /** - * Performs left-to-right function composition. The leftmost function may have - * any arity; the remaining functions must be unary. + * Performs left-to-right function composition. The first argument may have + * any arity; the remaining arguments must be unary. * * In some libraries this function is named `sequence`. * @@ -2264,15 +2697,17 @@ var tail = /*#__PURE__*/_curry1( /*#__PURE__*/_checkForMethod('tail', /*#__PURE_ * @see R.compose * @example * - * var f = R.pipe(Math.pow, R.negate, R.inc); + * const f = R.pipe(Math.pow, R.negate, R.inc); * * f(3, 4); // -(3^4) + 1 * @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))); } @@ -2300,13 +2735,16 @@ function pipe() { * R.reverse('a'); //=> 'a' * R.reverse(''); //=> '' */ -var reverse = /*#__PURE__*/_curry1(function reverse(list) { + +var reverse = +/*#__PURE__*/ +_curry1(function reverse(list) { return _isString(list) ? list.split('').reverse().join('') : Array.prototype.slice.call(list, 0).reverse(); }); /** - * Performs right-to-left function composition. The rightmost function may have - * any arity; the remaining functions must be unary. + * Performs right-to-left function composition. The last argument may have + * any arity; the remaining arguments must be unary. * * **Note:** The result of compose is not automatically curried. * @@ -2320,18 +2758,20 @@ var reverse = /*#__PURE__*/_curry1(function reverse(list) { * @see R.pipe * @example * - * var classyGreeting = (firstName, lastName) => "The name's " + lastName + ", " + firstName + " " + lastName - * var yellGreeting = R.compose(R.toUpper, classyGreeting); + * const classyGreeting = (firstName, lastName) => "The name's " + lastName + ", " + firstName + " " + lastName + * const yellGreeting = R.compose(R.toUpper, classyGreeting); * yellGreeting('James', 'Bond'); //=> "THE NAME'S BOND, JAMES BOND" * * R.compose(Math.abs, R.add(1), R.multiply(2))(-4) //=> 7 * * @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)); } @@ -2349,13 +2789,14 @@ function compose() { * @param {...Function} ...functions The functions to compose * @return {Function} * @see R.pipeK + * @deprecated since v0.26.0 * @example * * // get :: String -> Object -> Maybe * - * var get = R.curry((propName, obj) => Maybe(obj[propName])) + * const get = R.curry((propName, obj) => Maybe(obj[propName])) * * // getStateCode :: Maybe String -> Maybe String - * var getStateCode = R.composeK( + * const getStateCode = R.composeK( * R.compose(Maybe.of, R.toUpper), * get('state'), * get('address'), @@ -2365,10 +2806,12 @@ function compose() { * getStateCode({}); //=> Maybe.Nothing() * @symb R.composeK(f, g, h)(a) = R.chain(f, R.chain(g, h(a))) */ + function composeK() { if (arguments.length === 0) { throw new Error('composeK requires at least one argument'); } + var init = Array.prototype.slice.call(arguments); var last = init.pop(); return compose(compose.apply(this, map(chain, init)), last); @@ -2385,7 +2828,7 @@ function _pipeP(f, g) { /** * Performs left-to-right composition of one or more Promise-returning - * functions. The leftmost function may have any arity; the remaining functions + * functions. The first argument may have any arity; the remaining arguments * must be unary. * * @func @@ -2396,22 +2839,25 @@ function _pipeP(f, g) { * @param {...Function} functions * @return {Function} * @see R.composeP + * @deprecated since v0.26.0 * @example * * // followersForUser :: String -> Promise [User] - * var followersForUser = R.pipeP(db.getUserById, db.getFollowers); + * const followersForUser = R.pipeP(db.getUserById, db.getFollowers); */ + function pipeP() { if (arguments.length === 0) { throw new Error('pipeP requires at least one argument'); } + return _arity(arguments[0].length, reduce(_pipeP, arguments[0], tail(arguments))); } /** * Performs right-to-left composition of one or more Promise-returning - * functions. The rightmost function may have any arity; the remaining - * functions must be unary. + * functions. The last arguments may have any arity; the remaining + * arguments must be unary. * * @func * @memberOf R @@ -2421,9 +2867,10 @@ function pipeP() { * @param {...Function} functions The functions to compose * @return {Function} * @see R.pipeP + * @deprecated since v0.26.0 * @example * - * var db = { + * const db = { * users: { * JOE: { * name: 'Joe', @@ -2433,32 +2880,161 @@ function pipeP() { * } * * // We'll pretend to do a db lookup which returns a promise - * var lookupUser = (userId) => Promise.resolve(db.users[userId]) - * var lookupFollowers = (user) => Promise.resolve(user.followers) + * const lookupUser = (userId) => Promise.resolve(db.users[userId]) + * const lookupFollowers = (user) => Promise.resolve(user.followers) * lookupUser('JOE').then(lookupFollowers) * * // followersForUser :: String -> Promise [UserId] - * var followersForUser = R.composeP(lookupFollowers, lookupUser); + * const followersForUser = R.composeP(lookupFollowers, lookupUser); * followersForUser('JOE').then(followers => console.log('Followers:', followers)) * // Followers: ["STEVE","SUZY"] */ + function composeP() { if (arguments.length === 0) { throw new Error('composeP requires at least one argument'); } + return pipeP.apply(this, reverse(arguments)); } +/** + * Returns the first element of the given list or string. In some libraries + * this function is named `first`. + * + * @func + * @memberOf R + * @since v0.1.0 + * @category List + * @sig [a] -> a | Undefined + * @sig String -> String + * @param {Array|String} list + * @return {*} + * @see R.tail, R.init, R.last + * @example + * + * R.head(['fi', 'fo', 'fum']); //=> 'fi' + * R.head([]); //=> undefined + * + * R.head('abc'); //=> 'a' + * R.head(''); //=> '' + */ + +var head = +/*#__PURE__*/ +nth(0); + +function _identity(x) { + return x; +} + +/** + * A function that does nothing but return the parameter supplied to it. Good + * as a default or placeholder function. + * + * @func + * @memberOf R + * @since v0.1.0 + * @category Function + * @sig a -> a + * @param {*} x The value to return. + * @return {*} The input value, `x`. + * @example + * + * R.identity(1); //=> 1 + * + * const obj = {}; + * R.identity(obj) === obj; //=> true + * @symb R.identity(a) = a + */ + +var identity = +/*#__PURE__*/ +_curry1(_identity); + +/** + * Performs left-to-right function composition using transforming function. The first argument may have + * any arity; the remaining arguments must be unary. + * + * **Note:** The result of pipeWith is not automatically curried. Transforming function is not used on the + * first argument. + * + * @func + * @memberOf R + * @since v0.26.0 + * @category Function + * @sig ((* -> *), [((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)]) -> ((a, b, ..., n) -> z) + * @param {...Function} functions + * @return {Function} + * @see R.composeWith, R.pipe + * @example + * + * const pipeWhileNotNil = R.pipeWith((f, res) => R.isNil(res) ? res : f(res)); + * const f = pipeWhileNotNil([Math.pow, R.negate, R.inc]) + * + * f(3, 4); // -(3^4) + 1 + * @symb R.pipeWith(f)([g, h, i])(...args) = f(i, f(h, g(...args))) + */ + +var pipeWith = +/*#__PURE__*/ +_curry2(function pipeWith(xf, list) { + if (list.length <= 0) { + return identity; + } + + var headList = head(list); + var tailList = tail(list); + return _arity(headList.length, function () { + return _reduce(function (result, f) { + return xf.call(this, f, result); + }, headList.apply(this, arguments), tailList); + }); +}); + +/** + * Performs right-to-left function composition using transforming function. The last argument may have + * any arity; the remaining arguments must be unary. + * + * **Note:** The result of compose is not automatically curried. Transforming function is not used on the + * last argument. + * + * @func + * @memberOf R + * @since v0.26.0 + * @category Function + * @sig ((* -> *), [(y -> z), (x -> y), ..., (o -> p), ((a, b, ..., n) -> o)]) -> ((a, b, ..., n) -> z) + * @param {...Function} ...functions The functions to compose + * @return {Function} + * @see R.compose, R.pipeWith + * @example + * + * const composeWhileNotNil = R.composeWith((f, res) => R.isNil(res) ? res : f(res)); + * + * composeWhileNotNil([R.inc, R.prop('age')])({age: 1}) //=> 2 + * composeWhileNotNil([R.inc, R.prop('age')])({}) //=> undefined + * + * @symb R.composeWith(f)([g, h, i])(...args) = f(g, f(h, i(...args))) + */ + +var composeWith = +/*#__PURE__*/ +_curry2(function composeWith(xf, list) { + return pipeWith.apply(this, [xf, reverse(list)]); +}); + function _arrayFromIterator(iter) { var list = []; var next; + while (!(next = iter.next()).done) { list.push(next.value); } + return list; } -function _containsWith(pred, x, list) { +function _includesWith(pred, x, list) { var idx = 0; var len = list.length; @@ -2466,8 +3042,10 @@ function _containsWith(pred, x, list) { if (pred(x, list[idx])) { return true; } + idx += 1; } + return false; } @@ -2477,30 +3055,8 @@ function _functionName(f) { return match == null ? '' : match[1]; } -/** - * Returns true if its arguments are identical, false otherwise. Values are - * identical if they reference the same memory. `NaN` is identical to `NaN`; - * `0` and `-0` are not identical. - * - * @func - * @memberOf R - * @since v0.15.0 - * @category Relation - * @sig a -> a -> Boolean - * @param {*} a - * @param {*} b - * @return {Boolean} - * @example - * - * var o = {}; - * R.identical(o, o); //=> true - * R.identical(1, 1); //=> true - * R.identical(1, '1'); //=> false - * R.identical([], []); //=> false - * R.identical(0, -0); //=> false - * R.identical(NaN, NaN); //=> true - */ -var identical = /*#__PURE__*/_curry2(function identical(a, b) { +// Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is +function _objectIs(a, b) { // SameValue algorithm if (a === b) { // Steps 1-5, 7-10 @@ -2510,7 +3066,9 @@ var identical = /*#__PURE__*/_curry2(function identical(a, b) { // Step 6.a: NaN == NaN return a !== a && b !== b; } -}); +} + +var _objectIs$1 = typeof Object.is === 'function' ? Object.is : _objectIs; /** * private _uniqContentEquals function. @@ -2525,20 +3083,21 @@ var identical = /*#__PURE__*/_curry2(function identical(a, b) { 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 !_containsWith(function (b, aItem) { - return !_containsWith(eq, aItem, b); + + return !_includesWith(function (b, aItem) { + return !_includesWith(eq, aItem, b); }, b, a); } function _equals(a, b, stackA, stackB) { - if (identical(a, b)) { + if (_objectIs$1(a, b)) { return true; } @@ -2567,33 +3126,43 @@ function _equals(a, b, stackA, stackB) { if (typeof a.constructor === 'function' && _functionName(a.constructor) === 'Promise') { return a === b; } + break; + case 'Boolean': case 'Number': case 'String': - if (!(typeof a === typeof b && identical(a.valueOf(), b.valueOf()))) { + if (!(typeof a === typeof b && _objectIs$1(a.valueOf(), b.valueOf()))) { return false; } + break; + case 'Date': - if (!identical(a.valueOf(), b.valueOf())) { + 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; } @@ -2604,12 +3173,14 @@ function _equals(a, b, stackA, stackB) { } 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': @@ -2630,27 +3201,32 @@ function _equals(a, b, stackA, stackB) { 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; } @@ -2675,46 +3251,57 @@ function _equals(a, b, stackA, stackB) { * R.equals(1, '1'); //=> false * R.equals([1, 2, 3], [1, 2, 3]); //=> true * - * var a = {}; a.v = a; - * var b = {}; b.v = b; + * const a = {}; a.v = a; + * const b = {}; b.v = b; * R.equals(a, b); //=> true */ -var equals = /*#__PURE__*/_curry2(function equals(a, b) { + +var equals = +/*#__PURE__*/ +_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 - return list.indexOf(a, idx); + } // non-zero numbers can utilise Set + + return list.indexOf(a, idx); // all these types can utilise Set + case 'string': case 'boolean': case 'function': @@ -2726,26 +3313,29 @@ function _indexOf(list, a, idx) { // 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; } -function _contains(a, list) { +function _includes(a, list) { return _indexOf(list, a, 0) >= 0; } function _quote(s) { var escaped = s.replace(/\\/g, '\\\\').replace(/[\b]/g, '\\b') // \b matches word boundary; [\b] matches backspace .replace(/\f/g, '\\f').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t').replace(/\v/g, '\\v').replace(/\0/g, '\\0'); - return '"' + escaped.replace(/"/g, '\\"') + '"'; } @@ -2777,8 +3367,10 @@ function _filter(fn, list) { if (fn(list[idx])) { result[result.length] = list[idx]; } + idx += 1; } + return result; } @@ -2786,13 +3378,17 @@ function _isObject(x) { return Object.prototype.toString.call(x) === '[object Object]'; } -var XFilter = /*#__PURE__*/function () { +var XFilter = +/*#__PURE__*/ +function () { function XFilter(f, xf) { 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; }; @@ -2800,7 +3396,9 @@ var XFilter = /*#__PURE__*/function () { return XFilter; }(); -var _xfilter = /*#__PURE__*/_curry2(function _xfilter(f, xf) { +var _xfilter = +/*#__PURE__*/ +_curry2(function _xfilter(f, xf) { return new XFilter(f, xf); }); @@ -2825,20 +3423,25 @@ var _xfilter = /*#__PURE__*/_curry2(function _xfilter(f, xf) { * @see R.reject, R.transduce, R.addIndex * @example * - * var isEven = n => n % 2 === 0; + * const isEven = n => n % 2 === 0; * * R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4] * * R.filter(isEven, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4} */ -var filter = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['filter'], _xfilter, function (pred, filterable) { + +var filter = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable(['filter'], _xfilter, function (pred, filterable) { return _isObject(filterable) ? _reduce(function (acc, key) { if (pred(filterable[key])) { acc[key] = filterable[key]; } + return acc; - }, {}, keys(filterable)) : - // else + }, {}, keys(filterable)) : // else _filter(pred, filterable); })); @@ -2860,23 +3463,26 @@ var filter = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['filter'], _xfilt * @see R.filter, R.transduce, R.addIndex * @example * - * var isOdd = (n) => n % 2 === 1; + * const isOdd = (n) => n % 2 === 1; * * R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4] * * R.reject(isOdd, {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, d: 4} */ -var reject = /*#__PURE__*/_curry2(function reject(pred, filterable) { + +var reject = +/*#__PURE__*/ +_curry2(function reject(pred, filterable) { return filter(_complement(pred), filterable); }); function _toString(x, seen) { var recur = function recur(y) { var xs = seen.concat([x]); - return _contains(y, xs) ? '' : _toString(y, xs); - }; + return _includes(y, xs) ? '' : _toString(y, xs); + }; // mapPairs :: (Object, [String]) -> [String] + - // mapPairs :: (Object, [String]) -> [String] var mapPairs = function (obj, keys$$1) { return _map(function (k) { return _quote(k) + ': ' + recur(obj[k]); @@ -2886,30 +3492,39 @@ function _toString(x, seen) { 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) - ); + 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 Null]': return 'null'; + case '[object Number]': return typeof x === 'object' ? 'new Number(' + recur(x.valueOf()) + ')' : 1 / x === -Infinity ? '-0' : x.toString(10); + 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(', ') + '}'; } } @@ -2950,7 +3565,10 @@ function _toString(x, seen) { * 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 = /*#__PURE__*/_curry1(function toString(val) { + +var toString$1 = +/*#__PURE__*/ +_curry1(function toString(val) { return _toString(val, []); }); @@ -2982,25 +3600,34 @@ var toString$1 = /*#__PURE__*/_curry1(function toString(val) { * R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3] * R.concat([], []); //=> [] */ -var concat = /*#__PURE__*/_curry2(function concat(a, b) { + +var concat = +/*#__PURE__*/ +_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"'); }); @@ -3019,9 +3646,10 @@ var concat = /*#__PURE__*/_curry2(function concat(a, b) { * @sig [[(*... -> Boolean),(*... -> *)]] -> (*... -> *) * @param {Array} pairs A list of [predicate, transformer] * @return {Function} + * @see R.ifElse, R.unless, R.when * @example * - * var fn = R.cond([ + * const fn = R.cond([ * [R.equals(0), R.always('water freezes at 0°C')], * [R.equals(100), R.always('water boils at 100°C')], * [R.T, temp => 'nothing special happens at ' + temp + '°C'] @@ -3030,16 +3658,21 @@ var concat = /*#__PURE__*/_curry2(function concat(a, b) { * fn(50); //=> 'nothing special happens at 50°C' * fn(100); //=> 'water boils at 100°C' */ -var cond = /*#__PURE__*/_curry1(function cond(pairs) { + +var cond = +/*#__PURE__*/ +_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; } }); @@ -3066,49 +3699,63 @@ var cond = /*#__PURE__*/_curry1(function cond(pairs) { * } * * Salad.prototype.recipe = function() { - * var instructions = R.map(ingredient => 'Add a dollop of ' + ingredient, this.ingredients); + * const instructions = R.map(ingredient => 'Add a dollop of ' + ingredient, this.ingredients); * return R.join('\n', instructions); * }; * - * var ThreeLayerSalad = R.constructN(3, Salad); + * const ThreeLayerSalad = R.constructN(3, Salad); * * // Notice we no longer need the 'new' keyword, and the constructor is curried for 3 arguments. - * var salad = ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup'); + * const salad = ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup'); * * console.log(salad.recipe()); * // Add a dollop of Mayonnaise * // Add a dollop of Potato Chips * // Add a dollop of Ketchup */ -var constructN = /*#__PURE__*/_curry2(function constructN(n, Fn) { + +var constructN = +/*#__PURE__*/ +_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 (arguments.length) { 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); } @@ -3137,23 +3784,27 @@ var constructN = /*#__PURE__*/_curry2(function constructN(n, Fn) { * return "It's a " + this.kind + "!"; * } * - * var AnimalConstructor = R.construct(Animal) + * const AnimalConstructor = R.construct(Animal) * * // Notice we no longer need the 'new' keyword: * AnimalConstructor('Pig'); //=> {"kind": "Pig", "sighting": function (){...}}; * - * var animalTypes = ["Lion", "Tiger", "Bear"]; - * var animalSighting = R.invoker(0, 'sighting'); - * var sightNewAnimal = R.compose(animalSighting, AnimalConstructor); + * const animalTypes = ["Lion", "Tiger", "Bear"]; + * const animalSighting = R.invoker(0, 'sighting'); + * const sightNewAnimal = R.compose(animalSighting, AnimalConstructor); * R.map(sightNewAnimal, animalTypes); //=> ["It's a Lion!", "It's a Tiger!", "It's a Bear!"] */ -var construct = /*#__PURE__*/_curry1(function construct(Fn) { + +var construct = +/*#__PURE__*/ +_curry1(function construct(Fn) { return constructN(Fn.length, Fn); }); /** * Returns `true` if the specified value is equal, in [`R.equals`](#equals) * terms, to at least one element of the given list; `false` otherwise. + * Works also with strings. * * @func * @memberOf R @@ -3163,22 +3814,28 @@ var construct = /*#__PURE__*/_curry1(function construct(Fn) { * @param {Object} a The item to compare against. * @param {Array} list The array to consider. * @return {Boolean} `true` if an equivalent item is in the list, `false` otherwise. - * @see R.any + * @see R.includes + * @deprecated since v0.26.0 * @example * * R.contains(3, [1, 2, 3]); //=> true * R.contains(4, [1, 2, 3]); //=> false * R.contains({ name: 'Fred' }, [{ name: 'Fred' }]); //=> true * R.contains([42], [[42]]); //=> true + * R.contains('ba', 'banana'); //=>true */ -var contains$1 = /*#__PURE__*/_curry2(_contains); + +var contains$1 = +/*#__PURE__*/ +_curry2(_includes); /** * Accepts a converging function and a list of branching functions and returns - * a new function. When invoked, this new function is applied to some - * arguments, each branching function is applied to those same arguments. The - * results of each branching function are passed as arguments to the converging - * function to produce the return value. + * a new function. The arity of the new function is the same as the arity of + * the longest branching function. When invoked, this new function is applied + * to some arguments, and each branching function is applied to those same + * arguments. The results of each branching function are passed as arguments + * to the converging function to produce the return value. * * @func * @memberOf R @@ -3192,15 +3849,18 @@ var contains$1 = /*#__PURE__*/_curry2(_contains); * @see R.useWith * @example * - * var average = R.converge(R.divide, [R.sum, R.length]) + * const average = R.converge(R.divide, [R.sum, R.length]) * average([1, 2, 3, 4, 5, 6, 7]) //=> 4 * - * var strangeConcat = R.converge(R.concat, [R.toUpper, R.toLower]) + * const strangeConcat = R.converge(R.concat, [R.toUpper, R.toLower]) * strangeConcat("Yodel") //=> "YODELyodel" * * @symb R.converge(f, [g, h])(a, b) = f(g(a, b), h(a, b)) */ -var converge = /*#__PURE__*/_curry2(function converge(after, fns) { + +var converge = +/*#__PURE__*/ +_curry2(function converge(after, fns) { return curryN(reduce(max, 0, pluck('length', fns)), function () { var args = arguments; var context = this; @@ -3210,7 +3870,9 @@ var converge = /*#__PURE__*/_curry2(function converge(after, fns) { }); }); -var XReduceBy = /*#__PURE__*/function () { +var XReduceBy = +/*#__PURE__*/ +function () { function XReduceBy(valueFn, valueAcc, keyFn, xf) { this.valueFn = valueFn; this.valueAcc = valueAcc; @@ -3218,21 +3880,27 @@ var XReduceBy = /*#__PURE__*/function () { 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, this.valueAcc]; @@ -3243,7 +3911,9 @@ var XReduceBy = /*#__PURE__*/function () { return XReduceBy; }(); -var _xreduceBy = /*#__PURE__*/_curryN(4, [], function _xreduceBy(valueFn, valueAcc, keyFn, xf) { +var _xreduceBy = +/*#__PURE__*/ +_curryN(4, [], function _xreduceBy(valueFn, valueAcc, keyFn, xf) { return new XReduceBy(valueFn, valueAcc, keyFn, xf); }); @@ -3271,30 +3941,32 @@ var _xreduceBy = /*#__PURE__*/_curryN(4, [], function _xreduceBy(valueFn, valueA * @see R.groupBy, R.reduce * @example * - * var reduceToNamesBy = R.reduceBy((acc, student) => acc.concat(student.name), []); - * var namesByGrade = reduceToNamesBy(function(student) { - * var score = student.score; - * return score < 65 ? 'F' : - * score < 70 ? 'D' : - * score < 80 ? 'C' : - * score < 90 ? 'B' : 'A'; - * }); - * var students = [{name: 'Lucy', score: 92}, - * {name: 'Drew', score: 85}, - * // ... - * {name: 'Bart', score: 62}]; - * namesByGrade(students); - * // { - * // 'A': ['Lucy'], - * // 'B': ['Drew'] - * // // ..., - * // 'F': ['Bart'] - * // } + * const groupNames = (acc, {name}) => acc.concat(name) + * const toGrade = ({score}) => + * score < 65 ? 'F' : + * score < 70 ? 'D' : + * score < 80 ? 'C' : + * score < 90 ? 'B' : 'A' + * + * var students = [ + * {name: 'Abby', score: 83}, + * {name: 'Bart', score: 62}, + * {name: 'Curt', score: 88}, + * {name: 'Dora', score: 92}, + * ] + * + * reduceBy(groupNames, [], toGrade, students) + * //=> {"A": ["Dora"], "B": ["Abby", "Curt"], "F": ["Bart"]} */ -var reduceBy = /*#__PURE__*/_curryN(4, [], /*#__PURE__*/_dispatchable([], _xreduceBy, function reduceBy(valueFn, valueAcc, keyFn, list) { + +var reduceBy = +/*#__PURE__*/ +_curryN(4, [], +/*#__PURE__*/ +_dispatchable([], _xreduceBy, function reduceBy(valueFn, valueAcc, keyFn, list) { return _reduce(function (acc, elt) { var key = keyFn(elt); - acc[key] = valueFn(_has(key, acc) ? acc[key] : valueAcc, elt); + acc[key] = valueFn(_has(key, acc) ? acc[key] : _clone(valueAcc, [], [], false), elt); return acc; }, {}, list); })); @@ -3317,13 +3989,16 @@ var reduceBy = /*#__PURE__*/_curryN(4, [], /*#__PURE__*/_dispatchable([], _xredu * @return {Object} An object mapping keys to number of occurrences in the list. * @example * - * var numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2]; + * const numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2]; * R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1} * - * var letters = ['a', 'b', 'A', 'a', 'B', 'c']; + * const letters = ['a', 'b', 'A', 'a', 'B', 'c']; * R.countBy(R.toLower)(letters); //=> {'a': 3, 'b': 2, 'c': 1} */ -var countBy = /*#__PURE__*/reduceBy(function (acc, elem) { + +var countBy = +/*#__PURE__*/ +reduceBy(function (acc, elem) { return acc + 1; }, 0); @@ -3342,7 +4017,10 @@ var countBy = /*#__PURE__*/reduceBy(function (acc, elem) { * * R.dec(42); //=> 41 */ -var dec = /*#__PURE__*/add(-1); + +var dec = +/*#__PURE__*/ +add(-1); /** * Returns the second argument if it is not `null`, `undefined` or `NaN`; @@ -3358,15 +4036,19 @@ var dec = /*#__PURE__*/add(-1); * @return {*} The second value if it is not `null`, `undefined` or `NaN`, otherwise the default value * @example * - * var defaultTo42 = R.defaultTo(42); + * const defaultTo42 = R.defaultTo(42); * * defaultTo42(null); //=> 42 * defaultTo42(undefined); //=> 42 + * defaultTo42(false); //=> false * defaultTo42('Ramda'); //=> 'Ramda' * // parseInt('string') results in NaN * defaultTo42(parseInt('string')); //=> 42 */ -var defaultTo = /*#__PURE__*/_curry2(function defaultTo(d, v) { + +var defaultTo = +/*#__PURE__*/ +_curry2(function defaultTo(d, v) { return v == null || v !== v ? d : v; }); @@ -3386,18 +4068,221 @@ var defaultTo = /*#__PURE__*/_curry2(function defaultTo(d, v) { * @see R.ascend * @example * - * var byAge = R.descend(R.prop('age')); - * var people = [ - * // ... + * const byAge = R.descend(R.prop('age')); + * const people = [ + * { name: 'Emma', age: 70 }, + * { name: 'Peter', age: 78 }, + * { name: 'Mikhail', age: 62 }, * ]; - * var peopleByOldestFirst = R.sort(byAge, people); + * const peopleByOldestFirst = R.sort(byAge, people); + * //=> [{ name: 'Peter', age: 78 }, { name: 'Emma', age: 70 }, { name: 'Mikhail', age: 62 }] */ -var descend = /*#__PURE__*/_curry3(function descend(fn, a, b) { + +var descend = +/*#__PURE__*/ +_curry3(function descend(fn, a, b) { var aa = fn(a); var bb = fn(b); return aa > bb ? -1 : aa < bb ? 1 : 0; }); +var _Set = +/*#__PURE__*/ +function () { + function _Set() { + /* globals Set */ + this._nativeSet = typeof Set === 'function' ? new Set() : null; + this._items = {}; + } + + // 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. + // + // @param item The item to check or add to the Set instance. + // @param shouldAdd If true, the item will be added to the set if it doesn't + // already exist. + // @param set The set instance to check or add to. + // @return {boolean} true if the item already existed, otherwise false. + // + + + return _Set; +}(); + +function hasOrAdd(item, shouldAdd, set) { + var type = typeof item; + var prevSize, newSize; + + switch (type) { + case 'string': + case 'number': + // distinguish between +0 and -0 + if (item === 0 && 1 / item === -Infinity) { + if (set._items['-0']) { + return true; + } else { + if (shouldAdd) { + set._items['-0'] = true; + } + + return false; + } + } // 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 { + return set._nativeSet.has(item); + } + } else { + if (!(type in set._items)) { + if (shouldAdd) { + set._items[type] = {}; + set._items[type][item] = true; + } + + return false; + } else if (item in set._items[type]) { + return true; + } else { + 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 { + return set._nativeSet.has(item); + } + } else { + if (!(type in set._items)) { + 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; + } else { + 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 + + + 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 * contained in the second list. Objects and Arrays are compared in terms of @@ -3418,16 +4303,28 @@ var descend = /*#__PURE__*/_curry3(function descend(fn, a, b) { * 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 = /*#__PURE__*/_curry2(function difference(first, second) { + +var difference = +/*#__PURE__*/ +_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 (!_contains(first[idx], second) && !_contains(first[idx], out)) { + if (toFilterOut.add(first[idx])) { out[out.length] = first[idx]; } + idx += 1; } + return out; }); @@ -3448,21 +4345,27 @@ var difference = /*#__PURE__*/_curry2(function difference(first, second) { * @see R.difference, R.symmetricDifference, R.symmetricDifferenceWith * @example * - * var cmp = (x, y) => x.a === y.a; - * var l1 = [{a: 1}, {a: 2}, {a: 3}]; - * var l2 = [{a: 3}, {a: 4}]; + * const cmp = (x, y) => x.a === y.a; + * const l1 = [{a: 1}, {a: 2}, {a: 3}]; + * const l2 = [{a: 3}, {a: 4}]; * R.differenceWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}] */ -var differenceWith = /*#__PURE__*/_curry3(function differenceWith(pred, first, second) { + +var differenceWith = +/*#__PURE__*/ +_curry3(function differenceWith(pred, first, second) { var out = []; var idx = 0; var firstLen = first.length; + while (idx < firstLen) { - if (!_containsWith(pred, first[idx], second) && !_containsWith(pred, first[idx], out)) { + if (!_includesWith(pred, first[idx], second) && !_includesWith(pred, first[idx], out)) { out.push(first[idx]); } + idx += 1; } + return out; }); @@ -3477,16 +4380,21 @@ var differenceWith = /*#__PURE__*/_curry3(function differenceWith(pred, first, s * @param {String} prop The name of the property to dissociate * @param {Object} obj The object to clone * @return {Object} A new object equivalent to the original but without the specified property - * @see R.assoc + * @see R.assoc, R.omit * @example * * R.dissoc('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3} */ -var dissoc = /*#__PURE__*/_curry2(function dissoc(prop, obj) { + +var dissoc = +/*#__PURE__*/ +_curry2(function dissoc(prop, obj) { var result = {}; + for (var p in obj) { result[p] = obj[p]; } + delete result[prop]; return result; }); @@ -3506,11 +4414,15 @@ var dissoc = /*#__PURE__*/_curry2(function dissoc(prop, obj) { * @param {Number} count The number of elements to remove * @param {Array} list The list to remove from * @return {Array} A new Array with `count` elements from `start` removed. + * @see R.without * @example * * R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8] */ -var remove = /*#__PURE__*/_curry3(function remove(start, count, list) { + +var remove = +/*#__PURE__*/ +_curry3(function remove(start, count, list) { var result = Array.prototype.slice.call(list, 0); result.splice(start, count); return result; @@ -3532,14 +4444,17 @@ var remove = /*#__PURE__*/_curry3(function remove(start, count, list) { * @see R.adjust * @example * - * R.update(1, 11, [0, 1, 2]); //=> [0, 11, 2] - * R.update(1)(11)([0, 1, 2]); //=> [0, 11, 2] + * R.update(1, '_', ['a', 'b', 'c']); //=> ['a', '_', 'c'] + * R.update(-1, '_', ['a', 'b', 'c']); //=> ['a', 'b', '_'] * @symb R.update(-1, a, [b, c]) = [b, a] * @symb R.update(0, a, [b, c]) = [a, c] * @symb R.update(1, a, [b, c]) = [b, a] */ -var update = /*#__PURE__*/_curry3(function update(idx, x, list) { - return adjust(always(x), idx, list); + +var update = +/*#__PURE__*/ +_curry3(function update(idx, x, list) { + return adjust(idx, always(x), list); }); /** @@ -3561,22 +4476,29 @@ var update = /*#__PURE__*/_curry3(function update(idx, x, list) { * * R.dissocPath(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}} */ -var dissocPath = /*#__PURE__*/_curry2(function dissocPath(path, obj) { + +var dissocPath = +/*#__PURE__*/ +_curry2(function dissocPath(path, obj) { switch (path.length) { case 0: return obj; + case 1: - return _isInteger(path[0]) ? remove(path[0], 1, obj) : dissoc(path[0], obj); + return _isInteger(path[0]) && _isArray(obj) ? remove(path[0], 1, obj) : dissoc(path[0], obj); + default: var head = path[0]; var tail = Array.prototype.slice.call(path, 1); + if (obj[head] == null) { return obj; - } else if (_isInteger(path[0])) { + } else if (_isInteger(head) && _isArray(obj)) { return update(head, dissocPath(tail, obj[head]), obj); } else { return assoc(head, dissocPath(tail, obj[head]), obj); } + } }); @@ -3596,35 +4518,45 @@ var dissocPath = /*#__PURE__*/_curry2(function dissocPath(path, obj) { * * R.divide(71, 100); //=> 0.71 * - * var half = R.divide(R.__, 2); + * const half = R.divide(R.__, 2); * half(42); //=> 21 * - * var reciprocal = R.divide(1); + * const reciprocal = R.divide(1); * reciprocal(4); //=> 0.25 */ -var divide = /*#__PURE__*/_curry2(function divide(a, b) { + +var divide = +/*#__PURE__*/ +_curry2(function divide(a, b) { return a / b; }); -var XDrop = /*#__PURE__*/function () { +var XDrop = +/*#__PURE__*/ +function () { function XDrop(n, xf) { 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); }; return XDrop; }(); -var _xdrop = /*#__PURE__*/_curry2(function _xdrop(n, xf) { +var _xdrop = +/*#__PURE__*/ +_curry2(function _xdrop(n, xf) { return new XDrop(n, xf); }); @@ -3652,18 +4584,27 @@ var _xdrop = /*#__PURE__*/_curry2(function _xdrop(n, xf) { * R.drop(4, ['foo', 'bar', 'baz']); //=> [] * R.drop(3, 'ramda'); //=> 'da' */ -var drop = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['drop'], _xdrop, function drop(n, xs) { + +var drop = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable(['drop'], _xdrop, function drop(n, xs) { return slice(Math.max(0, n), Infinity, xs); })); -var XTake = /*#__PURE__*/function () { +var XTake = +/*#__PURE__*/ +function () { function XTake(n, xf) { this.xf = xf; 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); @@ -3673,7 +4614,9 @@ var XTake = /*#__PURE__*/function () { return XTake; }(); -var _xtake = /*#__PURE__*/_curry2(function _xtake(n, xf) { +var _xtake = +/*#__PURE__*/ +_curry2(function _xtake(n, xf) { return new XTake(n, xf); }); @@ -3701,7 +4644,7 @@ var _xtake = /*#__PURE__*/_curry2(function _xtake(n, xf) { * R.take(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] * R.take(3, 'ramda'); //=> 'ram' * - * var personnel = [ + * const personnel = [ * 'Dave Brubeck', * 'Paul Desmond', * 'Eugene Wright', @@ -3712,7 +4655,7 @@ var _xtake = /*#__PURE__*/_curry2(function _xtake(n, xf) { * 'Ron Crotty' * ]; * - * var takeFive = R.take(5); + * const takeFive = R.take(5); * takeFive(personnel); * //=> ['Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan'] * @symb R.take(-1, [a, b]) = [a, b] @@ -3720,7 +4663,12 @@ var _xtake = /*#__PURE__*/_curry2(function _xtake(n, xf) { * @symb R.take(1, [a, b]) = [a] * @symb R.take(2, [a, b]) = [a, b] */ -var take = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['take'], _xtake, function take(n, xs) { + +var take = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable(['take'], _xtake, function take(n, xs) { return slice(0, n < 0 ? Infinity : n, xs); })); @@ -3728,28 +4676,36 @@ function dropLast(n, xs) { return take(n < xs.length ? xs.length - n : 0, xs); } -var XDropLast = /*#__PURE__*/function () { +var XDropLast = +/*#__PURE__*/ +function () { function XDropLast(n, 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; @@ -3759,13 +4715,17 @@ var XDropLast = /*#__PURE__*/function () { return XDropLast; }(); -var _xdropLast = /*#__PURE__*/_curry2(function _xdropLast(n, xf) { +var _xdropLast = +/*#__PURE__*/ +_curry2(function _xdropLast(n, xf) { return new XDropLast(n, xf); }); /** * Returns a list containing all but the last `n` elements of the given `list`. * + * Acts as a transducer if a transformer is given in list position. + * * @func * @memberOf R * @since v0.16.0 @@ -3784,35 +4744,49 @@ var _xdropLast = /*#__PURE__*/_curry2(function _xdropLast(n, xf) { * R.dropLast(4, ['foo', 'bar', 'baz']); //=> [] * R.dropLast(3, 'ramda'); //=> 'ra' */ -var dropLast$1 = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xdropLast, dropLast)); + +var dropLast$1 = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_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); } -var XDropLastWhile = /*#__PURE__*/function () { +var XDropLastWhile = +/*#__PURE__*/ +function () { function XDropLastWhile(fn, xf) { this.f = fn; 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 = _reduce(this.xf['@@transducer/step'], result, this.retained); this.retained = []; return this.xf['@@transducer/step'](result, input); }; + XDropLastWhile.prototype.retain = function (result, input) { this.retained.push(input); return result; @@ -3821,7 +4795,9 @@ var XDropLastWhile = /*#__PURE__*/function () { return XDropLastWhile; }(); -var _xdropLastWhile = /*#__PURE__*/_curry2(function _xdropLastWhile(fn, xf) { +var _xdropLastWhile = +/*#__PURE__*/ +_curry2(function _xdropLastWhile(fn, xf) { return new XDropLastWhile(fn, xf); }); @@ -3832,6 +4808,8 @@ var _xdropLastWhile = /*#__PURE__*/_curry2(function _xdropLastWhile(fn, xf) { * function returns a `falsy` value. The predicate function is applied to one argument: * *(value)*. * + * Acts as a transducer if a transformer is given in list position. + * * @func * @memberOf R * @since v0.16.0 @@ -3844,15 +4822,22 @@ var _xdropLastWhile = /*#__PURE__*/_curry2(function _xdropLastWhile(fn, xf) { * @see R.takeLastWhile, R.addIndex, R.drop, R.dropWhile * @example * - * var lteThree = x => x <= 3; + * const lteThree = x => x <= 3; * * R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3, 4] * * R.dropLastWhile(x => x !== 'd' , 'Ramda'); //=> 'Ramd' */ -var dropLastWhile$1 = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xdropLastWhile, dropLastWhile)); -var XDropRepeatsWith = /*#__PURE__*/function () { +var dropLastWhile$1 = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable([], _xdropLastWhile, dropLastWhile)); + +var XDropRepeatsWith = +/*#__PURE__*/ +function () { function XDropRepeatsWith(pred, xf) { this.xf = xf; this.pred = pred; @@ -3862,13 +4847,16 @@ var XDropRepeatsWith = /*#__PURE__*/function () { 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); }; @@ -3876,41 +4864,12 @@ var XDropRepeatsWith = /*#__PURE__*/function () { return XDropRepeatsWith; }(); -var _xdropRepeatsWith = /*#__PURE__*/_curry2(function _xdropRepeatsWith(pred, xf) { +var _xdropRepeatsWith = +/*#__PURE__*/ +_curry2(function _xdropRepeatsWith(pred, xf) { return new XDropRepeatsWith(pred, xf); }); -/** - * 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 - * - * var 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 = /*#__PURE__*/_curry2(function nth(offset, list) { - var idx = offset < 0 ? list.length + offset : offset; - return _isString(list) ? list.charAt(idx) : list[idx]; -}); - /** * Returns the last element of the given list or string. * @@ -3931,7 +4890,10 @@ var nth = /*#__PURE__*/_curry2(function nth(offset, list) { * R.last('abc'); //=> 'c' * R.last(''); //=> '' */ -var last = /*#__PURE__*/nth(-1); + +var last = +/*#__PURE__*/ +nth(-1); /** * Returns a new list without any consecutively repeating elements. Equality is @@ -3951,22 +4913,31 @@ var last = /*#__PURE__*/nth(-1); * @see R.transduce * @example * - * var l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3]; + * 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 = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xdropRepeatsWith, function dropRepeatsWith(pred, list) { + +var dropRepeatsWith = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_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; })); @@ -3988,29 +4959,46 @@ var dropRepeatsWith = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xdro * * R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); //=> [1, 2, 3, 4, 2] */ -var dropRepeats = /*#__PURE__*/_curry1( /*#__PURE__*/_dispatchable([], /*#__PURE__*/_xdropRepeatsWith(equals), /*#__PURE__*/dropRepeatsWith(equals))); -var XDropWhile = /*#__PURE__*/function () { +var dropRepeats = +/*#__PURE__*/ +_curry1( +/*#__PURE__*/ +_dispatchable([], +/*#__PURE__*/ +_xdropRepeatsWith(equals), +/*#__PURE__*/ +dropRepeatsWith(equals))); + +var XDropWhile = +/*#__PURE__*/ +function () { function XDropWhile(f, xf) { 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); }; return XDropWhile; }(); -var _xdropWhile = /*#__PURE__*/_curry2(function _xdropWhile(f, xf) { +var _xdropWhile = +/*#__PURE__*/ +_curry2(function _xdropWhile(f, xf) { return new XDropWhile(f, xf); }); @@ -4036,18 +5024,25 @@ var _xdropWhile = /*#__PURE__*/_curry2(function _xdropWhile(f, xf) { * @see R.takeWhile, R.transduce, R.addIndex * @example * - * var lteTwo = x => x <= 2; + * const lteTwo = x => x <= 2; * * R.dropWhile(lteTwo, [1, 2, 3, 4, 3, 2, 1]); //=> [3, 4, 3, 2, 1] * * R.dropWhile(x => x !== 'd' , 'Ramda'); //=> 'da' */ -var dropWhile = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['dropWhile'], _xdropWhile, function dropWhile(pred, xs) { + +var dropWhile = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_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); })); @@ -4063,7 +5058,7 @@ var dropWhile = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['dropWhile'], * @param {Any} a * @param {Any} b * @return {Any} the first argument if truthy, otherwise the second argument. - * @see R.either + * @see R.either, R.xor * @example * * R.or(true, true); //=> true @@ -4071,7 +5066,10 @@ var dropWhile = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['dropWhile'], * R.or(false, true); //=> true * R.or(false, false); //=> false */ -var or = /*#__PURE__*/_curry2(function or(a, b) { + +var or = +/*#__PURE__*/ +_curry2(function or(a, b) { return a || b; }); @@ -4096,13 +5094,19 @@ var or = /*#__PURE__*/_curry2(function or(a, b) { * @see R.or * @example * - * var gt10 = x => x > 10; - * var even = x => x % 2 === 0; - * var f = R.either(gt10, even); + * const gt10 = x => x > 10; + * const even = x => x % 2 === 0; + * const f = R.either(gt10, even); * f(101); //=> true * f(8); //=> true + * + * R.either(Maybe.Just(false), Maybe.Just(55)); // => Maybe.Just(55) + * R.either([false, false, 'a'], [11]) // => [11, 11, "a"] */ -var either = /*#__PURE__*/_curry2(function either(f, g) { + +var either = +/*#__PURE__*/ +_curry2(function either(f, g) { return _isFunction(f) ? function _either() { return f.apply(this, arguments) || g.apply(this, arguments); } : lift(or)(f, g); @@ -4131,12 +5135,14 @@ var either = /*#__PURE__*/_curry2(function either(f, g) { * R.empty('unicorns'); //=> '' * R.empty({x: 1, y: 2}); //=> {} */ -var empty = /*#__PURE__*/_curry1(function empty(x) { + +var empty = +/*#__PURE__*/ +_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; - }() : - // else - void 0; + }() : void 0 // else + ; }); /** @@ -4161,22 +5167,28 @@ var empty = /*#__PURE__*/_curry1(function empty(x) { * R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz'] * R.takeLast(3, 'ramda'); //=> 'mda' */ -var takeLast = /*#__PURE__*/_curry2(function takeLast(n, xs) { + +var takeLast = +/*#__PURE__*/ +_curry2(function takeLast(n, xs) { return drop(n >= 0 ? xs.length - n : 0, xs); }); /** - * Checks if a list ends with the provided values + * Checks if a list ends with the provided sublist. + * + * Similarly, checks if a string ends with the provided substring. * * @func * @memberOf R * @since v0.24.0 * @category List - * @sig [a] -> Boolean - * @sig String -> Boolean + * @sig [a] -> [a] -> Boolean + * @sig String -> String -> Boolean * @param {*} suffix * @param {*} list * @return {Boolean} + * @see R.startsWith * @example * * R.endsWith('c', 'abc') //=> true @@ -4184,7 +5196,10 @@ var takeLast = /*#__PURE__*/_curry2(function takeLast(n, xs) { * R.endsWith(['c'], ['a', 'b', 'c']) //=> true * R.endsWith(['b'], ['a', 'b', 'c']) //=> false */ -var endsWith = /*#__PURE__*/_curry2(function (suffix, list) { + +var endsWith = +/*#__PURE__*/ +_curry2(function (suffix, list) { return equals(takeLast(suffix.length, list), suffix); }); @@ -4205,7 +5220,10 @@ var endsWith = /*#__PURE__*/_curry2(function (suffix, list) { * * R.eqBy(Math.abs, 5, -5); //=> true */ -var eqBy = /*#__PURE__*/_curry3(function eqBy(f, x, y) { + +var eqBy = +/*#__PURE__*/ +_curry3(function eqBy(f, x, y) { return equals(f(x), f(y)); }); @@ -4225,12 +5243,15 @@ var eqBy = /*#__PURE__*/_curry3(function eqBy(f, x, y) { * * @example * - * var o1 = { a: 1, b: 2, c: 3, d: 4 }; - * var o2 = { a: 10, b: 20, c: 3, d: 40 }; + * const o1 = { a: 1, b: 2, c: 3, d: 4 }; + * const o2 = { a: 10, b: 20, c: 3, d: 40 }; * R.eqProps('a', o1, o2); //=> false * R.eqProps('c', o1, o2); //=> true */ -var eqProps = /*#__PURE__*/_curry3(function eqProps(prop, obj1, obj2) { + +var eqProps = +/*#__PURE__*/ +_curry3(function eqProps(prop, obj1, obj2) { return equals(obj1[prop], obj2[prop]); }); @@ -4253,50 +5274,64 @@ var eqProps = /*#__PURE__*/_curry3(function eqProps(prop, obj1, obj2) { * @return {Object} The transformed object. * @example * - * var tomato = {firstName: ' Tomato ', data: {elapsed: 100, remaining: 1400}, id:123}; - * var transformations = { + * const tomato = {firstName: ' Tomato ', data: {elapsed: 100, remaining: 1400}, id:123}; + * const transformations = { * firstName: R.trim, * lastName: R.trim, // Will not get invoked. * data: {elapsed: R.add(1), remaining: R.add(-1)} * }; * R.evolve(transformations, tomato); //=> {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123} */ -var evolve = /*#__PURE__*/_curry2(function evolve(transformations, object) { - var result = {}; + +var evolve = +/*#__PURE__*/ +_curry2(function evolve(transformations, 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; }); -var XFind = /*#__PURE__*/function () { +var XFind = +/*#__PURE__*/ +function () { function XFind(f, xf) { this.xf = xf; 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; }; return XFind; }(); -var _xfind = /*#__PURE__*/_curry2(function _xfind(f, xf) { +var _xfind = +/*#__PURE__*/ +_curry2(function _xfind(f, xf) { return new XFind(f, xf); }); @@ -4320,48 +5355,65 @@ var _xfind = /*#__PURE__*/_curry2(function _xfind(f, xf) { * @see R.transduce * @example * - * var xs = [{a: 1}, {a: 2}, {a: 3}]; + * const xs = [{a: 1}, {a: 2}, {a: 3}]; * R.find(R.propEq('a', 2))(xs); //=> {a: 2} * R.find(R.propEq('a', 4))(xs); //=> undefined */ -var find = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['find'], _xfind, function find(fn, list) { + +var find = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_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; } })); -var XFindIndex = /*#__PURE__*/function () { +var XFindIndex = +/*#__PURE__*/ +function () { function XFindIndex(f, xf) { this.xf = xf; this.f = f; 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; }; return XFindIndex; }(); -var _xfindIndex = /*#__PURE__*/_curry2(function _xfindIndex(f, xf) { +var _xfindIndex = +/*#__PURE__*/ +_curry2(function _xfindIndex(f, xf) { return new XFindIndex(f, xf); }); @@ -4383,42 +5435,58 @@ var _xfindIndex = /*#__PURE__*/_curry2(function _xfindIndex(f, xf) { * @see R.transduce * @example * - * var xs = [{a: 1}, {a: 2}, {a: 3}]; + * const xs = [{a: 1}, {a: 2}, {a: 3}]; * R.findIndex(R.propEq('a', 2))(xs); //=> 1 * R.findIndex(R.propEq('a', 4))(xs); //=> -1 */ -var findIndex = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xfindIndex, function findIndex(fn, list) { + +var findIndex = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_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; })); -var XFindLast = /*#__PURE__*/function () { +var XFindLast = +/*#__PURE__*/ +function () { function XFindLast(f, xf) { 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; }; return XFindLast; }(); -var _xfindLast = /*#__PURE__*/_curry2(function _xfindLast(f, xf) { +var _xfindLast = +/*#__PURE__*/ +_curry2(function _xfindLast(f, xf) { return new XFindLast(f, xf); }); @@ -4440,43 +5508,59 @@ var _xfindLast = /*#__PURE__*/_curry2(function _xfindLast(f, xf) { * @see R.transduce * @example * - * var xs = [{a: 1, b: 0}, {a:1, b: 1}]; + * const xs = [{a: 1, b: 0}, {a:1, b: 1}]; * R.findLast(R.propEq('a', 1))(xs); //=> {a: 1, b: 1} * R.findLast(R.propEq('a', 4))(xs); //=> undefined */ -var findLast = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xfindLast, function findLast(fn, list) { + +var findLast = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable([], _xfindLast, function findLast(fn, list) { var idx = list.length - 1; + while (idx >= 0) { if (fn(list[idx])) { return list[idx]; } + idx -= 1; } })); -var XFindLastIndex = /*#__PURE__*/function () { +var XFindLastIndex = +/*#__PURE__*/ +function () { function XFindLastIndex(f, xf) { this.xf = xf; this.f = f; 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; }; return XFindLastIndex; }(); -var _xfindLastIndex = /*#__PURE__*/_curry2(function _xfindLastIndex(f, xf) { +var _xfindLastIndex = +/*#__PURE__*/ +_curry2(function _xfindLastIndex(f, xf) { return new XFindLastIndex(f, xf); }); @@ -4498,18 +5582,26 @@ var _xfindLastIndex = /*#__PURE__*/_curry2(function _xfindLastIndex(f, xf) { * @see R.transduce * @example * - * var xs = [{a: 1, b: 0}, {a:1, b: 1}]; + * const xs = [{a: 1, b: 0}, {a:1, b: 1}]; * R.findLastIndex(R.propEq('a', 1))(xs); //=> 1 * R.findLastIndex(R.propEq('a', 4))(xs); //=> -1 */ -var findLastIndex = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xfindLastIndex, function findLastIndex(fn, list) { + +var findLastIndex = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable([], _xfindLastIndex, function findLastIndex(fn, list) { var idx = list.length - 1; + while (idx >= 0) { if (fn(list[idx])) { return idx; } + idx -= 1; } + return -1; })); @@ -4530,7 +5622,12 @@ var findLastIndex = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xfindL * 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 = /*#__PURE__*/_curry1( /*#__PURE__*/_makeFlat(true)); + +var flatten = +/*#__PURE__*/ +_curry1( +/*#__PURE__*/ +_makeFlat(true)); /** * Returns a new function much like the supplied one, except that the first two @@ -4545,14 +5642,17 @@ var flatten = /*#__PURE__*/_curry1( /*#__PURE__*/_makeFlat(true)); * @return {*} The result of invoking `fn` with its first two parameters' order reversed. * @example * - * var mergeThree = (a, b, c) => [].concat(a, b, c); + * const mergeThree = (a, b, c) => [].concat(a, b, c); * * mergeThree(1, 2, 3); //=> [1, 2, 3] * * R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3] * @symb R.flip(f)(a, b, c) = f(b, a, c) */ -var flip = /*#__PURE__*/_curry1(function flip(fn) { + +var flip = +/*#__PURE__*/ +_curry1(function flip(fn) { return curryN(fn.length, function (a, b) { var args = Array.prototype.slice.call(arguments, 0); args[0] = b; @@ -4588,20 +5688,27 @@ var flip = /*#__PURE__*/_curry1(function flip(fn) { * @see R.addIndex * @example * - * var printXPlusFive = x => console.log(x + 5); + * const printXPlusFive = x => console.log(x + 5); * R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3] * // logs 6 * // logs 7 * // logs 8 * @symb R.forEach(f, [a, b, c]) = [a, b, c] */ -var forEach = /*#__PURE__*/_curry2( /*#__PURE__*/_checkForMethod('forEach', function forEach(fn, list) { + +var forEach = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_checkForMethod('forEach', function forEach(fn, list) { var len = list.length; var idx = 0; + while (idx < len) { fn(list[idx]); idx += 1; } + return list; })); @@ -4621,20 +5728,25 @@ var forEach = /*#__PURE__*/_curry2( /*#__PURE__*/_checkForMethod('forEach', func * @return {Object} The original object. * @example * - * var printKeyConcatValue = (value, key) => console.log(key + ':' + value); + * const printKeyConcatValue = (value, key) => console.log(key + ':' + value); * R.forEachObjIndexed(printKeyConcatValue, {x: 1, y: 2}); //=> {x: 1, y: 2} * // logs x:1 * // logs y:2 * @symb R.forEachObjIndexed(f, {x: a, y: b}) = {x: a, y: b} */ -var forEachObjIndexed = /*#__PURE__*/_curry2(function forEachObjIndexed(fn, obj) { + +var forEachObjIndexed = +/*#__PURE__*/ +_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; }); @@ -4654,13 +5766,18 @@ var forEachObjIndexed = /*#__PURE__*/_curry2(function forEachObjIndexed(fn, obj) * * R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3} */ -var fromPairs = /*#__PURE__*/_curry1(function fromPairs(pairs) { + +var fromPairs = +/*#__PURE__*/ +_curry1(function fromPairs(pairs) { var result = {}; var idx = 0; + while (idx < pairs.length) { result[pairs[idx][0]] = pairs[idx][1]; idx += 1; } + return result; }); @@ -4682,17 +5799,17 @@ var fromPairs = /*#__PURE__*/_curry1(function fromPairs(pairs) { * @param {Array} list The array to group * @return {Object} An object with the output of `fn` for keys, mapped to arrays of elements * that produced that key when passed to `fn`. - * @see R.transduce + * @see R.reduceBy, R.transduce * @example * - * var byGrade = R.groupBy(function(student) { - * var score = student.score; + * const byGrade = R.groupBy(function(student) { + * const score = student.score; * return score < 65 ? 'F' : * score < 70 ? 'D' : * score < 80 ? 'C' : * score < 90 ? 'B' : 'A'; * }); - * var students = [{name: 'Abby', score: 84}, + * const students = [{name: 'Abby', score: 84}, * {name: 'Eddy', score: 58}, * // ... * {name: 'Jack', score: 69}]; @@ -4704,10 +5821,18 @@ var fromPairs = /*#__PURE__*/_curry1(function fromPairs(pairs) { * // 'F': [{name: 'Eddy', score: 58}] * // } */ -var groupBy = /*#__PURE__*/_curry2( /*#__PURE__*/_checkForMethod('groupBy', /*#__PURE__*/reduceBy(function (acc, item) { + +var groupBy = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_checkForMethod('groupBy', +/*#__PURE__*/ +reduceBy(function (acc, item) { if (acc == null) { acc = []; } + acc.push(item); return acc; }, null))); @@ -4742,18 +5867,25 @@ var groupBy = /*#__PURE__*/_curry2( /*#__PURE__*/_checkForMethod('groupBy', /*#_ * R.groupWith(R.eqBy(isVowel), 'aestiou') * //=> ['ae', 'st', 'iou'] */ -var groupWith = /*#__PURE__*/_curry2(function (fn, list) { + +var groupWith = +/*#__PURE__*/ +_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; }); @@ -4778,7 +5910,10 @@ var groupWith = /*#__PURE__*/_curry2(function (fn, list) { * R.gt('a', 'z'); //=> false * R.gt('z', 'a'); //=> true */ -var gt = /*#__PURE__*/_curry2(function gt(a, b) { + +var gt = +/*#__PURE__*/ +_curry2(function gt(a, b) { return a > b; }); @@ -4803,10 +5938,57 @@ var gt = /*#__PURE__*/_curry2(function gt(a, b) { * R.gte('a', 'z'); //=> false * R.gte('z', 'a'); //=> true */ -var gte = /*#__PURE__*/_curry2(function gte(a, b) { + +var gte = +/*#__PURE__*/ +_curry2(function gte(a, b) { return a >= b; }); +/** + * Returns whether or not a path exists in an object. Only the object's + * own properties are checked. + * + * @func + * @memberOf R + * @since v0.26.0 + * @category Object + * @typedefn Idx = String | Int + * @sig [Idx] -> {a} -> Boolean + * @param {Array} path The path to use. + * @param {Object} obj The object to check the path in. + * @return {Boolean} Whether the path exists. + * @see R.has + * @example + * + * R.hasPath(['a', 'b'], {a: {b: 2}}); // => true + * R.hasPath(['a', 'b'], {a: {b: undefined}}); // => true + * R.hasPath(['a', 'b'], {a: {c: 2}}); // => false + * R.hasPath(['a', 'b'], {}); // => false + */ + +var hasPath = +/*#__PURE__*/ +_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]]; + idx += 1; + } else { + return false; + } + } + + return true; +}); + /** * Returns whether or not an object has an own property with the specified name * @@ -4820,18 +6002,23 @@ var gte = /*#__PURE__*/_curry2(function gte(a, b) { * @return {Boolean} Whether the property exists. * @example * - * var hasName = R.has('name'); + * const hasName = R.has('name'); * hasName({name: 'alice'}); //=> true * hasName({name: 'bob'}); //=> true * hasName({}); //=> false * - * var point = {x: 0, y: 0}; - * var pointHas = R.has(R.__, point); + * const point = {x: 0, y: 0}; + * const pointHas = R.has(R.__, point); * pointHas('x'); //=> true * pointHas('y'); //=> true * pointHas('z'); //=> false */ -var has = /*#__PURE__*/_curry2(_has); + +var has = +/*#__PURE__*/ +_curry2(function has(prop, obj) { + return hasPath([prop], obj); +}); /** * Returns whether or not an object or its prototype chain has a property with @@ -4855,61 +6042,46 @@ var has = /*#__PURE__*/_curry2(_has); * return this.width * this.height; * }; * - * var square = new Rectangle(2, 2); + * const square = new Rectangle(2, 2); * R.hasIn('width', square); //=> true * R.hasIn('area', square); //=> true */ -var hasIn = /*#__PURE__*/_curry2(function hasIn(prop, obj) { + +var hasIn = +/*#__PURE__*/ +_curry2(function hasIn(prop, obj) { return prop in obj; }); /** - * Returns the first element of the given list or string. In some libraries - * this function is named `first`. - * - * @func - * @memberOf R - * @since v0.1.0 - * @category List - * @sig [a] -> a | Undefined - * @sig String -> String - * @param {Array|String} list - * @return {*} - * @see R.tail, R.init, R.last - * @example - * - * R.head(['fi', 'fo', 'fum']); //=> 'fi' - * R.head([]); //=> undefined + * Returns true if its arguments are identical, false otherwise. Values are + * identical if they reference the same memory. `NaN` is identical to `NaN`; + * `0` and `-0` are not identical. * - * R.head('abc'); //=> 'a' - * R.head(''); //=> '' - */ -var head = /*#__PURE__*/nth(0); - -function _identity(x) { - return x; -} - -/** - * A function that does nothing but return the parameter supplied to it. Good - * as a default or placeholder function. + * Note this is merely a curried version of ES6 `Object.is`. * * @func * @memberOf R - * @since v0.1.0 - * @category Function - * @sig a -> a - * @param {*} x The value to return. - * @return {*} The input value, `x`. + * @since v0.15.0 + * @category Relation + * @sig a -> a -> Boolean + * @param {*} a + * @param {*} b + * @return {Boolean} * @example * - * R.identity(1); //=> 1 - * - * var obj = {}; - * R.identity(obj) === obj; //=> true - * @symb R.identity(a) = a + * const o = {}; + * R.identical(o, o); //=> true + * R.identical(1, 1); //=> true + * R.identical(1, '1'); //=> false + * R.identical([], []); //=> false + * R.identical(0, -0); //=> false + * R.identical(NaN, NaN); //=> true */ -var identity = /*#__PURE__*/_curry1(_identity); + +var identical = +/*#__PURE__*/ +_curry2(_objectIs$1); /** * Creates a function that will process either the `onTrue` or the `onFalse` @@ -4923,12 +6095,12 @@ var identity = /*#__PURE__*/_curry1(_identity); * @param {Function} condition A predicate function * @param {Function} onTrue A function to invoke when the `condition` evaluates to a truthy value. * @param {Function} onFalse A function to invoke when the `condition` evaluates to a falsy value. - * @return {Function} A new unary function that will process either the `onTrue` or the `onFalse` + * @return {Function} A new function that will process either the `onTrue` or the `onFalse` * function depending upon the result of the `condition` predicate. - * @see R.unless, R.when + * @see R.unless, R.when, R.cond * @example * - * var incCount = R.ifElse( + * const incCount = R.ifElse( * R.has('count'), * R.over(R.lensProp('count'), R.inc), * R.assoc('count', 1) @@ -4936,7 +6108,10 @@ var identity = /*#__PURE__*/_curry1(_identity); * incCount({}); //=> { count: 1 } * incCount({ count: 1 }); //=> { count: 2 } */ -var ifElse = /*#__PURE__*/_curry3(function ifElse(condition, onTrue, onFalse) { + +var ifElse = +/*#__PURE__*/ +_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); }); @@ -4957,7 +6132,37 @@ var ifElse = /*#__PURE__*/_curry3(function ifElse(condition, onTrue, onFalse) { * * R.inc(42); //=> 43 */ -var inc = /*#__PURE__*/add(1); + +var inc = +/*#__PURE__*/ +add(1); + +/** + * Returns `true` if the specified value is equal, in [`R.equals`](#equals) + * terms, to at least one element of the given list; `false` otherwise. + * Works also with strings. + * + * @func + * @memberOf R + * @since v0.26.0 + * @category List + * @sig a -> [a] -> Boolean + * @param {Object} a The item to compare against. + * @param {Array} list The array to consider. + * @return {Boolean} `true` if an equivalent item is in the list, `false` otherwise. + * @see R.any + * @example + * + * R.includes(3, [1, 2, 3]); //=> true + * R.includes(4, [1, 2, 3]); //=> false + * R.includes({ name: 'Fred' }, [{ name: 'Fred' }]); //=> true + * R.includes([42], [[42]]); //=> true + * R.includes('ba', 'banana'); //=>true + */ + +var includes = +/*#__PURE__*/ +_curry2(_includes); /** * Given a function that generates a key, turns a list of objects into an @@ -4977,11 +6182,14 @@ var inc = /*#__PURE__*/add(1); * @return {Object} An object indexing each array element by the given property. * @example * - * var list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}]; + * const list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}]; * R.indexBy(R.prop('id'), list); * //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}} */ -var indexBy = /*#__PURE__*/reduceBy(function (acc, elem) { + +var indexBy = +/*#__PURE__*/ +reduceBy(function (acc, elem) { return elem; }, null); @@ -5004,7 +6212,10 @@ var indexBy = /*#__PURE__*/reduceBy(function (acc, elem) { * R.indexOf(3, [1,2,3,4]); //=> 2 * R.indexOf(10, [1,2,3,4]); //=> -1 */ -var indexOf = /*#__PURE__*/_curry2(function indexOf(target, xs) { + +var indexOf = +/*#__PURE__*/ +_curry2(function indexOf(target, xs) { return typeof xs.indexOf === 'function' && !_isArray(xs) ? xs.indexOf(target) : _indexOf(xs, target, 0); }); @@ -5032,7 +6243,10 @@ var indexOf = /*#__PURE__*/_curry2(function indexOf(target, xs) { * R.init('a'); //=> '' * R.init(''); //=> '' */ -var init = /*#__PURE__*/slice(0, -1); + +var init = +/*#__PURE__*/ +slice(0, -1); /** * Takes a predicate `pred`, a list `xs`, and a list `ys`, and returns a list @@ -5069,9 +6283,12 @@ var init = /*#__PURE__*/slice(0, -1); * ); * //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}] */ -var innerJoin = /*#__PURE__*/_curry3(function innerJoin(pred, xs, ys) { + +var innerJoin = +/*#__PURE__*/ +_curry3(function innerJoin(pred, xs, ys) { return _filter(function (x) { - return _containsWith(pred, x, ys); + return _includesWith(pred, x, ys); }, xs); }); @@ -5094,7 +6311,10 @@ var innerJoin = /*#__PURE__*/_curry3(function innerJoin(pred, xs, ys) { * * R.insert(2, 'x', [1,2,3,4]); //=> [1,2,'x',3,4] */ -var insert = /*#__PURE__*/_curry3(function insert(idx, elt, list) { + +var insert = +/*#__PURE__*/ +_curry3(function insert(idx, elt, list) { idx = idx < list.length && idx >= 0 ? idx : list.length; var result = Array.prototype.slice.call(list, 0); result.splice(idx, 0, elt); @@ -5119,180 +6339,14 @@ var insert = /*#__PURE__*/_curry3(function insert(idx, elt, list) { * * R.insertAll(2, ['x','y','z'], [1,2,3,4]); //=> [1,2,'x','y','z',3,4] */ -var insertAll = /*#__PURE__*/_curry3(function insertAll(idx, elts, list) { + +var insertAll = +/*#__PURE__*/ +_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)); }); -var _Set = /*#__PURE__*/function () { - function _Set() { - /* globals Set */ - this._nativeSet = typeof Set === 'function' ? new Set() : null; - this._items = {}; - } - - // 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. - // - // @param item The item to check or add to the Set instance. - // @param shouldAdd If true, the item will be added to the set if it doesn't - // already exist. - // @param set The set instance to check or add to. - // @return {boolean} true if the item already existed, otherwise false. - // - return _Set; -}(); - -function hasOrAdd(item, shouldAdd, set) { - var type = typeof item; - var prevSize, newSize; - switch (type) { - case 'string': - case 'number': - // distinguish between +0 and -0 - if (item === 0 && 1 / item === -Infinity) { - if (set._items['-0']) { - return true; - } else { - if (shouldAdd) { - set._items['-0'] = true; - } - return false; - } - } - // 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 { - return set._nativeSet.has(item); - } - } else { - if (!(type in set._items)) { - if (shouldAdd) { - set._items[type] = {}; - set._items[type][item] = true; - } - return false; - } else if (item in set._items[type]) { - return true; - } else { - 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 { - return set._nativeSet.has(item); - } - } else { - if (!(type in set._items)) { - if (shouldAdd) { - set._items[type] = [item]; - } - return false; - } - if (!_contains(item, set._items[type])) { - if (shouldAdd) { - set._items[type].push(item); - } - return false; - } - return true; - } - - case 'undefined': - if (set._items[type]) { - return true; - } else { - 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 - if (!_contains(item, set._items[type])) { - if (shouldAdd) { - set._items[type].push(item); - } - return false; - } - return true; - } -} - /** * Returns a new list containing only one copy of each element in the original * list, based upon the value returned by applying the supplied function to @@ -5311,7 +6365,10 @@ function hasOrAdd(item, shouldAdd, set) { * * R.uniqBy(Math.abs, [-1, -5, 2, 10, 1, 2]); //=> [-1, -5, 2, 10] */ -var uniqBy = /*#__PURE__*/_curry2(function uniqBy(fn, list) { + +var uniqBy = +/*#__PURE__*/ +_curry2(function uniqBy(fn, list) { var set = new _Set(); var result = []; var idx = 0; @@ -5320,11 +6377,14 @@ var uniqBy = /*#__PURE__*/_curry2(function uniqBy(fn, list) { while (idx < list.length) { item = list[idx]; appliedItem = fn(item); + if (set.add(appliedItem)) { result.push(item); } + idx += 1; } + return result; }); @@ -5345,7 +6405,10 @@ var uniqBy = /*#__PURE__*/_curry2(function uniqBy(fn, list) { * R.uniq([1, '1']); //=> [1, '1'] * R.uniq([[42], [42]]); //=> [[42]] */ -var uniq = /*#__PURE__*/uniqBy(identity); + +var uniq = +/*#__PURE__*/ +uniqBy(identity); /** * Combines two lists into a set (i.e. no duplicates) composed of those @@ -5364,8 +6427,12 @@ var uniq = /*#__PURE__*/uniqBy(identity); * * R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3] */ -var intersection = /*#__PURE__*/_curry2(function intersection(list1, list2) { + +var intersection = +/*#__PURE__*/ +_curry2(function intersection(list1, list2) { var lookupList, filteredList; + if (list1.length > list2.length) { lookupList = list1; filteredList = list2; @@ -5373,7 +6440,8 @@ var intersection = /*#__PURE__*/_curry2(function intersection(list1, list2) { lookupList = list2; filteredList = list1; } - return uniq(_filter(flip(_contains)(lookupList), filteredList)); + + return uniq(_filter(flip(_includes)(lookupList), filteredList)); }); /** @@ -5391,24 +6459,31 @@ var intersection = /*#__PURE__*/_curry2(function intersection(list1, list2) { * @return {Array} The new list. * @example * - * R.intersperse('n', ['ba', 'a', 'a']); //=> ['ba', 'n', 'a', 'n', 'a'] + * R.intersperse('a', ['b', 'n', 'n', 's']); //=> ['b', 'a', 'n', 'a', 'n', 'a', 's'] */ -var intersperse = /*#__PURE__*/_curry2( /*#__PURE__*/_checkForMethod('intersperse', function intersperse(separator, list) { + +var intersperse = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_checkForMethod('intersperse', function intersperse(separator, list) { var out = []; var idx = 0; var length = list.length; + while (idx < length) { if (idx === length - 1) { out.push(list[idx]); } else { out.push(list[idx], 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'); @@ -5417,8 +6492,10 @@ function _objectAssign(target) { 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)) { @@ -5426,12 +6503,14 @@ function _objectAssign(target) { } } } + idx += 1; } + return output; } -var _assign = typeof Object.assign === 'function' ? Object.assign : _objectAssign; +var _objectAssign$1 = typeof Object.assign === 'function' ? Object.assign : _objectAssign; /** * Creates an object containing a single key:value pair. @@ -5447,13 +6526,16 @@ var _assign = typeof Object.assign === 'function' ? Object.assign : _objectAssig * @see R.pair * @example * - * var matchPhrases = R.compose( + * const matchPhrases = R.compose( * R.objOf('must'), * R.map(R.objOf('match_phrase')) * ); * matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]} */ -var objOf = /*#__PURE__*/_curry2(function objOf(key, val) { + +var objOf = +/*#__PURE__*/ +_curry2(function objOf(key, val) { var obj = {}; obj[key] = val; return obj; @@ -5477,24 +6559,27 @@ var _stepCatString = { var _stepCatObject = { '@@transducer/init': Object, '@@transducer/step': function (result, input) { - return _assign(result, _isArrayLike(input) ? objOf(input[0], input[1]) : input); + return _objectAssign$1(result, _isArrayLike(input) ? objOf(input[0], input[1]) : input); }, '@@transducer/result': _identity }; - function _stepCat(obj) { 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); } @@ -5526,17 +6611,21 @@ function _stepCat(obj) { * @param {Function} xf The transducer function. Receives a transformer and returns a transformer. * @param {Array} list The list to iterate over. * @return {*} The final, accumulated value. + * @see R.transduce * @example * - * var numbers = [1, 2, 3, 4]; - * var transducer = R.compose(R.map(R.add(1)), R.take(2)); + * const numbers = [1, 2, 3, 4]; + * const transducer = R.compose(R.map(R.add(1)), R.take(2)); * * R.into([], transducer, numbers); //=> [2, 3] * - * var intoArray = R.into([]); + * const intoArray = R.into([]); * intoArray(transducer, numbers); //=> [2, 3] */ -var into = /*#__PURE__*/_curry3(function into(acc, xf, list) { + +var into = +/*#__PURE__*/ +_curry3(function into(acc, xf, list) { return _isTransformer(acc) ? _reduce(xf(acc), acc['@@transducer/init'](), list) : _reduce(xf(_stepCat(acc)), _clone(acc, [], [], false), list); }); @@ -5554,7 +6643,7 @@ var into = /*#__PURE__*/_curry3(function into(acc, xf, list) { * @see R.invertObj * @example * - * var raceResultsByFirstName = { + * const raceResultsByFirstName = { * first: 'alice', * second: 'jake', * third: 'alice', @@ -5562,7 +6651,10 @@ var into = /*#__PURE__*/_curry3(function into(acc, xf, list) { * R.invert(raceResultsByFirstName); * //=> { 'alice': ['first', 'third'], 'jake':['second'] } */ -var invert = /*#__PURE__*/_curry1(function invert(obj) { + +var invert = +/*#__PURE__*/ +_curry1(function invert(obj) { var props = keys(obj); var len = props.length; var idx = 0; @@ -5575,6 +6667,7 @@ var invert = /*#__PURE__*/_curry1(function invert(obj) { list[list.length] = key; idx += 1; } + return out; }); @@ -5593,7 +6686,7 @@ var invert = /*#__PURE__*/_curry1(function invert(obj) { * @see R.invert * @example * - * var raceResults = { + * const raceResults = { * first: 'alice', * second: 'jake' * }; @@ -5601,11 +6694,14 @@ var invert = /*#__PURE__*/_curry1(function invert(obj) { * //=> { 'alice': 'first', 'jake':'second' } * * // Alternatively: - * var raceResults = ['alice', 'jake']; + * const raceResults = ['alice', 'jake']; * R.invertObj(raceResults); * //=> { 'alice': '0', 'jake':'1' } */ -var invertObj = /*#__PURE__*/_curry1(function invertObj(obj) { + +var invertObj = +/*#__PURE__*/ +_curry1(function invertObj(obj) { var props = keys(obj); var len = props.length; var idx = 0; @@ -5616,6 +6712,7 @@ var invertObj = /*#__PURE__*/_curry1(function invertObj(obj) { out[obj[key]] = key; idx += 1; } + return out; }); @@ -5633,25 +6730,37 @@ var invertObj = /*#__PURE__*/_curry1(function invertObj(obj) { * @sig Number -> String -> (a -> b -> ... -> n -> Object -> *) * @param {Number} arity Number of arguments the returned function should take * before the target object. - * @param {String} method Name of the method to call. + * @param {String} method Name of any of the target object's methods to call. * @return {Function} A new curried function. * @see R.construct * @example * - * var sliceFrom = R.invoker(1, 'slice'); + * const sliceFrom = R.invoker(1, 'slice'); * sliceFrom(6, 'abcdefghijklm'); //=> 'ghijklm' - * var sliceFrom6 = R.invoker(2, 'slice')(6); + * const sliceFrom6 = R.invoker(2, 'slice')(6); * sliceFrom6(8, 'abcdefghijklm'); //=> 'gh' + * + * const dog = { + * speak: async () => 'Woof!' + * }; + * const speak = R.invoker(0, 'speak'); + * speak(dog).then(console.log) //~> 'Woof!' + * * @symb R.invoker(0, 'method')(o) = o['method']() * @symb R.invoker(1, 'method')(a, o) = o['method'](a) * @symb R.invoker(2, 'method')(a, b, o) = o['method'](a, b) */ -var invoker = /*#__PURE__*/_curry2(function invoker(arity, method) { + +var invoker = +/*#__PURE__*/ +_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 + '"'); }); }); @@ -5679,7 +6788,10 @@ var invoker = /*#__PURE__*/_curry2(function invoker(arity, method) { * R.is(Object, 's'); //=> false * R.is(Number, {}); //=> false */ -var is = /*#__PURE__*/_curry2(function is(Ctor, val) { + +var is = +/*#__PURE__*/ +_curry2(function is(Ctor, val) { return val != null && val.constructor === Ctor || val instanceof Ctor; }); @@ -5704,7 +6816,10 @@ var is = /*#__PURE__*/_curry2(function is(Ctor, val) { * R.isEmpty({}); //=> true * R.isEmpty({length: 0}); //=> false */ -var isEmpty = /*#__PURE__*/_curry1(function isEmpty(x) { + +var isEmpty = +/*#__PURE__*/ +_curry1(function isEmpty(x) { return x != null && equals(x, empty(x)); }); @@ -5723,11 +6838,14 @@ var isEmpty = /*#__PURE__*/_curry1(function isEmpty(x) { * @see R.split * @example * - * var spacer = R.join(' '); + * const spacer = R.join(' '); * spacer(['a', 2, 3.4]); //=> 'a 2 3.4' * R.join('|', [1, 2, 3]); //=> '1|2|3' */ -var join = /*#__PURE__*/invoker(1, 'join'); + +var join = +/*#__PURE__*/ +invoker(1, 'join'); /** * juxt applies a list of functions to a list of values. @@ -5742,11 +6860,14 @@ var join = /*#__PURE__*/invoker(1, 'join'); * @see R.applySpec * @example * - * var getRange = R.juxt([Math.min, Math.max]); + * const getRange = R.juxt([Math.min, Math.max]); * getRange(3, 4, 9, -3); //=> [-3, 9] * @symb R.juxt([f, g, h])(a, b) = [f(a, b), g(a, b), h(a, b)] */ -var juxt = /*#__PURE__*/_curry1(function juxt(fns) { + +var juxt = +/*#__PURE__*/ +_curry1(function juxt(fns) { return converge(function () { return Array.prototype.slice.call(arguments, 0); }, fns); @@ -5768,17 +6889,22 @@ var juxt = /*#__PURE__*/_curry1(function juxt(fns) { * @see R.keys, R.valuesIn * @example * - * var F = function() { this.x = 'X'; }; + * const F = function() { this.x = 'X'; }; * F.prototype.y = 'Y'; - * var f = new F(); + * const f = new F(); * R.keysIn(f); //=> ['x', 'y'] */ -var keysIn = /*#__PURE__*/_curry1(function keysIn(obj) { + +var keysIn = +/*#__PURE__*/ +_curry1(function keysIn(obj) { var prop; var ks = []; + for (prop in obj) { ks[ks.length] = prop; } + return ks; }); @@ -5801,17 +6927,23 @@ var keysIn = /*#__PURE__*/_curry1(function keysIn(obj) { * R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6 * R.lastIndexOf(10, [1,2,3,4]); //=> -1 */ -var lastIndexOf = /*#__PURE__*/_curry2(function lastIndexOf(target, xs) { + +var lastIndexOf = +/*#__PURE__*/ +_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; } }); @@ -5835,7 +6967,10 @@ function _isNumber(x) { * R.length([]); //=> 0 * R.length([1, 2, 3]); //=> 3 */ -var length = /*#__PURE__*/_curry1(function length(list) { + +var length = +/*#__PURE__*/ +_curry1(function length(list) { return list != null && _isNumber(list.length) ? list.length : NaN; }); @@ -5856,13 +6991,16 @@ var length = /*#__PURE__*/_curry1(function length(list) { * @see R.view, R.set, R.over, R.lensIndex, R.lensProp * @example * - * var xLens = R.lens(R.prop('x'), R.assoc('x')); + * const xLens = R.lens(R.prop('x'), R.assoc('x')); * * R.view(xLens, {x: 1, y: 2}); //=> 1 * 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 = /*#__PURE__*/_curry2(function lens(getter, setter) { + +var lens = +/*#__PURE__*/ +_curry2(function lens(getter, setter) { return function (toFunctorFn) { return function (target) { return map(function (focus) { @@ -5883,16 +7021,19 @@ var lens = /*#__PURE__*/_curry2(function lens(getter, setter) { * @sig Number -> Lens s a * @param {Number} n * @return {Lens} - * @see R.view, R.set, R.over + * @see R.view, R.set, R.over, R.nth * @example * - * var headLens = R.lensIndex(0); + * const headLens = R.lensIndex(0); * * R.view(headLens, ['a', 'b', 'c']); //=> 'a' * R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c'] * R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c'] */ -var lensIndex = /*#__PURE__*/_curry1(function lensIndex(n) { + +var lensIndex = +/*#__PURE__*/ +_curry1(function lensIndex(n) { return lens(nth(n), update(n)); }); @@ -5911,7 +7052,7 @@ var lensIndex = /*#__PURE__*/_curry1(function lensIndex(n) { * @see R.view, R.set, R.over * @example * - * var xHeadYLens = R.lensPath(['x', 0, 'y']); + * const xHeadYLens = R.lensPath(['x', 0, 'y']); * * R.view(xHeadYLens, {x: [{y: 2, z: 3}, {y: 4, z: 5}]}); * //=> 2 @@ -5920,7 +7061,10 @@ var lensIndex = /*#__PURE__*/_curry1(function lensIndex(n) { * R.over(xHeadYLens, R.negate, {x: [{y: 2, z: 3}, {y: 4, z: 5}]}); * //=> {x: [{y: -2, z: 3}, {y: 4, z: 5}]} */ -var lensPath = /*#__PURE__*/_curry1(function lensPath(p) { + +var lensPath = +/*#__PURE__*/ +_curry1(function lensPath(p) { return lens(path(p), assocPath(p)); }); @@ -5938,13 +7082,16 @@ var lensPath = /*#__PURE__*/_curry1(function lensPath(p) { * @see R.view, R.set, R.over * @example * - * var xLens = R.lensProp('x'); + * const xLens = R.lensProp('x'); * * R.view(xLens, {x: 1, y: 2}); //=> 1 * 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 = /*#__PURE__*/_curry1(function lensProp(k) { + +var lensProp = +/*#__PURE__*/ +_curry1(function lensProp(k) { return lens(prop(k), assoc(k)); }); @@ -5969,7 +7116,10 @@ var lensProp = /*#__PURE__*/_curry1(function lensProp(k) { * R.lt('a', 'z'); //=> true * R.lt('z', 'a'); //=> false */ -var lt = /*#__PURE__*/_curry2(function lt(a, b) { + +var lt = +/*#__PURE__*/ +_curry2(function lt(a, b) { return a < b; }); @@ -5994,7 +7144,10 @@ var lt = /*#__PURE__*/_curry2(function lt(a, b) { * R.lte('a', 'z'); //=> true * R.lte('z', 'a'); //=> false */ -var lte = /*#__PURE__*/_curry2(function lte(a, b) { + +var lte = +/*#__PURE__*/ +_curry2(function lte(a, b) { return a <= b; }); @@ -6016,11 +7169,11 @@ var lte = /*#__PURE__*/_curry2(function lte(a, b) { * @param {*} acc The accumulator value. * @param {Array} list The list to iterate over. * @return {*} The final, accumulated value. - * @see R.addIndex, R.mapAccumRight + * @see R.scan, R.addIndex, R.mapAccumRight * @example * - * var digits = ['1', '2', '3', '4']; - * var appender = (a, b) => [a + b, a + b]; + * const digits = ['1', '2', '3', '4']; + * const appender = (a, b) => [a + b, a + b]; * * R.mapAccum(appender, 0, digits); //=> ['01234', ['01', '012', '0123', '01234']] * @symb R.mapAccum(f, a, [b, c, d]) = [ @@ -6032,16 +7185,21 @@ var lte = /*#__PURE__*/_curry2(function lte(a, b) { * ] * ] */ -var mapAccum = /*#__PURE__*/_curry3(function mapAccum(fn, acc, list) { + +var mapAccum = +/*#__PURE__*/ +_curry3(function mapAccum(fn, acc, list) { var idx = 0; var len = list.length; var result = []; var tuple = [acc]; + while (idx < len) { tuple = fn(tuple[0], list[idx]); result[idx] = tuple[1]; idx += 1; } + return [tuple[0], result]; }); @@ -6054,14 +7212,14 @@ var mapAccum = /*#__PURE__*/_curry3(function mapAccum(fn, acc, list) { * Similar to [`mapAccum`](#mapAccum), except moves through the input list from * the right to the left. * - * The iterator function receives two arguments, *value* and *acc*, and should - * return a tuple *[value, acc]*. + * The iterator function receives two arguments, *acc* and *value*, and should + * return a tuple *[acc, value]*. * * @func * @memberOf R * @since v0.10.0 * @category List - * @sig ((x, acc) -> (y, acc)) -> acc -> [x] -> ([y], acc) + * @sig ((acc, x) -> (acc, y)) -> acc -> [x] -> (acc, [y]) * @param {Function} fn The function to be called on every element of the input `list`. * @param {*} acc The accumulator value. * @param {Array} list The list to iterate over. @@ -6069,29 +7227,34 @@ var mapAccum = /*#__PURE__*/_curry3(function mapAccum(fn, acc, list) { * @see R.addIndex, R.mapAccum * @example * - * var digits = ['1', '2', '3', '4']; - * var append = (a, b) => [a + b, a + b]; + * const digits = ['1', '2', '3', '4']; + * const appender = (a, b) => [b + a, b + a]; * - * R.mapAccumRight(append, 5, digits); //=> [['12345', '2345', '345', '45'], '12345'] + * R.mapAccumRight(appender, 5, digits); //=> ['12345', ['12345', '2345', '345', '45']] * @symb R.mapAccumRight(f, a, [b, c, d]) = [ + * f(f(f(a, d)[0], c)[0], b)[0], * [ - * f(b, f(c, f(d, a)[0])[0])[1], - * f(c, f(d, a)[0])[1], - * f(d, a)[1], + * f(a, d)[1], + * f(f(a, d)[0], c)[1], + * f(f(f(a, d)[0], c)[0], b)[1] * ] - * f(b, f(c, f(d, a)[0])[0])[0], * ] */ -var mapAccumRight = /*#__PURE__*/_curry3(function mapAccumRight(fn, acc, list) { + +var mapAccumRight = +/*#__PURE__*/ +_curry3(function mapAccumRight(fn, acc, list) { var idx = list.length - 1; var result = []; var tuple = [acc]; + while (idx >= 0) { - tuple = fn(list[idx], tuple[0]); + tuple = fn(tuple[0], list[idx]); result[idx] = tuple[1]; idx -= 1; } - return [result, tuple[0]]; + + return [tuple[0], result]; }); /** @@ -6110,12 +7273,15 @@ var mapAccumRight = /*#__PURE__*/_curry3(function mapAccumRight(fn, acc, list) { * @see R.map * @example * - * var values = { x: 1, y: 2, z: 3 }; - * var prependKeyAndDouble = (num, key, obj) => key + (num * 2); + * const xyz = { x: 1, y: 2, z: 3 }; + * const prependKeyAndDouble = (num, key, obj) => key + (num * 2); * - * R.mapObjIndexed(prependKeyAndDouble, values); //=> { x: 'x2', y: 'y4', z: 'z6' } + * R.mapObjIndexed(prependKeyAndDouble, xyz); //=> { x: 'x2', y: 'y4', z: 'z6' } */ -var mapObjIndexed = /*#__PURE__*/_curry2(function mapObjIndexed(fn, obj) { + +var mapObjIndexed = +/*#__PURE__*/ +_curry2(function mapObjIndexed(fn, obj) { return _reduce(function (acc, key) { acc[key] = fn(obj[key], key, obj); return acc; @@ -6143,7 +7309,10 @@ var mapObjIndexed = /*#__PURE__*/_curry2(function mapObjIndexed(fn, obj) { * R.match(/a/, 'b'); //=> [] * R.match(/a/, null); //=> TypeError: null does not have a method named "match" */ -var match = /*#__PURE__*/_curry2(function match(rx, str) { + +var match = +/*#__PURE__*/ +_curry2(function match(rx, str) { return str.match(rx) || []; }); @@ -6171,22 +7340,27 @@ var match = /*#__PURE__*/_curry2(function match(rx, str) { * R.mathMod(17.2, 5); //=> NaN * R.mathMod(17, 5.3); //=> NaN * - * var clock = R.mathMod(R.__, 12); + * const clock = R.mathMod(R.__, 12); * clock(15); //=> 3 * clock(24); //=> 0 * - * var seventeenMod = R.mathMod(17); + * const seventeenMod = R.mathMod(17); * seventeenMod(3); //=> 2 * seventeenMod(4); //=> 1 * seventeenMod(10); //=> 7 */ -var mathMod = /*#__PURE__*/_curry2(function mathMod(m, p) { + +var mathMod = +/*#__PURE__*/ +_curry2(function mathMod(m, p) { if (!_isInteger(m)) { return NaN; } + if (!_isInteger(p) || p < 1) { return NaN; } + return (m % p + p) % p; }); @@ -6207,14 +7381,17 @@ var mathMod = /*#__PURE__*/_curry2(function mathMod(m, p) { * @example * * // square :: Number -> Number - * var square = n => n * n; + * const square = n => n * n; * * R.maxBy(square, -3, 2); //=> -3 * * R.reduce(R.maxBy(square), 0, [3, -5, 4, 1, -2]); //=> -5 * R.reduce(R.maxBy(square), 0, []); //=> 0 */ -var maxBy = /*#__PURE__*/_curry3(function maxBy(f, a, b) { + +var maxBy = +/*#__PURE__*/ +_curry3(function maxBy(f, a, b) { return f(b) > f(a) ? b : a; }); @@ -6233,7 +7410,10 @@ var maxBy = /*#__PURE__*/_curry3(function maxBy(f, a, b) { * * R.sum([2,4,6,8,100,1]); //=> 121 */ -var sum = /*#__PURE__*/reduce(add, 0); + +var sum = +/*#__PURE__*/ +reduce(add, 0); /** * Returns the mean of the given list of numbers. @@ -6251,7 +7431,10 @@ var sum = /*#__PURE__*/reduce(add, 0); * R.mean([2, 7, 9]); //=> 6 * R.mean([]); //=> NaN */ -var mean = /*#__PURE__*/_curry1(function mean(list) { + +var mean = +/*#__PURE__*/ +_curry1(function mean(list) { return sum(list) / list.length; }); @@ -6272,11 +7455,16 @@ var mean = /*#__PURE__*/_curry1(function mean(list) { * R.median([7, 2, 10, 9]); //=> 8 * R.median([]); //=> NaN */ -var median = /*#__PURE__*/_curry1(function median(list) { + +var median = +/*#__PURE__*/ +_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) { @@ -6285,11 +7473,11 @@ var median = /*#__PURE__*/_curry1(function median(list) { }); /** - * A customisable version of [`R.memoize`](#memoize). `memoizeWith` takes an - * additional function that will be applied to a given argument set and used to - * create the cache key under which the results of the function to be memoized - * will be stored. Care must be taken when implementing key generation to avoid - * clashes that may overwrite previous entries erroneously. + * Creates a new function that, when invoked, caches the result of calling `fn` + * for a given argument set and returns the result. Subsequent calls to the + * memoized `fn` with the same argument set will not result in an additional + * call to `fn`; instead, the cached result for that set of arguments will be + * returned. * * * @func @@ -6300,7 +7488,6 @@ var median = /*#__PURE__*/_curry1(function median(list) { * @param {Function} fn The function to generate the cache key. * @param {Function} fn The function to memoize. * @return {Function} Memoized version of `fn`. - * @see R.memoize * @example * * let count = 0; @@ -6313,49 +7500,22 @@ var median = /*#__PURE__*/_curry1(function median(list) { * factorial(5); //=> 120 * count; //=> 1 */ -var memoizeWith = /*#__PURE__*/_curry2(function memoizeWith(mFn, fn) { + +var memoizeWith = +/*#__PURE__*/ +_curry2(function memoizeWith(mFn, fn) { var cache = {}; return _arity(fn.length, function () { var key = mFn.apply(this, arguments); + if (!_has(key, cache)) { cache[key] = fn.apply(this, arguments); } + return cache[key]; }); }); -/** - * Creates a new function that, when invoked, caches the result of calling `fn` - * for a given argument set and returns the result. Subsequent calls to the - * memoized `fn` with the same argument set will not result in an additional - * call to `fn`; instead, the cached result for that set of arguments will be - * returned. - * - * @func - * @memberOf R - * @since v0.1.0 - * @category Function - * @sig (*... -> a) -> (*... -> a) - * @param {Function} fn The function to memoize. - * @return {Function} Memoized version of `fn`. - * @see R.memoizeWith - * @deprecated since v0.25.0 - * @example - * - * let count = 0; - * const factorial = R.memoize(n => { - * count += 1; - * return R.product(R.range(1, n + 1)); - * }); - * factorial(5); //=> 120 - * factorial(5); //=> 120 - * factorial(5); //=> 120 - * count; //=> 1 - */ -var memoize = /*#__PURE__*/memoizeWith(function () { - return toString$1(arguments); -}); - /** * Create a new object with the own properties of the first object merged with * the own properties of the second object. If a key exists in both objects, @@ -6369,18 +7529,22 @@ var memoize = /*#__PURE__*/memoizeWith(function () { * @param {Object} l * @param {Object} r * @return {Object} - * @see R.mergeDeepRight, R.mergeWith, R.mergeWithKey + * @see R.mergeRight, R.mergeDeepRight, R.mergeWith, R.mergeWithKey + * @deprecated since v0.26.0 * @example * * R.merge({ 'name': 'fred', 'age': 10 }, { 'age': 40 }); * //=> { 'name': 'fred', 'age': 40 } * - * var resetToDefault = R.merge(R.__, {x: 0}); - * resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2} - * @symb R.merge({ x: 1, y: 2 }, { y: 5, z: 3 }) = { x: 1, y: 5, z: 3 } + * const withDefaults = R.merge({x: 0, y: 0}); + * withDefaults({y: 2}); //=> {x: 0, y: 2} + * @symb R.merge(a, b) = {...a, ...b} */ -var merge = /*#__PURE__*/_curry2(function merge(l, r) { - return _assign({}, l, r); + +var merge = +/*#__PURE__*/ +_curry2(function merge(l, r) { + return _objectAssign$1({}, l, r); }); /** @@ -6400,8 +7564,11 @@ var merge = /*#__PURE__*/_curry2(function merge(l, r) { * 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 = /*#__PURE__*/_curry1(function mergeAll(list) { - return _assign.apply(null, [{}].concat(list)); + +var mergeAll = +/*#__PURE__*/ +_curry1(function mergeAll(list) { + return _objectAssign$1.apply(null, [{}].concat(list)); }); /** @@ -6429,7 +7596,10 @@ var mergeAll = /*#__PURE__*/_curry1(function mergeAll(list) { * //=> { 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 = /*#__PURE__*/_curry3(function mergeWithKey(fn, l, r) { + +var mergeWithKey = +/*#__PURE__*/ +_curry3(function mergeWithKey(fn, l, r) { var result = {}; var k; @@ -6467,7 +7637,7 @@ var mergeWithKey = /*#__PURE__*/_curry3(function mergeWithKey(fn, l, r) { * @param {Object} lObj * @param {Object} rObj * @return {Object} - * @see R.mergeWithKey, R.mergeDeep, R.mergeDeepWith + * @see R.mergeWithKey, R.mergeDeepWith * @example * * let concatValues = (k, l, r) => k == 'values' ? R.concat(l, r) : r @@ -6476,7 +7646,10 @@ var mergeWithKey = /*#__PURE__*/_curry3(function mergeWithKey(fn, l, r) { * { b: true, c: { thing: 'bar', values: [15, 35] }}); * //=> { a: true, b: true, c: { thing: 'bar', values: [10, 20, 15, 35] }} */ -var mergeDeepWithKey = /*#__PURE__*/_curry3(function mergeDeepWithKey(fn, lObj, rObj) { + +var mergeDeepWithKey = +/*#__PURE__*/ +_curry3(function mergeDeepWithKey(fn, lObj, rObj) { return mergeWithKey(function (k, lVal, rVal) { if (_isObject(lVal) && _isObject(rVal)) { return mergeDeepWithKey(fn, lVal, rVal); @@ -6507,7 +7680,10 @@ var mergeDeepWithKey = /*#__PURE__*/_curry3(function mergeDeepWithKey(fn, lObj, * { age: 40, contact: { email: 'baa@example.com' }}); * //=> { name: 'fred', age: 10, contact: { email: 'moo@example.com' }} */ -var mergeDeepLeft = /*#__PURE__*/_curry2(function mergeDeepLeft(lObj, rObj) { + +var mergeDeepLeft = +/*#__PURE__*/ +_curry2(function mergeDeepLeft(lObj, rObj) { return mergeDeepWithKey(function (k, lVal, rVal) { return lVal; }, lObj, rObj); @@ -6534,7 +7710,10 @@ var mergeDeepLeft = /*#__PURE__*/_curry2(function mergeDeepLeft(lObj, rObj) { * { age: 40, contact: { email: 'baa@example.com' }}); * //=> { name: 'fred', age: 40, contact: { email: 'baa@example.com' }} */ -var mergeDeepRight = /*#__PURE__*/_curry2(function mergeDeepRight(lObj, rObj) { + +var mergeDeepRight = +/*#__PURE__*/ +_curry2(function mergeDeepRight(lObj, rObj) { return mergeDeepWithKey(function (k, lVal, rVal) { return rVal; }, lObj, rObj); @@ -6559,7 +7738,7 @@ var mergeDeepRight = /*#__PURE__*/_curry2(function mergeDeepRight(lObj, rObj) { * @param {Object} lObj * @param {Object} rObj * @return {Object} - * @see R.mergeWith, R.mergeDeep, R.mergeDeepWithKey + * @see R.mergeWith, R.mergeDeepWithKey * @example * * R.mergeDeepWith(R.concat, @@ -6567,12 +7746,75 @@ var mergeDeepRight = /*#__PURE__*/_curry2(function mergeDeepRight(lObj, rObj) { * { b: true, c: { values: [15, 35] }}); * //=> { a: true, b: true, c: { values: [10, 20, 15, 35] }} */ -var mergeDeepWith = /*#__PURE__*/_curry3(function mergeDeepWith(fn, lObj, rObj) { + +var mergeDeepWith = +/*#__PURE__*/ +_curry3(function mergeDeepWith(fn, lObj, rObj) { return mergeDeepWithKey(function (k, lVal, rVal) { return fn(lVal, rVal); }, lObj, rObj); }); +/** + * Create a new object with the own properties of the first object merged with + * the own properties of the second object. If a key exists in both objects, + * the value from the first object will be used. + * + * @func + * @memberOf R + * @since v0.26.0 + * @category Object + * @sig {k: v} -> {k: v} -> {k: v} + * @param {Object} l + * @param {Object} r + * @return {Object} + * @see R.mergeRight, R.mergeDeepLeft, R.mergeWith, R.mergeWithKey + * @example + * + * R.mergeLeft({ 'age': 40 }, { 'name': 'fred', 'age': 10 }); + * //=> { 'name': 'fred', 'age': 40 } + * + * const resetToDefault = R.mergeLeft({x: 0}); + * resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2} + * @symb R.mergeLeft(a, b) = {...b, ...a} + */ + +var mergeLeft = +/*#__PURE__*/ +_curry2(function mergeLeft(l, r) { + return _objectAssign$1({}, r, l); +}); + +/** + * Create a new object with the own properties of the first object merged with + * the own properties of the second object. If a key exists in both objects, + * the value from the second object will be used. + * + * @func + * @memberOf R + * @since v0.26.0 + * @category Object + * @sig {k: v} -> {k: v} -> {k: v} + * @param {Object} l + * @param {Object} r + * @return {Object} + * @see R.mergeLeft, R.mergeDeepRight, R.mergeWith, R.mergeWithKey + * @example + * + * R.mergeRight({ 'name': 'fred', 'age': 10 }, { 'age': 40 }); + * //=> { 'name': 'fred', 'age': 40 } + * + * const withDefaults = R.mergeRight({x: 0, y: 0}); + * withDefaults({y: 2}); //=> {x: 0, y: 2} + * @symb R.mergeRight(a, b) = {...a, ...b} + */ + +var mergeRight = +/*#__PURE__*/ +_curry2(function mergeRight(l, r) { + return _objectAssign$1({}, l, r); +}); + /** * Creates a new object with the own properties of the two provided objects. If * a key exists in both objects, the provided function is applied to the values @@ -6596,7 +7838,10 @@ var mergeDeepWith = /*#__PURE__*/_curry3(function mergeDeepWith(fn, lObj, rObj) * { b: true, values: [15, 35] }); * //=> { a: true, b: true, values: [10, 20, 15, 35] } */ -var mergeWith = /*#__PURE__*/_curry3(function mergeWith(fn, l, r) { + +var mergeWith = +/*#__PURE__*/ +_curry3(function mergeWith(fn, l, r) { return mergeWithKey(function (_, _l, _r) { return fn(_l, _r); }, l, r); @@ -6619,7 +7864,10 @@ var mergeWith = /*#__PURE__*/_curry3(function mergeWith(fn, l, r) { * R.min(789, 123); //=> 123 * R.min('a', 'b'); //=> 'a' */ -var min = /*#__PURE__*/_curry2(function min(a, b) { + +var min = +/*#__PURE__*/ +_curry2(function min(a, b) { return b < a ? b : a; }); @@ -6640,14 +7888,17 @@ var min = /*#__PURE__*/_curry2(function min(a, b) { * @example * * // square :: Number -> Number - * var square = n => n * n; + * const square = n => n * n; * * R.minBy(square, -3, 2); //=> 2 * * R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]); //=> 1 * R.reduce(R.minBy(square), Infinity, []); //=> Infinity */ -var minBy = /*#__PURE__*/_curry3(function minBy(f, a, b) { + +var minBy = +/*#__PURE__*/ +_curry3(function minBy(f, a, b) { return f(b) < f(a) ? b : a; }); @@ -6672,14 +7923,47 @@ var minBy = /*#__PURE__*/_curry3(function minBy(f, a, b) { * R.modulo(-17, 3); //=> -2 * R.modulo(17, -3); //=> 2 * - * var isOdd = R.modulo(R.__, 2); + * const isOdd = R.modulo(R.__, 2); * isOdd(42); //=> 0 * isOdd(21); //=> 1 */ -var modulo = /*#__PURE__*/_curry2(function modulo(a, b) { + +var modulo = +/*#__PURE__*/ +_curry2(function modulo(a, b) { return a % b; }); +/** + * Move an item, at index `from`, to index `to`, in a list of elements. + * A new list will be created containing the new elements order. + * + * @func + * @memberOf R + * @since v0.27.1 + * @category List + * @sig Number -> Number -> [a] -> [a] + * @param {Number} from The source index + * @param {Number} to The destination index + * @param {Array} list The list which will serve to realise the move + * @return {Array} The new list reordered + * @example + * + * 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 = +/*#__PURE__*/ +_curry3(function (from, to, list) { + var length = list.length; + var result = list.slice(); + var positiveFrom = from < 0 ? length + from : from; + var positiveTo = to < 0 ? length + to : to; + var item = result.splice(positiveFrom, 1); + return positiveFrom < 0 || positiveFrom >= list.length || positiveTo < 0 || positiveTo >= list.length ? list : [].concat(result.slice(0, positiveTo)).concat(item).concat(result.slice(positiveTo, list.length)); +}); + /** * Multiplies two numbers. Equivalent to `a * b` but curried. * @@ -6694,13 +7978,16 @@ var modulo = /*#__PURE__*/_curry2(function modulo(a, b) { * @see R.divide * @example * - * var double = R.multiply(2); - * var triple = R.multiply(3); + * const double = R.multiply(2); + * const triple = R.multiply(3); * double(3); //=> 6 * triple(4); //=> 12 * R.multiply(2, 5); //=> 10 */ -var multiply = /*#__PURE__*/_curry2(function multiply(a, b) { + +var multiply = +/*#__PURE__*/ +_curry2(function multiply(a, b) { return a * b; }); @@ -6718,7 +8005,10 @@ var multiply = /*#__PURE__*/_curry2(function multiply(a, b) { * * R.negate(42); //=> -42 */ -var negate = /*#__PURE__*/_curry1(function negate(n) { + +var negate = +/*#__PURE__*/ +_curry1(function negate(n) { return -n; }); @@ -6726,7 +8016,9 @@ var negate = /*#__PURE__*/_curry1(function negate(n) { * Returns `true` if no elements of the list match the predicate, `false` * otherwise. * - * Dispatches to the `any` method of the second argument, if present. + * Dispatches to the `all` method of the second argument, if present. + * + * Acts as a transducer if a transformer is given in list position. * * @func * @memberOf R @@ -6739,13 +8031,18 @@ var negate = /*#__PURE__*/_curry1(function negate(n) { * @see R.all, R.any * @example * - * var isEven = n => n % 2 === 0; - * var isOdd = n => n % 2 === 1; + * const isEven = n => n % 2 === 0; + * const isOdd = n => n % 2 === 1; * * R.none(isEven, [1, 3, 5, 7, 9, 11]); //=> true * R.none(isOdd, [1, 3, 5, 7, 8, 11]); //=> false */ -var none = /*#__PURE__*/_curry2( /*#__PURE__*/_complement( /*#__PURE__*/_dispatchable(['any'], _xany, any))); + +var none = +/*#__PURE__*/ +_curry2(function none(fn, input) { + return all(_complement(fn), input); +}); /** * Returns a function which returns its nth argument. @@ -6765,7 +8062,10 @@ var none = /*#__PURE__*/_curry2( /*#__PURE__*/_complement( /*#__PURE__*/_dispatc * @symb R.nthArg(0)(a, b, c) = a * @symb R.nthArg(1)(a, b, c) = b */ -var nthArg = /*#__PURE__*/_curry1(function nthArg(n) { + +var nthArg = +/*#__PURE__*/ +_curry1(function nthArg(n) { var arity = n < 0 ? 1 : n + 1; return curryN(arity, function () { return nth(n, arguments); @@ -6776,7 +8076,9 @@ var nthArg = /*#__PURE__*/_curry1(function nthArg(n) { * `o` is a curried composition function that returns a unary function. * Like [`compose`](#compose), `o` performs right-to-left function composition. * Unlike [`compose`](#compose), the rightmost function passed to `o` will be - * invoked with only one argument. + * invoked with only one argument. Also, unlike [`compose`](#compose), `o` is + * limited to accepting only 2 unary functions. The name o was chosen because + * of its similarity to the mathematical composition operator ∘. * * @func * @memberOf R @@ -6789,15 +8091,18 @@ var nthArg = /*#__PURE__*/_curry1(function nthArg(n) { * @see R.compose, R.pipe * @example * - * var classyGreeting = name => "The name's " + name.last + ", " + name.first + " " + name.last - * var yellGreeting = R.o(R.toUpper, classyGreeting); + * const classyGreeting = name => "The name's " + name.last + ", " + name.first + " " + name.last + * const yellGreeting = R.o(R.toUpper, classyGreeting); * yellGreeting({first: 'James', last: 'Bond'}); //=> "THE NAME'S BOND, JAMES BOND" * * R.o(R.multiply(10), R.add(10))(-4) //=> 60 * * @symb R.o(f, g, x) = f(g(x)) */ -var o = /*#__PURE__*/_curry3(function o(f, g, x) { + +var o = +/*#__PURE__*/ +_curry3(function o(f, g, x) { return f(g(x)); }); @@ -6823,7 +8128,10 @@ function _of(x) { * R.of(null); //=> [null] * R.of([42]); //=> [[42]] */ -var of = /*#__PURE__*/_curry1(_of); + +var of = +/*#__PURE__*/ +_curry1(_of); /** * Returns a partial copy of an object omitting the keys specified. @@ -6841,7 +8149,10 @@ var of = /*#__PURE__*/_curry1(_of); * * R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3} */ -var omit = /*#__PURE__*/_curry2(function omit(names, obj) { + +var omit = +/*#__PURE__*/ +_curry2(function omit(names, obj) { var result = {}; var index = {}; var idx = 0; @@ -6857,6 +8168,7 @@ var omit = /*#__PURE__*/_curry2(function omit(names, obj) { result[prop] = obj[prop]; } } + return result; }); @@ -6875,31 +8187,80 @@ var omit = /*#__PURE__*/_curry2(function omit(names, obj) { * @return {Function} The wrapped function. * @example * - * var addOneOnce = R.once(x => x + 1); + * const addOneOnce = R.once(x => x + 1); * addOneOnce(10); //=> 11 * addOneOnce(addOneOnce(50)); //=> 11 */ -var once = /*#__PURE__*/_curry1(function once(fn) { + +var once = +/*#__PURE__*/ +_curry1(function once(fn) { var called = false; var result; return _arity(fn.length, function () { if (called) { return result; } + called = true; result = fn.apply(this, arguments); return result; }); }); -// `Identity` is a functor that holds a single value, where `map` simply +function _assertPromise(name, p) { + if (p == null || !_isFunction(p.then)) { + throw new TypeError('`' + name + '` expected a Promise, received ' + _toString(p, [])); + } +} + +/** + * Returns the result of applying the onFailure function to the value inside + * a failed promise. This is useful for handling rejected promises + * inside function compositions. + * + * @func + * @memberOf R + * @since v0.26.0 + * @category Function + * @sig (e -> b) -> (Promise e a) -> (Promise e b) + * @sig (e -> (Promise f b)) -> (Promise e a) -> (Promise f b) + * @param {Function} onFailure The function to apply. Can return a value or a promise of a value. + * @param {Promise} p + * @return {Promise} The result of calling `p.then(null, onFailure)` + * @see R.then + * @example + * + * var failedFetch = (id) => Promise.reject('bad ID'); + * var useDefault = () => ({ firstName: 'Bob', lastName: 'Loblaw' }) + * + * //recoverFromFailure :: String -> Promise ({firstName, lastName}) + * var recoverFromFailure = R.pipe( + * failedFetch, + * R.otherwise(useDefault), + * R.then(R.pick(['firstName', 'lastName'])), + * ); + * recoverFromFailure(12345).then(console.log) + */ + +var otherwise = +/*#__PURE__*/ +_curry2(function otherwise(f, p) { + _assertPromise('otherwise', p); + + return p.then(null, f); +}); + // transforms the held value with the provided function. + var Identity = function (x) { - return { value: x, map: function (f) { + return { + value: x, + map: function (f) { return Identity(f(x)); - } }; + } + }; }; - /** * 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 @@ -6918,11 +8279,15 @@ var Identity = function (x) { * @see R.prop, R.lensIndex, R.lensProp * @example * - * var headLens = R.lensIndex(0); + * const headLens = R.lensIndex(0); * * R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz'] */ -var over = /*#__PURE__*/_curry3(function over(lens, f, x) { + + +var over = +/*#__PURE__*/ +_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 // setter function of the lens. @@ -6947,7 +8312,10 @@ var over = /*#__PURE__*/_curry3(function over(lens, f, x) { * * R.pair('foo', 'bar'); //=> ['foo', 'bar'] */ -var pair = /*#__PURE__*/_curry2(function pair(fst, snd) { + +var pair = +/*#__PURE__*/ +_curry2(function pair(fst, snd) { return [fst, snd]; }); @@ -6972,22 +8340,25 @@ function _createPartialApplicator(concat) { * @param {Function} f * @param {Array} args * @return {Function} - * @see R.partialRight + * @see R.partialRight, R.curry * @example * - * var multiply2 = (a, b) => a * b; - * var double = R.partial(multiply2, [2]); + * const multiply2 = (a, b) => a * b; + * const double = R.partial(multiply2, [2]); * double(2); //=> 4 * - * var greet = (salutation, title, firstName, lastName) => + * const greet = (salutation, title, firstName, lastName) => * salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!'; * - * var sayHello = R.partial(greet, ['Hello']); - * var sayHelloToMs = R.partial(sayHello, ['Ms.']); + * const sayHello = R.partial(greet, ['Hello']); + * const sayHelloToMs = R.partial(sayHello, ['Ms.']); * sayHelloToMs('Jane', 'Jones'); //=> 'Hello, Ms. Jane Jones!' * @symb R.partial(f, [a, b])(c, d) = f(a, b, c, d) */ -var partial = /*#__PURE__*/_createPartialApplicator(_concat); + +var partial = +/*#__PURE__*/ +_createPartialApplicator(_concat); /** * Takes a function `f` and a list of arguments, and returns a function `g`. @@ -7005,15 +8376,20 @@ var partial = /*#__PURE__*/_createPartialApplicator(_concat); * @see R.partial * @example * - * var greet = (salutation, title, firstName, lastName) => + * const greet = (salutation, title, firstName, lastName) => * salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!'; * - * var greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']); + * 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) */ -var partialRight = /*#__PURE__*/_createPartialApplicator( /*#__PURE__*/flip(_concat)); + +var partialRight = +/*#__PURE__*/ +_createPartialApplicator( +/*#__PURE__*/ +flip(_concat)); /** * Takes a predicate and a list or other `Filterable` object and returns the @@ -7033,13 +8409,16 @@ var partialRight = /*#__PURE__*/_createPartialApplicator( /*#__PURE__*/flip(_con * @see R.filter, R.reject * @example * - * R.partition(R.contains('s'), ['sss', 'ttt', 'foo', 'bars']); + * R.partition(R.includes('s'), ['sss', 'ttt', 'foo', 'bars']); * // => [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ] * - * R.partition(R.contains('s'), { a: 'sss', b: 'ttt', foo: 'bars' }); + * R.partition(R.includes('s'), { a: 'sss', b: 'ttt', foo: 'bars' }); * // => [ { a: 'sss', foo: 'bars' }, { b: 'ttt' } ] */ -var partition = /*#__PURE__*/juxt([filter, reject]); + +var partition = +/*#__PURE__*/ +juxt([filter, reject]); /** * Determines whether a nested path on an object has a specific value, in @@ -7058,14 +8437,17 @@ var partition = /*#__PURE__*/juxt([filter, reject]); * `false` otherwise. * @example * - * var user1 = { address: { zipCode: 90210 } }; - * var user2 = { address: { zipCode: 55555 } }; - * var user3 = { name: 'Bob' }; - * var users = [ user1, user2, user3 ]; - * var isFamous = R.pathEq(['address', 'zipCode'], 90210); + * const user1 = { address: { zipCode: 90210 } }; + * const user2 = { address: { zipCode: 55555 } }; + * const user3 = { name: 'Bob' }; + * const users = [ user1, user2, user3 ]; + * const isFamous = R.pathEq(['address', 'zipCode'], 90210); * R.filter(isFamous, users); //=> [ user1 ] */ -var pathEq = /*#__PURE__*/_curry3(function pathEq(_path, val, obj) { + +var pathEq = +/*#__PURE__*/ +_curry3(function pathEq(_path, val, obj) { return equals(path(_path, obj), val); }); @@ -7088,7 +8470,10 @@ var pathEq = /*#__PURE__*/_curry3(function pathEq(_path, val, obj) { * R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2 * R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A" */ -var pathOr = /*#__PURE__*/_curry3(function pathOr(d, p, obj) { + +var pathOr = +/*#__PURE__*/ +_curry3(function pathOr(d, p, obj) { return defaultTo(d, path(p, obj)); }); @@ -7110,9 +8495,13 @@ var pathOr = /*#__PURE__*/_curry3(function pathOr(d, p, obj) { * @example * * R.pathSatisfies(y => y > 0, ['x', 'y'], {x: {y: 2}}); //=> true + * R.pathSatisfies(R.is(Object), [], {x: {y: 2}}); //=> true */ -var pathSatisfies = /*#__PURE__*/_curry3(function pathSatisfies(pred, propPath, obj) { - return propPath.length > 0 && pred(path(propPath, obj)); + +var pathSatisfies = +/*#__PURE__*/ +_curry3(function pathSatisfies(pred, propPath, obj) { + return pred(path(propPath, obj)); }); /** @@ -7133,15 +8522,21 @@ var pathSatisfies = /*#__PURE__*/_curry3(function pathSatisfies(pred, propPath, * 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 = /*#__PURE__*/_curry2(function pick(names, obj) { + +var pick = +/*#__PURE__*/ +_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; }); @@ -7163,15 +8558,20 @@ var pick = /*#__PURE__*/_curry2(function pick(names, obj) { * 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 = /*#__PURE__*/_curry2(function pickAll(names, obj) { + +var pickAll = +/*#__PURE__*/ +_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; }); @@ -7192,16 +8592,21 @@ var pickAll = /*#__PURE__*/_curry2(function pickAll(names, obj) { * @see R.pick, R.filter * @example * - * var isUpperCase = (val, key) => key.toUpperCase() === key; + * const isUpperCase = (val, key) => key.toUpperCase() === key; * R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4} */ -var pickBy = /*#__PURE__*/_curry2(function pickBy(test, obj) { + +var pickBy = +/*#__PURE__*/ +_curry2(function pickBy(test, obj) { var result = {}; + for (var prop in obj) { if (test(obj[prop], prop, obj)) { result[prop] = obj[prop]; } } + return result; }); @@ -7219,13 +8624,14 @@ var pickBy = /*#__PURE__*/_curry2(function pickBy(test, obj) { * @param {...Function} * @return {Function} * @see R.composeK + * @deprecated since v0.26.0 * @example * * // parseJson :: String -> Maybe * * // get :: String -> Object -> Maybe * * * // getStateCode :: Maybe String -> Maybe String - * var getStateCode = R.pipeK( + * const getStateCode = R.pipeK( * parseJson, * get('user'), * get('address'), @@ -7239,10 +8645,12 @@ var pickBy = /*#__PURE__*/_curry2(function pickBy(test, obj) { * //=> Nothing() * @symb R.pipeK(f, g, h)(a) = R.chain(h, R.chain(g, f(a))) */ + function pipeK() { if (arguments.length === 0) { throw new Error('pipeK requires at least one argument'); } + return composeK.apply(this, reverse(arguments)); } @@ -7263,7 +8671,10 @@ function pipeK() { * * R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum'] */ -var prepend = /*#__PURE__*/_curry2(function prepend(el, list) { + +var prepend = +/*#__PURE__*/ +_curry2(function prepend(el, list) { return _concat([el], list); }); @@ -7282,7 +8693,10 @@ var prepend = /*#__PURE__*/_curry2(function prepend(el, list) { * * R.product([2,4,6,8,100,1]); //=> 38400 */ -var product = /*#__PURE__*/reduce(multiply, 1); + +var product = +/*#__PURE__*/ +reduce(multiply, 1); /** * Accepts a function `fn` and a list of transformer functions and returns a @@ -7313,14 +8727,19 @@ var product = /*#__PURE__*/reduce(multiply, 1); * 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 = /*#__PURE__*/_curry2(function useWith(fn, transformers) { + +var useWith = +/*#__PURE__*/ +_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))); }); }); @@ -7339,17 +8758,20 @@ var useWith = /*#__PURE__*/_curry2(function useWith(fn, transformers) { * @return {Array} An array of objects with just the `props` properties. * @example * - * var abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2}; - * var fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7}; - * var kids = [abby, fred]; + * const abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2}; + * const fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7}; + * const kids = [abby, fred]; * R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}] */ -var project = /*#__PURE__*/useWith(_map, [pickAll, identity]); // passing `identity` gives correct arity + +var project = +/*#__PURE__*/ +useWith(_map, [pickAll, identity]); // passing `identity` gives correct arity /** * Returns `true` if the specified object property is equal, in * [`R.equals`](#equals) terms, to the given value; `false` otherwise. - * You can test multiple properties with [`R.where`](#where). + * You can test multiple properties with [`R.whereEq`](#whereEq). * * @func * @memberOf R @@ -7363,15 +8785,18 @@ var project = /*#__PURE__*/useWith(_map, [pickAll, identity]); // passing `ident * @see R.whereEq, R.propSatisfies, R.equals * @example * - * var abby = {name: 'Abby', age: 7, hair: 'blond'}; - * var fred = {name: 'Fred', age: 12, hair: 'brown'}; - * var rusty = {name: 'Rusty', age: 10, hair: 'brown'}; - * var alois = {name: 'Alois', age: 15, disposition: 'surly'}; - * var kids = [abby, fred, rusty, alois]; - * var hasBrownHair = R.propEq('hair', 'brown'); + * const abby = {name: 'Abby', age: 7, hair: 'blond'}; + * const fred = {name: 'Fred', age: 12, hair: 'brown'}; + * const rusty = {name: 'Rusty', age: 10, hair: 'brown'}; + * const alois = {name: 'Alois', age: 15, disposition: 'surly'}; + * const kids = [abby, fred, rusty, alois]; + * const hasBrownHair = R.propEq('hair', 'brown'); * R.filter(hasBrownHair, kids); //=> [fred, rusty] */ -var propEq = /*#__PURE__*/_curry3(function propEq(name, val, obj) { + +var propEq = +/*#__PURE__*/ +_curry3(function propEq(name, val, obj) { return equals(val, obj[name]); }); @@ -7395,7 +8820,10 @@ var propEq = /*#__PURE__*/_curry3(function propEq(name, val, obj) { * R.propIs(Number, 'x', {x: 'foo'}); //=> false * R.propIs(Number, 'x', {}); //=> false */ -var propIs = /*#__PURE__*/_curry3(function propIs(type, name, obj) { + +var propIs = +/*#__PURE__*/ +_curry3(function propIs(type, name, obj) { return is(type, obj[name]); }); @@ -7415,18 +8843,21 @@ var propIs = /*#__PURE__*/_curry3(function propIs(type, name, obj) { * @return {*} The value of given property of the supplied object or the default value. * @example * - * var alice = { + * const alice = { * name: 'ALICE', * age: 101 * }; - * var favorite = R.prop('favoriteLibrary'); - * var favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary'); + * const favorite = R.prop('favoriteLibrary'); + * const favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary'); * * favorite(alice); //=> undefined * favoriteWithDefault(alice); //=> 'Ramda' */ -var propOr = /*#__PURE__*/_curry3(function propOr(val, p, obj) { - return obj != null && _has(p, obj) ? obj[p] : val; + +var propOr = +/*#__PURE__*/ +_curry3(function propOr(val, p, obj) { + return pathOr(val, [p], obj); }); /** @@ -7448,7 +8879,10 @@ var propOr = /*#__PURE__*/_curry3(function propOr(val, p, obj) { * * R.propSatisfies(x => x > 0, 'x', {x: 1, y: 2}); //=> true */ -var propSatisfies = /*#__PURE__*/_curry3(function propSatisfies(pred, name, obj) { + +var propSatisfies = +/*#__PURE__*/ +_curry3(function propSatisfies(pred, name, obj) { return pred(obj[name]); }); @@ -7469,20 +8903,16 @@ var propSatisfies = /*#__PURE__*/_curry3(function propSatisfies(pred, name, obj) * R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2] * R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2] * - * var fullName = R.compose(R.join(' '), R.props(['first', 'last'])); + * const fullName = R.compose(R.join(' '), R.props(['first', 'last'])); * fullName({last: 'Bullet-Tooth', age: 33, first: 'Tony'}); //=> 'Tony Bullet-Tooth' */ -var props = /*#__PURE__*/_curry2(function props(ps, obj) { - var len = ps.length; - var out = []; - var idx = 0; - - while (idx < len) { - out[idx] = obj[ps[idx]]; - idx += 1; - } - return out; +var props = +/*#__PURE__*/ +_curry2(function props(ps, obj) { + return ps.map(function (p) { + return path([p], obj); + }); }); /** @@ -7495,22 +8925,28 @@ var props = /*#__PURE__*/_curry2(function props(ps, obj) { * @sig Number -> Number -> [Number] * @param {Number} from The first number in the list. * @param {Number} to One more than the last number in the list. - * @return {Array} The list of numbers in tthe set `[a, b)`. + * @return {Array} The list of numbers in the set `[a, b)`. * @example * * R.range(1, 5); //=> [1, 2, 3, 4] * R.range(50, 53); //=> [50, 51, 52] */ -var range = /*#__PURE__*/_curry2(function range(from, to) { + +var range = +/*#__PURE__*/ +_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; } + return result; }); @@ -7556,12 +8992,17 @@ var range = /*#__PURE__*/_curry2(function range(from, to) { * * @symb R.reduceRight(f, a, [b, c, d]) = f(b, f(c, f(d, a))) */ -var reduceRight = /*#__PURE__*/_curry3(function reduceRight(fn, acc, list) { + +var reduceRight = +/*#__PURE__*/ +_curry3(function reduceRight(fn, acc, list) { var idx = list.length - 1; + while (idx >= 0) { acc = fn(list[idx], acc); idx -= 1; } + return acc; }); @@ -7587,14 +9028,17 @@ var reduceRight = /*#__PURE__*/_curry3(function reduceRight(fn, acc, list) { * @see R.reduce, R.reduced * @example * - * var isOdd = (acc, x) => x % 2 === 1; - * var xs = [1, 3, 5, 60, 777, 800]; + * const isOdd = (acc, x) => x % 2 === 1; + * const xs = [1, 3, 5, 60, 777, 800]; * R.reduceWhile(isOdd, R.add, 0, xs); //=> 9 * - * var ys = [2, 4, 6] + * const ys = [2, 4, 6] * R.reduceWhile(isOdd, R.add, 111, ys); //=> 111 */ -var reduceWhile = /*#__PURE__*/_curryN(4, [], function _reduceWhile(pred, fn, a, list) { + +var reduceWhile = +/*#__PURE__*/ +_curryN(4, [], function _reduceWhile(pred, fn, a, list) { return _reduce(function (acc, x) { return pred(acc, x) ? fn(acc, x) : _reduced(acc); }, a, list); @@ -7605,9 +9049,10 @@ var reduceWhile = /*#__PURE__*/_curryN(4, [], function _reduceWhile(pred, fn, a, * and transduce functions. The returned value should be considered a black * box: the internal structure is not guaranteed to be stable. * - * Note: this optimization is unavailable to functions not explicitly listed - * above. For instance, it is not currently supported by - * [`reduceRight`](#reduceRight). + * Note: this optimization is only available to the below functions: + * - [`reduce`](#reduce) + * - [`reduceWhile`](#reduceWhile) + * - [`transduce`](#transduce) * * @func * @memberOf R @@ -7616,7 +9061,7 @@ var reduceWhile = /*#__PURE__*/_curryN(4, [], function _reduceWhile(pred, fn, a, * @sig a -> * * @param {*} x The final value of the reduce. * @return {*} The wrapped value. - * @see R.reduce, R.transduce + * @see R.reduce, R.reduceWhile, R.transduce * @example * * R.reduce( @@ -7624,7 +9069,10 @@ var reduceWhile = /*#__PURE__*/_curryN(4, [], function _reduceWhile(pred, fn, a, * [], * [1, 2, 3, 4, 5]) // [1, 2, 3] */ -var reduced = /*#__PURE__*/_curry1(_reduced); + +var reduced = +/*#__PURE__*/ +_curry1(_reduced); /** * Calls an input function `n` times, returning an array containing the results @@ -7649,7 +9097,10 @@ var reduced = /*#__PURE__*/_curry1(_reduced); * @symb R.times(f, 1) = [f(0)] * @symb R.times(f, 2) = [f(0), f(1)] */ -var times = /*#__PURE__*/_curry2(function times(fn, n) { + +var times = +/*#__PURE__*/ +_curry2(function times(fn, n) { var len = Number(n); var idx = 0; var list; @@ -7657,11 +9108,14 @@ var times = /*#__PURE__*/_curry2(function times(fn, n) { if (len < 0 || isNaN(len)) { throw new RangeError('n must be a non-negative number'); } + list = new Array(len); + while (idx < len) { list[idx] = fn(idx); idx += 1; } + return list; }); @@ -7681,20 +9135,27 @@ var times = /*#__PURE__*/_curry2(function times(fn, n) { * * R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi'] * - * var obj = {}; - * var repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}] + * const obj = {}; + * const repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}] * repeatedObjs[0] === repeatedObjs[1]; //=> true * @symb R.repeat(a, 0) = [] * @symb R.repeat(a, 1) = [a] * @symb R.repeat(a, 2) = [a, a] */ -var repeat = /*#__PURE__*/_curry2(function repeat(value, n) { + +var repeat = +/*#__PURE__*/ +_curry2(function repeat(value, n) { return times(always(value), n); }); /** * Replace a substring or regex match in a string with a replacement. * + * The first two parameters correspond to the parameters of the + * `String.prototype.replace()` function, so the second parameter can also be a + * function. + * * @func * @memberOf R * @since v0.7.0 @@ -7712,7 +9173,10 @@ var repeat = /*#__PURE__*/_curry2(function repeat(value, n) { * // Use the "g" (global) flag to replace all occurrences: * R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar' */ -var replace = /*#__PURE__*/_curry3(function replace(regex, replacement, str) { + +var replace = +/*#__PURE__*/ +_curry3(function replace(regex, replacement, str) { return str.replace(regex, replacement); }); @@ -7730,22 +9194,27 @@ var replace = /*#__PURE__*/_curry3(function replace(regex, replacement, str) { * @param {*} acc The accumulator value. * @param {Array} list The list to iterate over. * @return {Array} A list of all intermediately reduced values. - * @see R.reduce + * @see R.reduce, R.mapAccum * @example * - * var numbers = [1, 2, 3, 4]; - * var factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24] + * const numbers = [1, 2, 3, 4]; + * 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 = /*#__PURE__*/_curry3(function scan(fn, acc, list) { + +var scan = +/*#__PURE__*/ +_curry3(function scan(fn, acc, list) { var idx = 0; var len = list.length; var result = [acc]; + while (idx < len) { acc = fn(acc, list[idx]); result[idx + 1] = acc; idx += 1; } + return result; }); @@ -7773,7 +9242,10 @@ var scan = /*#__PURE__*/_curry3(function scan(fn, acc, list) { * R.sequence(R.of, Just([1, 2, 3])); //=> [Just(1), Just(2), Just(3)] * R.sequence(R.of, Nothing()); //=> [Nothing()] */ -var sequence = /*#__PURE__*/_curry2(function sequence(of, traversable) { + +var sequence = +/*#__PURE__*/ +_curry2(function sequence(of, traversable) { return typeof traversable.sequence === 'function' ? traversable.sequence(of) : reduceRight(function (x, acc) { return ap(map(prepend, x), acc); }, of([]), traversable); @@ -7796,12 +9268,15 @@ var sequence = /*#__PURE__*/_curry2(function sequence(of, traversable) { * @see R.prop, R.lensIndex, R.lensProp * @example * - * var xLens = R.lensProp('x'); + * const xLens = R.lensProp('x'); * * 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 = /*#__PURE__*/_curry3(function set(lens, v, x) { + +var set = +/*#__PURE__*/ +_curry3(function set(lens, v, x) { return over(lens, always(v), x); }); @@ -7822,10 +9297,13 @@ var set = /*#__PURE__*/_curry3(function set(lens, v, x) { * @return {Array} a new array with its elements sorted by the comparator function. * @example * - * var diff = function(a, b) { return a - b; }; + * const diff = function(a, b) { return a - b; }; * R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7] */ -var sort = /*#__PURE__*/_curry2(function sort(comparator, list) { + +var sort = +/*#__PURE__*/ +_curry2(function sort(comparator, list) { return Array.prototype.slice.call(list, 0).sort(comparator); }); @@ -7842,26 +9320,30 @@ var sort = /*#__PURE__*/_curry2(function sort(comparator, list) { * @return {Array} A new list sorted by the keys generated by `fn`. * @example * - * var sortByFirstItem = R.sortBy(R.prop(0)); - * var sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop('name'))); - * var pairs = [[-1, 1], [-2, 2], [-3, 3]]; + * const sortByFirstItem = R.sortBy(R.prop(0)); + * const pairs = [[-1, 1], [-2, 2], [-3, 3]]; * sortByFirstItem(pairs); //=> [[-3, 3], [-2, 2], [-1, 1]] - * var alice = { + * + * const sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop('name'))); + * const alice = { * name: 'ALICE', * age: 101 * }; - * var bob = { + * const bob = { * name: 'Bob', * age: -10 * }; - * var clara = { + * const clara = { * name: 'clara', * age: 314.159 * }; - * var people = [clara, bob, alice]; + * const people = [clara, bob, alice]; * sortByNameCaseInsensitive(people); //=> [alice, bob, clara] */ -var sortBy = /*#__PURE__*/_curry2(function sortBy(fn, list) { + +var sortBy = +/*#__PURE__*/ +_curry2(function sortBy(fn, list) { return Array.prototype.slice.call(list, 0).sort(function (a, b) { var aa = fn(a); var bb = fn(b); @@ -7882,33 +9364,38 @@ var sortBy = /*#__PURE__*/_curry2(function sortBy(fn, list) { * @return {Array} A new list sorted according to the comarator functions. * @example * - * var alice = { + * const alice = { * name: 'alice', * age: 40 * }; - * var bob = { + * const bob = { * name: 'bob', * age: 30 * }; - * var clara = { + * const clara = { * name: 'clara', * age: 40 * }; - * var people = [clara, bob, alice]; - * var ageNameSort = R.sortWith([ + * const people = [clara, bob, alice]; + * const ageNameSort = R.sortWith([ * R.descend(R.prop('age')), * R.ascend(R.prop('name')) * ]); * ageNameSort(people); //=> [alice, clara, bob] */ -var sortWith = /*#__PURE__*/_curry2(function sortWith(fns, list) { + +var sortWith = +/*#__PURE__*/ +_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; }); }); @@ -7924,16 +9411,19 @@ var sortWith = /*#__PURE__*/_curry2(function sortWith(fns, list) { * @sig (String | RegExp) -> String -> [String] * @param {String|RegExp} sep The pattern. * @param {String} str The string to separate into an array. - * @return {Array} The array of strings from `str` separated by `str`. + * @return {Array} The array of strings from `str` separated by `sep`. * @see R.join * @example * - * var pathComponents = R.split('/'); + * const pathComponents = R.split('/'); * R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node'] * * R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd'] */ -var split = /*#__PURE__*/invoker(1, 'split'); + +var split = +/*#__PURE__*/ +invoker(1, 'split'); /** * Splits a given list or string at a given index. @@ -7953,7 +9443,10 @@ var split = /*#__PURE__*/invoker(1, 'split'); * R.splitAt(5, 'hello world'); //=> ['hello', ' world'] * R.splitAt(-1, 'foobar'); //=> ['fooba', 'r'] */ -var splitAt = /*#__PURE__*/_curry2(function splitAt(index, array) { + +var splitAt = +/*#__PURE__*/ +_curry2(function splitAt(index, array) { return [slice(0, index, array), slice(index, length(array), array)]; }); @@ -7974,15 +9467,21 @@ var splitAt = /*#__PURE__*/_curry2(function splitAt(index, array) { * 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 = /*#__PURE__*/_curry2(function splitEvery(n, list) { + +var splitEvery = +/*#__PURE__*/ +_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; }); @@ -8005,7 +9504,10 @@ var splitEvery = /*#__PURE__*/_curry2(function splitEvery(n, list) { * * R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]] */ -var splitWhen = /*#__PURE__*/_curry2(function splitWhen(pred, list) { + +var splitWhen = +/*#__PURE__*/ +_curry2(function splitWhen(pred, list) { var idx = 0; var len = list.length; var prefix = []; @@ -8019,17 +9521,20 @@ var splitWhen = /*#__PURE__*/_curry2(function splitWhen(pred, list) { }); /** - * Checks if a list starts with the provided values + * Checks if a list starts with the provided sublist. + * + * Similarly, checks if a string starts with the provided substring. * * @func * @memberOf R * @since v0.24.0 * @category List - * @sig [a] -> Boolean - * @sig String -> Boolean + * @sig [a] -> [a] -> Boolean + * @sig String -> String -> Boolean * @param {*} prefix * @param {*} list * @return {Boolean} + * @see R.endsWith * @example * * R.startsWith('a', 'abc') //=> true @@ -8037,7 +9542,10 @@ var splitWhen = /*#__PURE__*/_curry2(function splitWhen(pred, list) { * R.startsWith(['a'], ['a', 'b', 'c']) //=> true * R.startsWith(['b'], ['a', 'b', 'c']) //=> false */ -var startsWith = /*#__PURE__*/_curry2(function (prefix, list) { + +var startsWith = +/*#__PURE__*/ +_curry2(function (prefix, list) { return equals(take(prefix.length, list), prefix); }); @@ -8057,14 +9565,17 @@ var startsWith = /*#__PURE__*/_curry2(function (prefix, list) { * * R.subtract(10, 8); //=> 2 * - * var minus5 = R.subtract(R.__, 5); + * const minus5 = R.subtract(R.__, 5); * minus5(17); //=> 12 * - * var complementaryAngle = R.subtract(90); + * const complementaryAngle = R.subtract(90); * complementaryAngle(30); //=> 60 * complementaryAngle(72); //=> 18 */ -var subtract = /*#__PURE__*/_curry2(function subtract(a, b) { + +var subtract = +/*#__PURE__*/ +_curry2(function subtract(a, b) { return Number(a) - Number(b); }); @@ -8086,7 +9597,10 @@ var subtract = /*#__PURE__*/_curry2(function subtract(a, b) { * 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 = /*#__PURE__*/_curry2(function symmetricDifference(list1, list2) { + +var symmetricDifference = +/*#__PURE__*/ +_curry2(function symmetricDifference(list1, list2) { return concat(difference(list1, list2), difference(list2, list1)); }); @@ -8107,12 +9621,15 @@ var symmetricDifference = /*#__PURE__*/_curry2(function symmetricDifference(list * @see R.symmetricDifference, R.difference, R.differenceWith * @example * - * var eqA = R.eqBy(R.prop('a')); - * var l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}]; - * var l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}]; + * const eqA = R.eqBy(R.prop('a')); + * const l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}]; + * 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 = /*#__PURE__*/_curry3(function symmetricDifferenceWith(pred, list1, list2) { + +var symmetricDifferenceWith = +/*#__PURE__*/ +_curry3(function symmetricDifferenceWith(pred, list1, list2) { return concat(differenceWith(pred, list1, list2), differenceWith(pred, list2, list1)); }); @@ -8135,27 +9652,36 @@ var symmetricDifferenceWith = /*#__PURE__*/_curry3(function symmetricDifferenceW * @see R.dropLastWhile, R.addIndex * @example * - * var isNotOne = x => x !== 1; + * const isNotOne = x => x !== 1; * * R.takeLastWhile(isNotOne, [1, 2, 3, 4]); //=> [2, 3, 4] * * R.takeLastWhile(x => x !== 'R' , 'Ramda'); //=> 'amda' */ -var takeLastWhile = /*#__PURE__*/_curry2(function takeLastWhile(fn, xs) { + +var takeLastWhile = +/*#__PURE__*/ +_curry2(function takeLastWhile(fn, xs) { var idx = xs.length - 1; + while (idx >= 0 && fn(xs[idx])) { idx -= 1; } + return slice(idx + 1, Infinity, xs); }); -var XTakeWhile = /*#__PURE__*/function () { +var XTakeWhile = +/*#__PURE__*/ +function () { function XTakeWhile(f, xf) { 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); }; @@ -8163,7 +9689,9 @@ var XTakeWhile = /*#__PURE__*/function () { return XTakeWhile; }(); -var _xtakeWhile = /*#__PURE__*/_curry2(function _xtakeWhile(f, xf) { +var _xtakeWhile = +/*#__PURE__*/ +_curry2(function _xtakeWhile(f, xf) { return new XTakeWhile(f, xf); }); @@ -8190,28 +9718,39 @@ var _xtakeWhile = /*#__PURE__*/_curry2(function _xtakeWhile(f, xf) { * @see R.dropWhile, R.transduce, R.addIndex * @example * - * var isNotFour = x => x !== 4; + * const isNotFour = x => x !== 4; * * R.takeWhile(isNotFour, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3] * * R.takeWhile(x => x !== 'd' , 'Ramda'); //=> 'Ram' */ -var takeWhile = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable(['takeWhile'], _xtakeWhile, function takeWhile(fn, xs) { + +var takeWhile = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_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); })); -var XTap = /*#__PURE__*/function () { +var XTap = +/*#__PURE__*/ +function () { function XTap(f, xf) { 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); @@ -8220,7 +9759,9 @@ var XTap = /*#__PURE__*/function () { return XTap; }(); -var _xtap = /*#__PURE__*/_curry2(function _xtap(f, xf) { +var _xtap = +/*#__PURE__*/ +_curry2(function _xtap(f, xf) { return new XTap(f, xf); }); @@ -8239,12 +9780,17 @@ var _xtap = /*#__PURE__*/_curry2(function _xtap(f, xf) { * @return {*} `x`. * @example * - * var sayX = x => console.log('x is ' + x); + * const sayX = x => console.log('x is ' + x); * R.tap(sayX, 100); //=> 100 * // logs 'x is 100' * @symb R.tap(f, a) = a */ -var tap = /*#__PURE__*/_curry2( /*#__PURE__*/_dispatchable([], _xtap, function tap(fn, x) { + +var tap = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +_dispatchable([], _xtap, function tap(fn, x) { fn(x); return x; })); @@ -8270,13 +9816,52 @@ function _isRegExp(x) { * R.test(/^x/, 'xyz'); //=> true * R.test(/^y/, 'xyz'); //=> false */ -var test = /*#__PURE__*/_curry2(function test(pattern, str) { + +var test = +/*#__PURE__*/ +_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); }); +/** + * Returns the result of applying the onSuccess function to the value inside + * a successfully resolved promise. This is useful for working with promises + * inside function compositions. + * + * @func + * @memberOf R + * @since v0.27.1 + * @category Function + * @sig (a -> b) -> (Promise e a) -> (Promise e b) + * @sig (a -> (Promise e b)) -> (Promise e a) -> (Promise e b) + * @param {Function} onSuccess The function to apply. Can return a value or a promise of a value. + * @param {Promise} p + * @return {Promise} The result of calling `p.then(onSuccess)` + * @see R.otherwise + * @example + * + * var makeQuery = (email) => ({ query: { email }}); + * + * //getMemberName :: String -> Promise ({firstName, lastName}) + * var getMemberName = R.pipe( + * makeQuery, + * fetchMember, + * R.andThen(R.pick(['firstName', 'lastName'])) + * ); + */ + +var andThen = +/*#__PURE__*/ +_curry2(function andThen(f, p) { + _assertPromise('andThen', p); + + return p.then(f); +}); + /** * The lower case version of a string. * @@ -8292,7 +9877,10 @@ var test = /*#__PURE__*/_curry2(function test(pattern, str) { * * R.toLower('XYZ'); //=> 'xyz' */ -var toLower = /*#__PURE__*/invoker(0, 'toLowerCase'); + +var toLower = +/*#__PURE__*/ +invoker(0, 'toLowerCase'); /** * Converts an object into an array of key, value arrays. Only the object's @@ -8312,13 +9900,18 @@ var toLower = /*#__PURE__*/invoker(0, 'toLowerCase'); * * R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]] */ -var toPairs = /*#__PURE__*/_curry1(function toPairs(obj) { + +var toPairs = +/*#__PURE__*/ +_curry1(function toPairs(obj) { var pairs = []; + for (var prop in obj) { if (_has(prop, obj)) { pairs[pairs.length] = [prop, obj[prop]]; } } + return pairs; }); @@ -8338,16 +9931,21 @@ var toPairs = /*#__PURE__*/_curry1(function toPairs(obj) { * and prototype properties. * @example * - * var F = function() { this.x = 'X'; }; + * const F = function() { this.x = 'X'; }; * F.prototype.y = 'Y'; - * var f = new F(); + * const f = new F(); * R.toPairsIn(f); //=> [['x','X'], ['y','Y']] */ -var toPairsIn = /*#__PURE__*/_curry1(function toPairsIn(obj) { + +var toPairsIn = +/*#__PURE__*/ +_curry1(function toPairsIn(obj) { var pairs = []; + for (var prop in obj) { pairs[pairs.length] = [prop, obj[prop]]; } + return pairs; }); @@ -8366,7 +9964,10 @@ var toPairsIn = /*#__PURE__*/_curry1(function toPairsIn(obj) { * * R.toUpper('abc'); //=> 'ABC' */ -var toUpper = /*#__PURE__*/invoker(0, 'toUpperCase'); + +var toUpper = +/*#__PURE__*/ +invoker(0, 'toUpperCase'); /** * Initializes a transducer using supplied iterator function. Returns a single @@ -8407,15 +10008,18 @@ var toUpper = /*#__PURE__*/invoker(0, 'toUpperCase'); * @see R.reduce, R.reduced, R.into * @example * - * var numbers = [1, 2, 3, 4]; - * var transducer = R.compose(R.map(R.add(1)), R.take(2)); + * const numbers = [1, 2, 3, 4]; + * const transducer = R.compose(R.map(R.add(1)), R.take(2)); * R.transduce(transducer, R.flip(R.append), [], numbers); //=> [2, 3] * - * var isOdd = (x) => x % 2 === 1; - * var firstOddTransducer = R.compose(R.filter(isOdd), R.take(1)); + * const isOdd = (x) => x % 2 === 1; + * const firstOddTransducer = R.compose(R.filter(isOdd), R.take(1)); * R.transduce(firstOddTransducer, R.flip(R.append), [], R.range(0, 100)); //=> [1] */ -var transduce = /*#__PURE__*/curryN(4, function transduce(xf, fn, acc, list) { + +var transduce = +/*#__PURE__*/ +curryN(4, function transduce(xf, fn, acc, list) { return _reduce(xf(typeof fn === 'function' ? _xwrap(fn) : fn), acc, list); }); @@ -8443,21 +10047,29 @@ var transduce = /*#__PURE__*/curryN(4, function transduce(xf, fn, acc, list) { * @symb R.transpose([[a, b], [c, d]]) = [[a, c], [b, d]] * @symb R.transpose([[a, b], [c]]) = [[a, c], [b]] */ -var transpose = /*#__PURE__*/_curry1(function transpose(outerlist) { + +var transpose = +/*#__PURE__*/ +_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; }); @@ -8481,13 +10093,16 @@ var transpose = /*#__PURE__*/_curry1(function transpose(outerlist) { * @see R.sequence * @example * - * // Returns `Nothing` if the given divisor is `0` - * safeDiv = n => d => d === 0 ? Nothing() : Just(n / d) + * // Returns `Maybe.Nothing` if the given divisor is `0` + * const safeDiv = n => d => d === 0 ? Maybe.Nothing() : Maybe.Just(n / d) * - * R.traverse(Maybe.of, safeDiv(10), [2, 4, 5]); //=> Just([5, 2.5, 2]) - * R.traverse(Maybe.of, safeDiv(10), [2, 0, 5]); //=> Nothing + * R.traverse(Maybe.of, safeDiv(10), [2, 4, 5]); //=> Maybe.Just([5, 2.5, 2]) + * R.traverse(Maybe.of, safeDiv(10), [2, 0, 5]); //=> Maybe.Nothing */ -var traverse = /*#__PURE__*/_curry3(function traverse(of, f, traversable) { + +var traverse = +/*#__PURE__*/ +_curry3(function traverse(of, f, traversable) { return typeof traversable['fantasy-land/traverse'] === 'function' ? traversable['fantasy-land/traverse'](f, of) : sequence(of, map(f, traversable)); }); @@ -8509,14 +10124,22 @@ var hasProtoTrim = typeof String.prototype.trim === 'function'; * R.trim(' xyz '); //=> 'xyz' * R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z'] */ -var _trim = !hasProtoTrim || /*#__PURE__*/ws.trim() || ! /*#__PURE__*/zeroWidth.trim() ? function trim(str) { + +var trim = !hasProtoTrim || +/*#__PURE__*/ +ws.trim() || ! +/*#__PURE__*/ +zeroWidth.trim() ? +/*#__PURE__*/ +_curry1(function trim(str) { var beginRx = new RegExp('^[' + ws + '][' + ws + ']*'); var endRx = new RegExp('[' + ws + '][' + ws + ']*$'); return str.replace(beginRx, '').replace(endRx, ''); -} : function trim(str) { +}) : +/*#__PURE__*/ +_curry1(function trim(str) { return str.trim(); -}; -var trim = /*#__PURE__*/_curry1(_trim); +}); /** * `tryCatch` takes two functions, a `tryer` and a `catcher`. The returned @@ -8537,9 +10160,14 @@ var trim = /*#__PURE__*/_curry1(_trim); * @example * * R.tryCatch(R.prop('x'), R.F)({x: true}); //=> true - * R.tryCatch(R.prop('x'), R.F)(null); //=> false + * R.tryCatch(() => { throw 'foo'}, R.always('catched'))('bar') // => 'catched' + * 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 = /*#__PURE__*/_curry2(function _tryCatch(tryer, catcher) { + +var tryCatch = +/*#__PURE__*/ +_curry2(function _tryCatch(tryer, catcher) { return _arity(tryer.length, function () { try { return tryer.apply(this, arguments); @@ -8573,7 +10201,10 @@ var tryCatch = /*#__PURE__*/_curry2(function _tryCatch(tryer, catcher) { * R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]' * @symb R.unapply(f)(a, b) = f([a, b]) */ -var unapply = /*#__PURE__*/_curry1(function unapply(fn) { + +var unapply = +/*#__PURE__*/ +_curry1(function unapply(fn) { return function () { return fn(Array.prototype.slice.call(arguments, 0)); }; @@ -8595,19 +10226,22 @@ var unapply = /*#__PURE__*/_curry1(function unapply(fn) { * @see R.binary, R.nAry * @example * - * var takesTwoArgs = function(a, b) { + * const takesTwoArgs = function(a, b) { * return [a, b]; * }; * takesTwoArgs.length; //=> 2 * takesTwoArgs(1, 2); //=> [1, 2] * - * var takesOneArg = R.unary(takesTwoArgs); + * const takesOneArg = R.unary(takesTwoArgs); * takesOneArg.length; //=> 1 * // Only 1 argument is passed to the wrapped function * takesOneArg(1, 2); //=> [1, undefined] * @symb R.unary(f)(a, b, c) = f(a) */ -var unary = /*#__PURE__*/_curry1(function unary(fn) { + +var unary = +/*#__PURE__*/ +_curry1(function unary(fn) { return nAry(1, fn); }); @@ -8625,23 +10259,28 @@ var unary = /*#__PURE__*/_curry1(function unary(fn) { * @see R.curry * @example * - * var addFour = a => b => c => d => a + b + c + d; + * const addFour = a => b => c => d => a + b + c + d; * - * var uncurriedAddFour = R.uncurryN(4, addFour); + * const uncurriedAddFour = R.uncurryN(4, addFour); * uncurriedAddFour(1, 2, 3, 4); //=> 10 */ -var uncurryN = /*#__PURE__*/_curry2(function uncurryN(depth, fn) { + +var uncurryN = +/*#__PURE__*/ +_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; }); }); @@ -8667,17 +10306,22 @@ var uncurryN = /*#__PURE__*/_curry2(function uncurryN(depth, fn) { * @return {Array} The final list. * @example * - * var f = n => n > 50 ? false : [-n, n + 10]; + * const f = n => n > 50 ? false : [-n, n + 10]; * 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 = /*#__PURE__*/_curry2(function unfold(fn, seed) { + +var unfold = +/*#__PURE__*/ +_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; }); @@ -8698,7 +10342,12 @@ var unfold = /*#__PURE__*/_curry2(function unfold(fn, seed) { * * R.union([1, 2, 3], [2, 3, 4]); //=> [1, 2, 3, 4] */ -var union = /*#__PURE__*/_curry2( /*#__PURE__*/compose(uniq, _concat)); + +var union = +/*#__PURE__*/ +_curry2( +/*#__PURE__*/ +compose(uniq, _concat)); /** * Returns a new list containing only one copy of each element in the original @@ -8716,24 +10365,31 @@ var union = /*#__PURE__*/_curry2( /*#__PURE__*/compose(uniq, _concat)); * @return {Array} The list of unique items. * @example * - * var strEq = R.eqBy(String); + * const strEq = R.eqBy(String); * R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2] * R.uniqWith(strEq)([{}, {}]); //=> [{}] * R.uniqWith(strEq)([1, '1', 1]); //=> [1] * R.uniqWith(strEq)(['1', 1, 1]); //=> ['1'] */ -var uniqWith = /*#__PURE__*/_curry2(function uniqWith(pred, list) { + +var uniqWith = +/*#__PURE__*/ +_curry2(function uniqWith(pred, list) { var idx = 0; var len = list.length; var result = []; var item; + while (idx < len) { item = list[idx]; - if (!_containsWith(pred, item, result)) { + + if (!_includesWith(pred, item, result)) { result[result.length] = item; } + idx += 1; } + return result; }); @@ -8755,11 +10411,14 @@ var uniqWith = /*#__PURE__*/_curry2(function uniqWith(pred, list) { * @see R.union * @example * - * var l1 = [{a: 1}, {a: 2}]; - * var l2 = [{a: 1}, {a: 4}]; + * const l1 = [{a: 1}, {a: 2}]; + * const l2 = [{a: 1}, {a: 4}]; * R.unionWith(R.eqBy(R.prop('a')), l1, l2); //=> [{a: 1}, {a: 2}, {a: 4}] */ -var unionWith = /*#__PURE__*/_curry3(function unionWith(pred, list1, list2) { + +var unionWith = +/*#__PURE__*/ +_curry3(function unionWith(pred, list1, list2) { return uniqWith(pred, _concat(list1, list2)); }); @@ -8780,14 +10439,17 @@ var unionWith = /*#__PURE__*/_curry3(function unionWith(pred, list1, list2) { * @param {*} x An object to test with the `pred` function and * pass to `whenFalseFn` if necessary. * @return {*} Either `x` or the result of applying `x` to `whenFalseFn`. - * @see R.ifElse, R.when + * @see R.ifElse, R.when, R.cond * @example * * let safeInc = R.unless(R.isNil, R.inc); * safeInc(null); //=> null * safeInc(1); //=> 2 */ -var unless = /*#__PURE__*/_curry3(function unless(pred, whenFalseFn, x) { + +var unless = +/*#__PURE__*/ +_curry3(function unless(pred, whenFalseFn, x) { return pred(x) ? x : whenFalseFn(x); }); @@ -8808,7 +10470,10 @@ var unless = /*#__PURE__*/_curry3(function unless(pred, whenFalseFn, x) { * R.unnest([1, [2], [[3]]]); //=> [1, 2, [3]] * R.unnest([[1, 2], [3, 4], [5, 6]]); //=> [1, 2, 3, 4, 5, 6] */ -var unnest = /*#__PURE__*/chain(_identity); + +var unnest = +/*#__PURE__*/ +chain(_identity); /** * Takes a predicate, a transformation function, and an initial value, @@ -8829,11 +10494,16 @@ var unnest = /*#__PURE__*/chain(_identity); * * R.until(R.gt(R.__, 100), R.multiply(2))(1) // => 128 */ -var until = /*#__PURE__*/_curry3(function until(pred, fn, init) { + +var until = +/*#__PURE__*/ +_curry3(function until(pred, fn, init) { var val = init; + while (!pred(val)) { val = fn(val); } + return val; }); @@ -8853,27 +10523,33 @@ var until = /*#__PURE__*/_curry3(function until(pred, fn, init) { * @see R.values, R.keysIn * @example * - * var F = function() { this.x = 'X'; }; + * const F = function() { this.x = 'X'; }; * F.prototype.y = 'Y'; - * var f = new F(); + * const f = new F(); * R.valuesIn(f); //=> ['X', 'Y'] */ -var valuesIn = /*#__PURE__*/_curry1(function valuesIn(obj) { + +var valuesIn = +/*#__PURE__*/ +_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 (x) { - return { value: x, 'fantasy-land/map': function () { + return { + value: x, + 'fantasy-land/map': function () { return this; - } }; + } + }; }; - /** * 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. @@ -8890,12 +10566,16 @@ var Const = function (x) { * @see R.prop, R.lensIndex, R.lensProp * @example * - * var 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 */ -var view = /*#__PURE__*/_curry2(function view(lens, x) { + + +var view = +/*#__PURE__*/ +_curry2(function view(lens, x) { // Using `Const` effectively ignores the setter function of the `lens`, // leaving the value returned by the getter function unmodified. return lens(Const)(x).value; @@ -8918,18 +10598,21 @@ var view = /*#__PURE__*/_curry2(function view(lens, x) { * @param {*} x An object to test with the `pred` function and * pass to `whenTrueFn` if necessary. * @return {*} Either `x` or the result of applying `x` to `whenTrueFn`. - * @see R.ifElse, R.unless + * @see R.ifElse, R.unless, R.cond * @example * * // truncate :: String -> String - * var truncate = R.when( + * const truncate = R.when( * R.propSatisfies(R.gt(R.__, 10), 'length'), * R.pipe(R.take(10), R.append('…'), R.join('')) * ); * truncate('12345'); //=> '12345' * truncate('0123456789ABC'); //=> '0123456789…' */ -var when = /*#__PURE__*/_curry3(function when(pred, whenTrueFn, x) { + +var when = +/*#__PURE__*/ +_curry3(function when(pred, whenTrueFn, x) { return pred(x) ? whenTrueFn(x) : x; }); @@ -8955,7 +10638,7 @@ var when = /*#__PURE__*/_curry3(function when(pred, whenTrueFn, x) { * @example * * // pred :: Object -> Boolean - * var pred = R.where({ + * const pred = R.where({ * a: R.equals('foo'), * b: R.complement(R.equals('bar')), * x: R.gt(R.__, 10), @@ -8968,12 +10651,16 @@ var when = /*#__PURE__*/_curry3(function when(pred, whenTrueFn, x) { * pred({a: 'foo', b: 'xxx', x: 10, y: 19}); //=> false * pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> false */ -var where = /*#__PURE__*/_curry2(function where(spec, testObj) { + +var where = +/*#__PURE__*/ +_curry2(function where(spec, testObj) { for (var prop in spec) { if (_has(prop, spec) && !spec[prop](testObj[prop])) { return false; } } + return true; }); @@ -8998,14 +10685,17 @@ var where = /*#__PURE__*/_curry2(function where(spec, testObj) { * @example * * // pred :: Object -> Boolean - * var pred = R.whereEq({a: 1, b: 2}); + * const pred = R.whereEq({a: 1, b: 2}); * * pred({a: 1}); //=> false * pred({a: 1, b: 2}); //=> true * pred({a: 1, b: 2, c: 3}); //=> true * pred({a: 1, b: 1}); //=> false */ -var whereEq = /*#__PURE__*/_curry2(function whereEq(spec, testObj) { + +var whereEq = +/*#__PURE__*/ +_curry2(function whereEq(spec, testObj) { return where(map(equals, spec), testObj); }); @@ -9023,13 +10713,44 @@ var whereEq = /*#__PURE__*/_curry2(function whereEq(spec, testObj) { * @param {Array} list1 The values to be removed from `list2`. * @param {Array} list2 The array to remove values from. * @return {Array} The new array without values in `list1`. - * @see R.transduce, R.difference + * @see R.transduce, R.difference, R.remove * @example * * R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4] */ -var without = /*#__PURE__*/_curry2(function (xs, list) { - return reject(flip(_contains)(xs), list); + +var without = +/*#__PURE__*/ +_curry2(function (xs, list) { + return reject(flip(_includes)(xs), list); +}); + +/** + * Exclusive disjunction logical operation. + * Returns `true` if one of the arguments is truthy and the other is falsy. + * Otherwise, it returns `false`. + * + * @func + * @memberOf R + * @since v0.27.1 + * @category Logic + * @sig a -> b -> Boolean + * @param {Any} a + * @param {Any} b + * @return {Boolean} true if one of the arguments is truthy and the other is falsy + * @see R.or, R.and + * @example + * + * R.xor(true, true); //=> false + * R.xor(true, false); //=> true + * R.xor(false, true); //=> true + * R.xor(false, false); //=> false + */ + +var xor = +/*#__PURE__*/ +_curry2(function xor(a, b) { + return Boolean(!a ^ !b); }); /** @@ -9050,21 +10771,28 @@ var without = /*#__PURE__*/_curry2(function (xs, list) { * 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 = /*#__PURE__*/_curry2(function xprod(a, b) { + +var xprod = +/*#__PURE__*/ +_curry2(function xprod(a, b) { // = xprodWith(prepend); (takes about 3 times as long...) var idx = 0; var ilen = a.length; var j; var jlen = b.length; var result = []; + while (idx < ilen) { j = 0; + while (j < jlen) { result[result.length] = [a[idx], b[j]]; j += 1; } + idx += 1; } + return result; }); @@ -9087,14 +10815,19 @@ var xprod = /*#__PURE__*/_curry2(function xprod(a, b) { * 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 = /*#__PURE__*/_curry2(function zip(a, b) { + +var zip = +/*#__PURE__*/ +_curry2(function zip(a, b) { var rv = []; var idx = 0; var len = Math.min(a.length, b.length); + while (idx < len) { rv[idx] = [a[idx], b[idx]]; idx += 1; } + return rv; }); @@ -9115,14 +10848,19 @@ var zip = /*#__PURE__*/_curry2(function zip(a, b) { * * R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3} */ -var zipObj = /*#__PURE__*/_curry2(function zipObj(keys, values) { + +var zipObj = +/*#__PURE__*/ +_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; }); @@ -9143,24 +10881,59 @@ var zipObj = /*#__PURE__*/_curry2(function zipObj(keys, values) { * using `fn`. * @example * - * var f = (x, y) => { + * const f = (x, y) => { * // ... * }; * R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']); * //=> [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 = /*#__PURE__*/_curry3(function zipWith(fn, a, b) { + +var zipWith = +/*#__PURE__*/ +_curry3(function zipWith(fn, a, b) { var rv = []; var idx = 0; var len = Math.min(a.length, b.length); + while (idx < len) { rv[idx] = fn(a[idx], b[idx]); idx += 1; } + return rv; }); +/** + * Creates a thunk out of a function. A thunk delays a calculation until + * its result is needed, providing lazy evaluation of arguments. + * + * @func + * @memberOf R + * @since v0.26.0 + * @category Function + * @sig ((a, b, ..., j) -> k) -> (a, b, ..., j) -> (() -> k) + * @param {Function} fn A function to wrap in a thunk + * @return {Function} Expects arguments for `fn` and returns a new function + * that, when called, applies those arguments to `fn`. + * @see R.partial, R.partialRight + * @example + * + * R.thunkify(R.identity)(42)(); //=> 42 + * R.thunkify((a, b) => a + b)(25, 17)(); //=> 42 + */ + +var thunkify = +/*#__PURE__*/ +_curry1(function thunkify(fn) { + return curryN(fn.length, function createThunk() { + var fnArgs = arguments; + return function invokeThunk() { + return fn.apply(this, fnArgs); + }; + }); +}); + var es = Object.freeze({ @@ -9197,6 +10970,7 @@ var es = Object.freeze({ compose: compose, composeK: composeK, composeP: composeP, + composeWith: composeWith, concat: concat, cond: cond, construct: construct, @@ -9243,11 +11017,13 @@ var es = Object.freeze({ gte: gte, has: has, hasIn: hasIn, + hasPath: hasPath, head: head, identical: identical, identity: identity, ifElse: ifElse, inc: inc, + includes: includes, indexBy: indexBy, indexOf: indexOf, init: init, @@ -9288,7 +11064,6 @@ var es = Object.freeze({ maxBy: maxBy, mean: mean, median: median, - memoize: memoize, memoizeWith: memoizeWith, merge: merge, mergeAll: mergeAll, @@ -9296,11 +11071,14 @@ var es = Object.freeze({ mergeDeepRight: mergeDeepRight, mergeDeepWith: mergeDeepWith, mergeDeepWithKey: mergeDeepWithKey, + mergeLeft: mergeLeft, + mergeRight: mergeRight, mergeWith: mergeWith, mergeWithKey: mergeWithKey, min: min, minBy: minBy, modulo: modulo, + move: move, multiply: multiply, nAry: nAry, negate: negate, @@ -9314,12 +11092,14 @@ var es = Object.freeze({ omit: omit, once: once, or: or, + otherwise: otherwise, over: over, pair: pair, partial: partial, partialRight: partialRight, partition: partition, path: path, + paths: paths, pathEq: pathEq, pathOr: pathOr, pathSatisfies: pathSatisfies, @@ -9329,6 +11109,7 @@ var es = Object.freeze({ pipe: pipe, pipeK: pipeK, pipeP: pipeP, + pipeWith: pipeWith, pluck: pluck, prepend: prepend, product: product, @@ -9373,6 +11154,7 @@ var es = Object.freeze({ takeWhile: takeWhile, tap: tap, test: test, + andThen: andThen, times: times, toLower: toLower, toPairs: toPairs, @@ -9406,211 +11188,54 @@ var es = Object.freeze({ where: where, whereEq: whereEq, without: without, + xor: xor, xprod: xprod, zip: zip, zipObj: zipObj, - zipWith: zipWith + zipWith: zipWith, + thunkify: thunkify }); -function _arity$1(n, fn) { - /* eslint-disable no-unused-vars */ - switch (n) { - case 0: - return function () { - return fn.apply(this, arguments); - }; - case 1: - return function (a0) { - return fn.apply(this, arguments); - }; - case 2: - return function (a0, a1) { - return fn.apply(this, arguments); - }; - case 3: - return function (a0, a1, a2) { - return fn.apply(this, arguments); - }; - case 4: - return function (a0, a1, a2, a3) { - return fn.apply(this, arguments); - }; - case 5: - return function (a0, a1, a2, a3, a4) { - return fn.apply(this, arguments); - }; - case 6: - return function (a0, a1, a2, a3, a4, a5) { - return fn.apply(this, arguments); - }; - case 7: - return function (a0, a1, a2, a3, a4, a5, a6) { - return fn.apply(this, arguments); - }; - case 8: - return function (a0, a1, a2, a3, a4, a5, a6, a7) { - return fn.apply(this, arguments); - }; - case 9: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { - return fn.apply(this, arguments); - }; - case 10: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { - return fn.apply(this, arguments); - }; - default: - throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); - } -} -var _arity_1 = _arity$1; - -function _isPlaceholder$1(a) { - return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; -} -var _isPlaceholder_1 = _isPlaceholder$1; - -/** - * Optimized internal one-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curry1$1(fn) { - return function f1(a) { - if (arguments.length === 0 || _isPlaceholder_1(a)) { - return f1; - } else { - return fn.apply(this, arguments); +// Utility +var slice$2 = Array.prototype.slice; +var concat$2 = Array.prototype.concat; + +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } + +/** + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. + */ +function curryN$2(n, func) { + return function() { + var curargs = slice$2.call(arguments); + + if (curargs.length >= n) { + return func.apply(null, curargs); } - }; -} -var _curry1_1 = _curry1$1; - -/** - * Optimized internal two-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - -function _curry2$1(fn) { - return function f2(a, b) { - switch (arguments.length) { - case 0: - return f2; - case 1: - return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { - return fn(a, _b); - }); - default: - return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { - return fn(_a, b); - }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { - return fn(a, _b); - }) : fn(a, b); - } - }; + return curryN$2(n - curargs.length, function() { + return func.apply(null, concat$2.call(curargs, slice$2.call(arguments))); + }); + } } -var _curry2_1 = _curry2$1; - -/** - * Internal curryN function. - * - * @private - * @category Function - * @param {Number} length The arity of the curried function. - * @param {Array} received An array of arguments received thus far. - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - -function _curryN$1(length, received, fn) { - return function () { - var combined = []; - var argsIdx = 0; - var left = length; - var combinedIdx = 0; - while (combinedIdx < received.length || argsIdx < arguments.length) { - var result; - if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { - result = received[combinedIdx]; - } else { - result = arguments[argsIdx]; - argsIdx += 1; - } - combined[combinedIdx] = result; - if (!_isPlaceholder_1(result)) { - left -= 1; - } - combinedIdx += 1; - } - return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN$1(length, combined, fn)); - }; +function curry$2(func) { + return curryN$2(func.length, func); } -var _curryN_1 = _curryN$1; - -/** - * Returns a curried equivalent of the provided function, with the specified - * arity. The curried function has two unusual capabilities. First, its - * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the - * following are equivalent: - * - * - `g(1)(2)(3)` - * - `g(1)(2, 3)` - * - `g(1, 2)(3)` - * - `g(1, 2, 3)` - * - * Secondly, the special placeholder value [`R.__`](#__) may be used to specify - * "gaps", allowing partial application of any combination of arguments, - * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), - * the following are equivalent: - * - * - `g(1, 2, 3)` - * - `g(_, 2, 3)(1)` - * - `g(_, _, 3)(1)(2)` - * - `g(_, _, 3)(1, 2)` - * - `g(_, 2)(1)(3)` - * - `g(_, 2)(1, 3)` - * - `g(_, 2)(_, 3)(1)` - * - * @func - * @memberOf R - * @since v0.5.0 - * @category Function - * @sig Number -> (* -> a) -> (* -> a) - * @param {Number} length The arity for the returned function. - * @param {Function} fn The function to curry. - * @return {Function} A new, curried function. - * @see R.curry - * @example - * - * var sumArgs = (...args) => R.sum(args); - * - * var curriedAddFourNumbers = R.curryN(4, sumArgs); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); - * g(4); //=> 10 - */ - - -var curryN$1 = /*#__PURE__*/_curry2_1(function curryN(length, fn) { - if (length === 1) { - return _curry1_1(fn); - } - return _arity_1(length, _curryN_1(length, [], fn)); -}); -var curryN_1 = curryN$1; -// Utility function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -9677,7 +11302,7 @@ flyd.stream['fantasy-land/of'] = flyd.stream.of = flyd.stream; * return n1() > n2() ? n1() : n2(); * }, [n1, n2]); */ -flyd.combine = curryN_1(2, combine); +flyd.combine = curryN$2(2, combine); function combine(fn, streams) { var i, s, deps, depEndStreams; var endStream = createDependentStream([], trueFn); @@ -9794,10 +11419,10 @@ flyd.endsOn = function(endS, s) { * var squaredNumbers = flyd.map(function(n) { return n*n; }, numbers); */ // Library functions use self callback to accept (null, undefined) update triggers. -function map$1(f, s) { +function map$2(f, s) { return combine(function(s, self) { self(f(s.val)); }, [s]); } -flyd.map = curryN_1(2, map$1); +flyd.map = curryN$2(2, map$2); /** * Chain a stream @@ -9820,7 +11445,7 @@ flyd.map = curryN_1(2, map$1); * return flyd.stream(findUsers(filter)); * }, filter); */ -flyd.chain = curryN_1(2, chain$1); +flyd.chain = curryN$2(2, chain$2); /** * Apply a stream @@ -9846,7 +11471,7 @@ flyd.chain = curryN_1(2, chain$1); * .pipe(ap(n2)); * added_pipe() // 3 */ -flyd.ap = curryN_1(2, ap$1); +flyd.ap = curryN$2(2, ap$2); /** * Listen to stream events @@ -9862,7 +11487,7 @@ flyd.ap = curryN_1(2, ap$1); * @param {stream} stream - the stream * @return {stream} an empty stream (can be ended) */ -flyd.on = curryN_1(2, function(f, s) { +flyd.on = curryN$2(2, function(f, s) { return combine(function(s) { f(s.val); }, [s]); }); @@ -9884,7 +11509,7 @@ flyd.on = curryN_1(2, function(f, s) { * numbers(2)(3)(5); * sum(); // 10 */ -flyd.scan = curryN_1(3, function(f, acc, s) { +flyd.scan = curryN$2(3, function(f, acc, s) { var ns = combine(function(s, self) { self(acc = f(acc, s.val)); }, [s]); @@ -9910,7 +11535,7 @@ flyd.scan = curryN_1(3, function(f, acc, s) { * button2Elm.addEventListener(btn2Clicks); * var allClicks = flyd.merge(btn1Clicks, btn2Clicks); */ -flyd.merge = curryN_1(2, function(s1, s2) { +flyd.merge = curryN$2(2, function(s1, s2) { var s = flyd.immediate(combine(function(s1, s2, self, changed) { if (changed[0]) { self(changed[0]()); @@ -9947,7 +11572,7 @@ flyd.merge = curryN_1(2, function(s1, s2) { * s1(1)(1)(2)(3)(3)(3)(4); * results; // => [2, 4, 6, 8] */ -flyd.transduce = curryN_1(2, function(xform, source) { +flyd.transduce = curryN$2(2, function(xform, source) { xform = xform(new StreamTransformer()); return combine(function(source, self) { var res = xform['@@transducer/step'](undefined, source.val); @@ -9975,7 +11600,8 @@ flyd.transduce = curryN_1(2, function(xform, source) { * var a = flyd.curryN(2, add); * a(2)(4) // => 6 */ -flyd.curryN = curryN_1; +flyd.curryN = curryN$2; +flyd.curry = curry$2; /** * Returns a new stream identical to the original except every @@ -9994,7 +11620,7 @@ flyd.curryN = curryN_1; * var numbers = flyd.stream(0); * var squaredNumbers = numbers.map(function(n) { return n*n; }); */ -function boundMap(f) { return map$1(f, this); } +function boundMap(f) { return map$2(f, this); } /** * Returns the result of applying function `fn` to this stream @@ -10012,10 +11638,10 @@ function boundMap(f) { return map$1(f, this); } function operator_pipe(f) { return f(this) } function boundChain(f) { - return chain$1(f, this); + return chain$2(f, this); } -function chain$1(f, s) { +function chain$2(f, s) { // Internal state to end flat map stream var flatEnd = flyd.stream(1); var internalEnded = flyd.on(function() { @@ -10036,7 +11662,7 @@ function chain$1(f, s) { internalEnded(newS.end); // Update self on call -- newS is never handed out so deps don't matter - last = map$1(own, newS); + last = map$2(own, newS); }, [s]); flyd.endsOn(flatEnd.end, flatStream); @@ -10082,19 +11708,19 @@ flyd.flattenPromise = function flattenPromise(s) { * var addToNumbers1 = flyd.map(add, numbers1); * var added = addToNumbers1.ap(numbers2); */ -function ap$1(s2, s1) { +function ap$2(s2, s1) { return combine(function(s1, s2, self) { self(s1.val(s2.val)); }, [s1, s2]); } function boundAp(s2) { - return ap$1(s2, this); + return ap$2(s2, this); } /** * @private */ function fantasy_land_ap(s1) { - return ap$1(this, s1); + return ap$2(this, s1); } /** diff --git a/examples/secret-combination/build.js b/examples/secret-combination/build.js index b359640..7398dfd 100644 --- a/examples/secret-combination/build.js +++ b/examples/secret-combination/build.js @@ -1,205 +1,46 @@ var secretcombination = (function () { 'use strict'; -function _arity(n, fn) { - /* eslint-disable no-unused-vars */ - switch (n) { - case 0: - return function () { - return fn.apply(this, arguments); - }; - case 1: - return function (a0) { - return fn.apply(this, arguments); - }; - case 2: - return function (a0, a1) { - return fn.apply(this, arguments); - }; - case 3: - return function (a0, a1, a2) { - return fn.apply(this, arguments); - }; - case 4: - return function (a0, a1, a2, a3) { - return fn.apply(this, arguments); - }; - case 5: - return function (a0, a1, a2, a3, a4) { - return fn.apply(this, arguments); - }; - case 6: - return function (a0, a1, a2, a3, a4, a5) { - return fn.apply(this, arguments); - }; - case 7: - return function (a0, a1, a2, a3, a4, a5, a6) { - return fn.apply(this, arguments); - }; - case 8: - return function (a0, a1, a2, a3, a4, a5, a6, a7) { - return fn.apply(this, arguments); - }; - case 9: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { - return fn.apply(this, arguments); - }; - case 10: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { - return fn.apply(this, arguments); - }; - default: - throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); - } -} -var _arity_1 = _arity; - -function _isPlaceholder(a) { - return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; -} -var _isPlaceholder_1 = _isPlaceholder; - -/** - * Optimized internal one-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curry1(fn) { - return function f1(a) { - if (arguments.length === 0 || _isPlaceholder_1(a)) { - return f1; - } else { - return fn.apply(this, arguments); +// Utility +var slice = Array.prototype.slice; +var concat = Array.prototype.concat; + +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } + +/** + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. + */ +function curryN(n, func) { + return function() { + var curargs = slice.call(arguments); + + if (curargs.length >= n) { + return func.apply(null, curargs); } - }; -} -var _curry1_1 = _curry1; - -/** - * Optimized internal two-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - -function _curry2(fn) { - return function f2(a, b) { - switch (arguments.length) { - case 0: - return f2; - case 1: - return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { - return fn(a, _b); - }); - default: - return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { - return fn(_a, b); - }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { - return fn(a, _b); - }) : fn(a, b); - } - }; + return curryN(n - curargs.length, function() { + return func.apply(null, concat.call(curargs, slice.call(arguments))); + }); + } } -var _curry2_1 = _curry2; -/** - * Internal curryN function. - * - * @private - * @category Function - * @param {Number} length The arity of the curried function. - * @param {Array} received An array of arguments received thus far. - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curryN(length, received, fn) { - return function () { - var combined = []; - var argsIdx = 0; - var left = length; - var combinedIdx = 0; - while (combinedIdx < received.length || argsIdx < arguments.length) { - var result; - if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { - result = received[combinedIdx]; - } else { - result = arguments[argsIdx]; - argsIdx += 1; - } - combined[combinedIdx] = result; - if (!_isPlaceholder_1(result)) { - left -= 1; - } - combinedIdx += 1; - } - return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); - }; +function curry(func) { + return curryN(func.length, func); } -var _curryN_1 = _curryN; - -/** - * Returns a curried equivalent of the provided function, with the specified - * arity. The curried function has two unusual capabilities. First, its - * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the - * following are equivalent: - * - * - `g(1)(2)(3)` - * - `g(1)(2, 3)` - * - `g(1, 2)(3)` - * - `g(1, 2, 3)` - * - * Secondly, the special placeholder value [`R.__`](#__) may be used to specify - * "gaps", allowing partial application of any combination of arguments, - * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), - * the following are equivalent: - * - * - `g(1, 2, 3)` - * - `g(_, 2, 3)(1)` - * - `g(_, _, 3)(1)(2)` - * - `g(_, _, 3)(1, 2)` - * - `g(_, 2)(1)(3)` - * - `g(_, 2)(1, 3)` - * - `g(_, 2)(_, 3)(1)` - * - * @func - * @memberOf R - * @since v0.5.0 - * @category Function - * @sig Number -> (* -> a) -> (* -> a) - * @param {Number} length The arity for the returned function. - * @param {Function} fn The function to curry. - * @return {Function} A new, curried function. - * @see R.curry - * @example - * - * var sumArgs = (...args) => R.sum(args); - * - * var curriedAddFourNumbers = R.curryN(4, sumArgs); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); - * g(4); //=> 10 - */ - - -var curryN = /*#__PURE__*/_curry2_1(function curryN(length, fn) { - if (length === 1) { - return _curry1_1(fn); - } - return _arity_1(length, _curryN_1(length, [], fn)); -}); -var curryN_1 = curryN; -// Utility function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -266,7 +107,7 @@ flyd.stream['fantasy-land/of'] = flyd.stream.of = flyd.stream; * return n1() > n2() ? n1() : n2(); * }, [n1, n2]); */ -flyd.combine = curryN_1(2, combine); +flyd.combine = curryN(2, combine); function combine(fn, streams) { var i, s, deps, depEndStreams; var endStream = createDependentStream([], trueFn); @@ -386,7 +227,7 @@ flyd.endsOn = function(endS, s) { function map(f, s) { return combine(function(s, self) { self(f(s.val)); }, [s]); } -flyd.map = curryN_1(2, map); +flyd.map = curryN(2, map); /** * Chain a stream @@ -409,7 +250,7 @@ flyd.map = curryN_1(2, map); * return flyd.stream(findUsers(filter)); * }, filter); */ -flyd.chain = curryN_1(2, chain); +flyd.chain = curryN(2, chain); /** * Apply a stream @@ -435,7 +276,7 @@ flyd.chain = curryN_1(2, chain); * .pipe(ap(n2)); * added_pipe() // 3 */ -flyd.ap = curryN_1(2, ap); +flyd.ap = curryN(2, ap); /** * Listen to stream events @@ -451,7 +292,7 @@ flyd.ap = curryN_1(2, ap); * @param {stream} stream - the stream * @return {stream} an empty stream (can be ended) */ -flyd.on = curryN_1(2, function(f, s) { +flyd.on = curryN(2, function(f, s) { return combine(function(s) { f(s.val); }, [s]); }); @@ -473,7 +314,7 @@ flyd.on = curryN_1(2, function(f, s) { * numbers(2)(3)(5); * sum(); // 10 */ -flyd.scan = curryN_1(3, function(f, acc, s) { +flyd.scan = curryN(3, function(f, acc, s) { var ns = combine(function(s, self) { self(acc = f(acc, s.val)); }, [s]); @@ -499,7 +340,7 @@ flyd.scan = curryN_1(3, function(f, acc, s) { * button2Elm.addEventListener(btn2Clicks); * var allClicks = flyd.merge(btn1Clicks, btn2Clicks); */ -flyd.merge = curryN_1(2, function(s1, s2) { +flyd.merge = curryN(2, function(s1, s2) { var s = flyd.immediate(combine(function(s1, s2, self, changed) { if (changed[0]) { self(changed[0]()); @@ -536,7 +377,7 @@ flyd.merge = curryN_1(2, function(s1, s2) { * s1(1)(1)(2)(3)(3)(3)(4); * results; // => [2, 4, 6, 8] */ -flyd.transduce = curryN_1(2, function(xform, source) { +flyd.transduce = curryN(2, function(xform, source) { xform = xform(new StreamTransformer()); return combine(function(source, self) { var res = xform['@@transducer/step'](undefined, source.val); @@ -564,7 +405,8 @@ flyd.transduce = curryN_1(2, function(xform, source) { * var a = flyd.curryN(2, add); * a(2)(4) // => 6 */ -flyd.curryN = curryN_1; +flyd.curryN = curryN; +flyd.curry = curry; /** * Returns a new stream identical to the original except every diff --git a/examples/sum/build.js b/examples/sum/build.js index 084b961..d8fd393 100644 --- a/examples/sum/build.js +++ b/examples/sum/build.js @@ -1,205 +1,46 @@ var sum = (function () { 'use strict'; -function _arity(n, fn) { - /* eslint-disable no-unused-vars */ - switch (n) { - case 0: - return function () { - return fn.apply(this, arguments); - }; - case 1: - return function (a0) { - return fn.apply(this, arguments); - }; - case 2: - return function (a0, a1) { - return fn.apply(this, arguments); - }; - case 3: - return function (a0, a1, a2) { - return fn.apply(this, arguments); - }; - case 4: - return function (a0, a1, a2, a3) { - return fn.apply(this, arguments); - }; - case 5: - return function (a0, a1, a2, a3, a4) { - return fn.apply(this, arguments); - }; - case 6: - return function (a0, a1, a2, a3, a4, a5) { - return fn.apply(this, arguments); - }; - case 7: - return function (a0, a1, a2, a3, a4, a5, a6) { - return fn.apply(this, arguments); - }; - case 8: - return function (a0, a1, a2, a3, a4, a5, a6, a7) { - return fn.apply(this, arguments); - }; - case 9: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { - return fn.apply(this, arguments); - }; - case 10: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { - return fn.apply(this, arguments); - }; - default: - throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); - } -} -var _arity_1 = _arity; - -function _isPlaceholder(a) { - return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; -} -var _isPlaceholder_1 = _isPlaceholder; - -/** - * Optimized internal one-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curry1(fn) { - return function f1(a) { - if (arguments.length === 0 || _isPlaceholder_1(a)) { - return f1; - } else { - return fn.apply(this, arguments); +// Utility +var slice = Array.prototype.slice; +var concat = Array.prototype.concat; + +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } + +/** + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. + */ +function curryN(n, func) { + return function() { + var curargs = slice.call(arguments); + + if (curargs.length >= n) { + return func.apply(null, curargs); } - }; -} -var _curry1_1 = _curry1; - -/** - * Optimized internal two-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - -function _curry2(fn) { - return function f2(a, b) { - switch (arguments.length) { - case 0: - return f2; - case 1: - return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { - return fn(a, _b); - }); - default: - return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { - return fn(_a, b); - }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { - return fn(a, _b); - }) : fn(a, b); - } - }; + return curryN(n - curargs.length, function() { + return func.apply(null, concat.call(curargs, slice.call(arguments))); + }); + } } -var _curry2_1 = _curry2; -/** - * Internal curryN function. - * - * @private - * @category Function - * @param {Number} length The arity of the curried function. - * @param {Array} received An array of arguments received thus far. - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curryN(length, received, fn) { - return function () { - var combined = []; - var argsIdx = 0; - var left = length; - var combinedIdx = 0; - while (combinedIdx < received.length || argsIdx < arguments.length) { - var result; - if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { - result = received[combinedIdx]; - } else { - result = arguments[argsIdx]; - argsIdx += 1; - } - combined[combinedIdx] = result; - if (!_isPlaceholder_1(result)) { - left -= 1; - } - combinedIdx += 1; - } - return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); - }; +function curry(func) { + return curryN(func.length, func); } -var _curryN_1 = _curryN; - -/** - * Returns a curried equivalent of the provided function, with the specified - * arity. The curried function has two unusual capabilities. First, its - * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the - * following are equivalent: - * - * - `g(1)(2)(3)` - * - `g(1)(2, 3)` - * - `g(1, 2)(3)` - * - `g(1, 2, 3)` - * - * Secondly, the special placeholder value [`R.__`](#__) may be used to specify - * "gaps", allowing partial application of any combination of arguments, - * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), - * the following are equivalent: - * - * - `g(1, 2, 3)` - * - `g(_, 2, 3)(1)` - * - `g(_, _, 3)(1)(2)` - * - `g(_, _, 3)(1, 2)` - * - `g(_, 2)(1)(3)` - * - `g(_, 2)(1, 3)` - * - `g(_, 2)(_, 3)(1)` - * - * @func - * @memberOf R - * @since v0.5.0 - * @category Function - * @sig Number -> (* -> a) -> (* -> a) - * @param {Number} length The arity for the returned function. - * @param {Function} fn The function to curry. - * @return {Function} A new, curried function. - * @see R.curry - * @example - * - * var sumArgs = (...args) => R.sum(args); - * - * var curriedAddFourNumbers = R.curryN(4, sumArgs); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); - * g(4); //=> 10 - */ - - -var curryN = /*#__PURE__*/_curry2_1(function curryN(length, fn) { - if (length === 1) { - return _curry1_1(fn); - } - return _arity_1(length, _curryN_1(length, [], fn)); -}); -var curryN_1 = curryN; -// Utility function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -266,7 +107,7 @@ flyd.stream['fantasy-land/of'] = flyd.stream.of = flyd.stream; * return n1() > n2() ? n1() : n2(); * }, [n1, n2]); */ -flyd.combine = curryN_1(2, combine); +flyd.combine = curryN(2, combine); function combine(fn, streams) { var i, s, deps, depEndStreams; var endStream = createDependentStream([], trueFn); @@ -386,7 +227,7 @@ flyd.endsOn = function(endS, s) { function map(f, s) { return combine(function(s, self) { self(f(s.val)); }, [s]); } -flyd.map = curryN_1(2, map); +flyd.map = curryN(2, map); /** * Chain a stream @@ -409,7 +250,7 @@ flyd.map = curryN_1(2, map); * return flyd.stream(findUsers(filter)); * }, filter); */ -flyd.chain = curryN_1(2, chain); +flyd.chain = curryN(2, chain); /** * Apply a stream @@ -435,7 +276,7 @@ flyd.chain = curryN_1(2, chain); * .pipe(ap(n2)); * added_pipe() // 3 */ -flyd.ap = curryN_1(2, ap); +flyd.ap = curryN(2, ap); /** * Listen to stream events @@ -451,7 +292,7 @@ flyd.ap = curryN_1(2, ap); * @param {stream} stream - the stream * @return {stream} an empty stream (can be ended) */ -flyd.on = curryN_1(2, function(f, s) { +flyd.on = curryN(2, function(f, s) { return combine(function(s) { f(s.val); }, [s]); }); @@ -473,7 +314,7 @@ flyd.on = curryN_1(2, function(f, s) { * numbers(2)(3)(5); * sum(); // 10 */ -flyd.scan = curryN_1(3, function(f, acc, s) { +flyd.scan = curryN(3, function(f, acc, s) { var ns = combine(function(s, self) { self(acc = f(acc, s.val)); }, [s]); @@ -499,7 +340,7 @@ flyd.scan = curryN_1(3, function(f, acc, s) { * button2Elm.addEventListener(btn2Clicks); * var allClicks = flyd.merge(btn1Clicks, btn2Clicks); */ -flyd.merge = curryN_1(2, function(s1, s2) { +flyd.merge = curryN(2, function(s1, s2) { var s = flyd.immediate(combine(function(s1, s2, self, changed) { if (changed[0]) { self(changed[0]()); @@ -536,7 +377,7 @@ flyd.merge = curryN_1(2, function(s1, s2) { * s1(1)(1)(2)(3)(3)(3)(4); * results; // => [2, 4, 6, 8] */ -flyd.transduce = curryN_1(2, function(xform, source) { +flyd.transduce = curryN(2, function(xform, source) { xform = xform(new StreamTransformer()); return combine(function(source, self) { var res = xform['@@transducer/step'](undefined, source.val); @@ -564,7 +405,8 @@ flyd.transduce = curryN_1(2, function(xform, source) { * var a = flyd.curryN(2, add); * a(2)(4) // => 6 */ -flyd.curryN = curryN_1; +flyd.curryN = curryN; +flyd.curry = curry; /** * Returns a new stream identical to the original except every diff --git a/examples/who-to-follow/build.js b/examples/who-to-follow/build.js index cbc1c54..96c8017 100644 --- a/examples/who-to-follow/build.js +++ b/examples/who-to-follow/build.js @@ -1,205 +1,46 @@ var whotofollow = (function () { 'use strict'; -function _arity(n, fn) { - /* eslint-disable no-unused-vars */ - switch (n) { - case 0: - return function () { - return fn.apply(this, arguments); - }; - case 1: - return function (a0) { - return fn.apply(this, arguments); - }; - case 2: - return function (a0, a1) { - return fn.apply(this, arguments); - }; - case 3: - return function (a0, a1, a2) { - return fn.apply(this, arguments); - }; - case 4: - return function (a0, a1, a2, a3) { - return fn.apply(this, arguments); - }; - case 5: - return function (a0, a1, a2, a3, a4) { - return fn.apply(this, arguments); - }; - case 6: - return function (a0, a1, a2, a3, a4, a5) { - return fn.apply(this, arguments); - }; - case 7: - return function (a0, a1, a2, a3, a4, a5, a6) { - return fn.apply(this, arguments); - }; - case 8: - return function (a0, a1, a2, a3, a4, a5, a6, a7) { - return fn.apply(this, arguments); - }; - case 9: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { - return fn.apply(this, arguments); - }; - case 10: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { - return fn.apply(this, arguments); - }; - default: - throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); - } -} -var _arity_1 = _arity; +// Utility +var slice = Array.prototype.slice; +var concat = Array.prototype.concat; -function _isPlaceholder(a) { - return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; -} -var _isPlaceholder_1 = _isPlaceholder; +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } /** - * Optimized internal one-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. */ +function curryN(n, func) { + return function() { + var curargs = slice.call(arguments); - -function _curry1(fn) { - return function f1(a) { - if (arguments.length === 0 || _isPlaceholder_1(a)) { - return f1; - } else { - return fn.apply(this, arguments); + if (curargs.length >= n) { + return func.apply(null, curargs); } - }; -} -var _curry1_1 = _curry1; - -/** - * Optimized internal two-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - -function _curry2(fn) { - return function f2(a, b) { - switch (arguments.length) { - case 0: - return f2; - case 1: - return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { - return fn(a, _b); - }); - default: - return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { - return fn(_a, b); - }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { - return fn(a, _b); - }) : fn(a, b); - } - }; + return curryN(n - curargs.length, function() { + return func.apply(null, concat.call(curargs, slice.call(arguments))); + }); + } } -var _curry2_1 = _curry2; - -/** - * Internal curryN function. - * - * @private - * @category Function - * @param {Number} length The arity of the curried function. - * @param {Array} received An array of arguments received thus far. - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - -function _curryN(length, received, fn) { - return function () { - var combined = []; - var argsIdx = 0; - var left = length; - var combinedIdx = 0; - while (combinedIdx < received.length || argsIdx < arguments.length) { - var result; - if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { - result = received[combinedIdx]; - } else { - result = arguments[argsIdx]; - argsIdx += 1; - } - combined[combinedIdx] = result; - if (!_isPlaceholder_1(result)) { - left -= 1; - } - combinedIdx += 1; - } - return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); - }; +function curry(func) { + return curryN(func.length, func); } -var _curryN_1 = _curryN; - -/** - * Returns a curried equivalent of the provided function, with the specified - * arity. The curried function has two unusual capabilities. First, its - * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the - * following are equivalent: - * - * - `g(1)(2)(3)` - * - `g(1)(2, 3)` - * - `g(1, 2)(3)` - * - `g(1, 2, 3)` - * - * Secondly, the special placeholder value [`R.__`](#__) may be used to specify - * "gaps", allowing partial application of any combination of arguments, - * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), - * the following are equivalent: - * - * - `g(1, 2, 3)` - * - `g(_, 2, 3)(1)` - * - `g(_, _, 3)(1)(2)` - * - `g(_, _, 3)(1, 2)` - * - `g(_, 2)(1)(3)` - * - `g(_, 2)(1, 3)` - * - `g(_, 2)(_, 3)(1)` - * - * @func - * @memberOf R - * @since v0.5.0 - * @category Function - * @sig Number -> (* -> a) -> (* -> a) - * @param {Number} length The arity for the returned function. - * @param {Function} fn The function to curry. - * @return {Function} A new, curried function. - * @see R.curry - * @example - * - * var sumArgs = (...args) => R.sum(args); - * - * var curriedAddFourNumbers = R.curryN(4, sumArgs); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); - * g(4); //=> 10 - */ - -var curryN = /*#__PURE__*/_curry2_1(function curryN(length, fn) { - if (length === 1) { - return _curry1_1(fn); - } - return _arity_1(length, _curryN_1(length, [], fn)); -}); -var curryN_1 = curryN; - -// Utility function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -266,7 +107,7 @@ flyd.stream['fantasy-land/of'] = flyd.stream.of = flyd.stream; * return n1() > n2() ? n1() : n2(); * }, [n1, n2]); */ -flyd.combine = curryN_1(2, combine); +flyd.combine = curryN(2, combine); function combine(fn, streams) { var i, s, deps, depEndStreams; var endStream = createDependentStream([], trueFn); @@ -386,7 +227,7 @@ flyd.endsOn = function(endS, s) { function map(f, s) { return combine(function(s, self) { self(f(s.val)); }, [s]); } -flyd.map = curryN_1(2, map); +flyd.map = curryN(2, map); /** * Chain a stream @@ -409,7 +250,7 @@ flyd.map = curryN_1(2, map); * return flyd.stream(findUsers(filter)); * }, filter); */ -flyd.chain = curryN_1(2, chain); +flyd.chain = curryN(2, chain); /** * Apply a stream @@ -435,7 +276,7 @@ flyd.chain = curryN_1(2, chain); * .pipe(ap(n2)); * added_pipe() // 3 */ -flyd.ap = curryN_1(2, ap); +flyd.ap = curryN(2, ap); /** * Listen to stream events @@ -451,7 +292,7 @@ flyd.ap = curryN_1(2, ap); * @param {stream} stream - the stream * @return {stream} an empty stream (can be ended) */ -flyd.on = curryN_1(2, function(f, s) { +flyd.on = curryN(2, function(f, s) { return combine(function(s) { f(s.val); }, [s]); }); @@ -473,7 +314,7 @@ flyd.on = curryN_1(2, function(f, s) { * numbers(2)(3)(5); * sum(); // 10 */ -flyd.scan = curryN_1(3, function(f, acc, s) { +flyd.scan = curryN(3, function(f, acc, s) { var ns = combine(function(s, self) { self(acc = f(acc, s.val)); }, [s]); @@ -499,7 +340,7 @@ flyd.scan = curryN_1(3, function(f, acc, s) { * button2Elm.addEventListener(btn2Clicks); * var allClicks = flyd.merge(btn1Clicks, btn2Clicks); */ -flyd.merge = curryN_1(2, function(s1, s2) { +flyd.merge = curryN(2, function(s1, s2) { var s = flyd.immediate(combine(function(s1, s2, self, changed) { if (changed[0]) { self(changed[0]()); @@ -536,7 +377,7 @@ flyd.merge = curryN_1(2, function(s1, s2) { * s1(1)(1)(2)(3)(3)(3)(4); * results; // => [2, 4, 6, 8] */ -flyd.transduce = curryN_1(2, function(xform, source) { +flyd.transduce = curryN(2, function(xform, source) { xform = xform(new StreamTransformer()); return combine(function(source, self) { var res = xform['@@transducer/step'](undefined, source.val); @@ -564,7 +405,8 @@ flyd.transduce = curryN_1(2, function(xform, source) { * var a = flyd.curryN(2, add); * a(2)(4) // => 6 */ -flyd.curryN = curryN_1; +flyd.curryN = curryN; +flyd.curry = curry; /** * Returns a new stream identical to the original except every diff --git a/flyd.js b/flyd.js index b876951..e83e315 100644 --- a/flyd.js +++ b/flyd.js @@ -4,205 +4,46 @@ (global.flyd = factory()); }(this, (function () { 'use strict'; -function _arity(n, fn) { - /* eslint-disable no-unused-vars */ - switch (n) { - case 0: - return function () { - return fn.apply(this, arguments); - }; - case 1: - return function (a0) { - return fn.apply(this, arguments); - }; - case 2: - return function (a0, a1) { - return fn.apply(this, arguments); - }; - case 3: - return function (a0, a1, a2) { - return fn.apply(this, arguments); - }; - case 4: - return function (a0, a1, a2, a3) { - return fn.apply(this, arguments); - }; - case 5: - return function (a0, a1, a2, a3, a4) { - return fn.apply(this, arguments); - }; - case 6: - return function (a0, a1, a2, a3, a4, a5) { - return fn.apply(this, arguments); - }; - case 7: - return function (a0, a1, a2, a3, a4, a5, a6) { - return fn.apply(this, arguments); - }; - case 8: - return function (a0, a1, a2, a3, a4, a5, a6, a7) { - return fn.apply(this, arguments); - }; - case 9: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { - return fn.apply(this, arguments); - }; - case 10: - return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { - return fn.apply(this, arguments); - }; - default: - throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); - } -} -var _arity_1 = _arity; - -function _isPlaceholder(a) { - return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; -} -var _isPlaceholder_1 = _isPlaceholder; - -/** - * Optimized internal one-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curry1(fn) { - return function f1(a) { - if (arguments.length === 0 || _isPlaceholder_1(a)) { - return f1; - } else { - return fn.apply(this, arguments); +// Utility +var slice = Array.prototype.slice; +var concat = Array.prototype.concat; + +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } + +/** + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. + */ +function curryN(n, func) { + return function() { + var curargs = slice.call(arguments); + + if (curargs.length >= n) { + return func.apply(null, curargs); } - }; -} -var _curry1_1 = _curry1; -/** - * Optimized internal two-arity curry function. - * - * @private - * @category Function - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curry2(fn) { - return function f2(a, b) { - switch (arguments.length) { - case 0: - return f2; - case 1: - return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { - return fn(a, _b); - }); - default: - return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { - return fn(_a, b); - }) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { - return fn(a, _b); - }) : fn(a, b); - } - }; + return curryN(n - curargs.length, function() { + return func.apply(null, concat.call(curargs, slice.call(arguments))); + }); + } } -var _curry2_1 = _curry2; -/** - * Internal curryN function. - * - * @private - * @category Function - * @param {Number} length The arity of the curried function. - * @param {Array} received An array of arguments received thus far. - * @param {Function} fn The function to curry. - * @return {Function} The curried function. - */ - - -function _curryN(length, received, fn) { - return function () { - var combined = []; - var argsIdx = 0; - var left = length; - var combinedIdx = 0; - while (combinedIdx < received.length || argsIdx < arguments.length) { - var result; - if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { - result = received[combinedIdx]; - } else { - result = arguments[argsIdx]; - argsIdx += 1; - } - combined[combinedIdx] = result; - if (!_isPlaceholder_1(result)) { - left -= 1; - } - combinedIdx += 1; - } - return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); - }; +function curry(func) { + return curryN(func.length, func); } -var _curryN_1 = _curryN; - -/** - * Returns a curried equivalent of the provided function, with the specified - * arity. The curried function has two unusual capabilities. First, its - * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the - * following are equivalent: - * - * - `g(1)(2)(3)` - * - `g(1)(2, 3)` - * - `g(1, 2)(3)` - * - `g(1, 2, 3)` - * - * Secondly, the special placeholder value [`R.__`](#__) may be used to specify - * "gaps", allowing partial application of any combination of arguments, - * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), - * the following are equivalent: - * - * - `g(1, 2, 3)` - * - `g(_, 2, 3)(1)` - * - `g(_, _, 3)(1)(2)` - * - `g(_, _, 3)(1, 2)` - * - `g(_, 2)(1)(3)` - * - `g(_, 2)(1, 3)` - * - `g(_, 2)(_, 3)(1)` - * - * @func - * @memberOf R - * @since v0.5.0 - * @category Function - * @sig Number -> (* -> a) -> (* -> a) - * @param {Number} length The arity for the returned function. - * @param {Function} fn The function to curry. - * @return {Function} A new, curried function. - * @see R.curry - * @example - * - * var sumArgs = (...args) => R.sum(args); - * - * var curriedAddFourNumbers = R.curryN(4, sumArgs); - * var f = curriedAddFourNumbers(1, 2); - * var g = f(3); - * g(4); //=> 10 - */ - -var curryN = /*#__PURE__*/_curry2_1(function curryN(length, fn) { - if (length === 1) { - return _curry1_1(fn); - } - return _arity_1(length, _curryN_1(length, [], fn)); -}); -var curryN_1 = curryN; - -// Utility function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -269,7 +110,7 @@ flyd.stream['fantasy-land/of'] = flyd.stream.of = flyd.stream; * return n1() > n2() ? n1() : n2(); * }, [n1, n2]); */ -flyd.combine = curryN_1(2, combine); +flyd.combine = curryN(2, combine); function combine(fn, streams) { var i, s, deps, depEndStreams; var endStream = createDependentStream([], trueFn); @@ -389,7 +230,7 @@ flyd.endsOn = function(endS, s) { function map(f, s) { return combine(function(s, self) { self(f(s.val)); }, [s]); } -flyd.map = curryN_1(2, map); +flyd.map = curryN(2, map); /** * Chain a stream @@ -412,7 +253,7 @@ flyd.map = curryN_1(2, map); * return flyd.stream(findUsers(filter)); * }, filter); */ -flyd.chain = curryN_1(2, chain); +flyd.chain = curryN(2, chain); /** * Apply a stream @@ -438,7 +279,7 @@ flyd.chain = curryN_1(2, chain); * .pipe(ap(n2)); * added_pipe() // 3 */ -flyd.ap = curryN_1(2, ap); +flyd.ap = curryN(2, ap); /** * Listen to stream events @@ -454,7 +295,7 @@ flyd.ap = curryN_1(2, ap); * @param {stream} stream - the stream * @return {stream} an empty stream (can be ended) */ -flyd.on = curryN_1(2, function(f, s) { +flyd.on = curryN(2, function(f, s) { return combine(function(s) { f(s.val); }, [s]); }); @@ -476,7 +317,7 @@ flyd.on = curryN_1(2, function(f, s) { * numbers(2)(3)(5); * sum(); // 10 */ -flyd.scan = curryN_1(3, function(f, acc, s) { +flyd.scan = curryN(3, function(f, acc, s) { var ns = combine(function(s, self) { self(acc = f(acc, s.val)); }, [s]); @@ -502,7 +343,7 @@ flyd.scan = curryN_1(3, function(f, acc, s) { * button2Elm.addEventListener(btn2Clicks); * var allClicks = flyd.merge(btn1Clicks, btn2Clicks); */ -flyd.merge = curryN_1(2, function(s1, s2) { +flyd.merge = curryN(2, function(s1, s2) { var s = flyd.immediate(combine(function(s1, s2, self, changed) { if (changed[0]) { self(changed[0]()); @@ -539,7 +380,7 @@ flyd.merge = curryN_1(2, function(s1, s2) { * s1(1)(1)(2)(3)(3)(3)(4); * results; // => [2, 4, 6, 8] */ -flyd.transduce = curryN_1(2, function(xform, source) { +flyd.transduce = curryN(2, function(xform, source) { xform = xform(new StreamTransformer()); return combine(function(source, self) { var res = xform['@@transducer/step'](undefined, source.val); @@ -567,7 +408,8 @@ flyd.transduce = curryN_1(2, function(xform, source) { * var a = flyd.curryN(2, add); * a(2)(4) // => 6 */ -flyd.curryN = curryN_1; +flyd.curryN = curryN; +flyd.curry = curry; /** * Returns a new stream identical to the original except every diff --git a/flyd.min.js b/flyd.min.js index ef7519b..84544ad 100644 --- a/flyd.min.js +++ b/flyd.min.js @@ -1 +1 @@ -!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.flyd=t()}(this,function(){"use strict";var n=function(n,t){switch(n){case 0:return function(){return t.apply(this,arguments)};case 1:return function(n){return t.apply(this,arguments)};case 2:return function(n,e){return t.apply(this,arguments)};case 3:return function(n,e,r){return t.apply(this,arguments)};case 4:return function(n,e,r,u){return t.apply(this,arguments)};case 5:return function(n,e,r,u,a){return t.apply(this,arguments)};case 6:return function(n,e,r,u,a,i){return t.apply(this,arguments)};case 7:return function(n,e,r,u,a,i,s){return t.apply(this,arguments)};case 8:return function(n,e,r,u,a,i,s,o){return t.apply(this,arguments)};case 9:return function(n,e,r,u,a,i,s,o,d){return t.apply(this,arguments)};case 10:return function(n,e,r,u,a,i,s,o,d,f){return t.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}};var t=function(n){return null!=n&&"object"==typeof n&&!0===n["@@functional/placeholder"]};var e=function(n){return function e(r){return 0===arguments.length||t(r)?e:n.apply(this,arguments)}};var r=function e(r,u,a){return function(){for(var i=[],s=0,o=r,d=0;d=arguments.length)?f=u[d]:(f=arguments[s],s+=1),i[d]=f,t(f)||(o-=1),d+=1}return o<=0?a.apply(this,i):n(o,e(r,i,a))}},u=function(n){return function r(u,a){switch(arguments.length){case 0:return r;case 1:return t(u)?r:e(function(t){return n(u,t)});default:return t(u)&&t(a)?r:t(u)?e(function(t){return n(t,a)}):t(a)?e(function(t){return n(u,t)}):n(u,a)}}}(function(t,u){return 1===t?e(u):n(t,r(t,[],u))});function a(){return!0}var i,s=[],o=[],d=-1,f=!1,c=!1;var p={};function l(n,t){var e,r,u,i,s=w([],a);for(u=[],i=[],e=0;e=0;--d)!0===(e=o[d]).shouldUpdate&&A(e),e.queued=!1}(e),s.length>0&&x(),c=!1):i===e?function(n,t){var e,r;for(e=0;e0?[]:void 0,e.shouldUpdate=!1,S(n,e),e}function A(n){var t;if((!(t=n).end||!0!==t.end.val)&&function(n){return!0===n.depsMet||function(n){return n.depsMet=n.deps.every(function(n){return n.hasVal}),n.depsMet}(n)}(n))if(void 0===i){i=n,n.depsChanged&&(n.fnArgs[n.fnArgs.length-1]=n.depsChanged);var e=n.fn.apply(n.fn,n.fnArgs);void 0!==e&&n(e),i=void 0,void 0!==n.depsChanged&&(n.depsChanged=[]),n.shouldUpdate=!1,!1===(f||c)&&x(),function(n){return n.listeners.some(function(n){return n.shouldUpdate})}(n)&&(c?n.listeners.forEach(function(n){n.shouldUpdate&&q(A,n)}):n(n.val))}else q(A,n)}function O(n){var t,e=n.listeners;if(!1===n.queued){for(n.queued=!0,t=0;t0;){var n=s.shift(),t=n.updaters.shift();t&&n.shouldUpdate&&t(n)}f=!1}function S(n,t){for(var e=0;e0&&e(n),e},p.stream["fantasy-land/of"]=p.stream.of=p.stream,p.combine=u(2,l),p.isStream=function(n){return!!((t=n)&&t.constructor&&t.call&&t.apply)&&"hasVal"in n;var t},p.immediate=function(n){return!1===n.depsMet&&(n.depsMet=!0,A(n)),n},p.endsOn=function(n,t){return E(t.end),n.listeners.push(t.end),t.end.deps.push(n),t},p.map=u(2,h),p.chain=u(2,m),p.ap=u(2,C),p.on=u(2,function(n,t){return l(function(t){n(t.val)},[t])}),p.scan=u(3,function(n,t,e){var r=l(function(e,r){r(t=n(t,e.val))},[e]);return r.hasVal||r(t),r}),p.merge=u(2,function(n,t){var e=p.immediate(l(function(n,t,e,r){r[0]?e(r[0]()):n.hasVal?e(n.val):t.hasVal&&e(t.val)},[n,t]));return p.endsOn(l(function(){return!0},[n.end,t.end]),e),e}),p.transduce=u(2,function(n,t){return n=n(new P),l(function(t,e){var r=n["@@transducer/step"](void 0,t.val);return r&&!0===r["@@transducer/reduced"]?(e.end(!0),r["@@transducer/value"]):r},[t])}),p.curryN=u,p.fromPromise=function(n){var t=p.stream();return n.then(function(n){t(n),t.end(!0)}),t},p.flattenPromise=function(n){return l(function(n,t){n().then(t)},[n])},P.prototype["@@transducer/init"]=function(){},P.prototype["@@transducer/result"]=function(){},P.prototype["@@transducer/step"]=function(n,t){return t},p}); +!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.flyd=e()}(this,function(){"use strict";var n=Array.prototype.slice,e=Array.prototype.concat;function t(r,u){return function(){var a=n.call(arguments);return a.length>=r?u.apply(null,a):t(r-a.length,function(){return u.apply(null,e.call(a,n.call(arguments)))})}}function r(){return!0}var u,a=[],o=[],s=-1,d=!1,i=!1;var f={};function c(n,e){var t,u,a,o,s=V([],r);for(a=[],o=[],t=0;t=0;--s)!0===(t=o[s]).shouldUpdate&&M(t),t.queued=!1}(t),a.length>0&&b(),i=!1):u===t?function(n,e){var t,r;for(t=0;t0?[]:void 0,t.shouldUpdate=!1,x(n,t),t}function M(n){var e;if((!(e=n).end||!0!==e.end.val)&&function(n){return!0===n.depsMet||function(n){return n.depsMet=n.deps.every(function(n){return n.hasVal}),n.depsMet}(n)}(n))if(void 0===u){u=n,n.depsChanged&&(n.fnArgs[n.fnArgs.length-1]=n.depsChanged);var t=n.fn.apply(n.fn,n.fnArgs);void 0!==t&&n(t),u=void 0,void 0!==n.depsChanged&&(n.depsChanged=[]),n.shouldUpdate=!1,!1===(d||i)&&b(),function(n){return n.listeners.some(function(n){return n.shouldUpdate})}(n)&&(i?n.listeners.forEach(function(n){n.shouldUpdate&&q(M,n)}):n(n.val))}else q(M,n)}function O(n){var e,t=n.listeners;if(!1===n.queued){for(n.queued=!0,e=0;e0;){var n=a.shift(),e=n.updaters.shift();e&&n.shouldUpdate&&e(n)}d=!1}function x(n,e){for(var t=0;t0&&t(n),t},f.stream["fantasy-land/of"]=f.stream.of=f.stream,f.combine=t(2,c),f.isStream=function(n){return!!((e=n)&&e.constructor&&e.call&&e.apply)&&"hasVal"in n;var e},f.immediate=function(n){return!1===n.depsMet&&(n.depsMet=!0,M(n)),n},f.endsOn=function(n,e){return N(e.end),n.listeners.push(e.end),e.end.deps.push(n),e},f.map=t(2,l),f.chain=t(2,g),f.ap=t(2,m),f.on=t(2,function(n,e){return c(function(e){n(e.val)},[e])}),f.scan=t(3,function(n,e,t){var r=c(function(t,r){r(e=n(e,t.val))},[t]);return r.hasVal||r(e),r}),f.merge=t(2,function(n,e){var t=f.immediate(c(function(n,e,t,r){r[0]?t(r[0]()):n.hasVal?t(n.val):e.hasVal&&t(e.val)},[n,e]));return f.endsOn(c(function(){return!0},[n.end,e.end]),t),t}),f.transduce=t(2,function(n,e){return n=n(new j),c(function(e,t){var r=n["@@transducer/step"](void 0,e.val);return r&&!0===r["@@transducer/reduced"]?(t.end(!0),r["@@transducer/value"]):r},[e])}),f.curryN=t,f.curry=function(n){return t(n.length,n)},f.fromPromise=function(n){var e=f.stream();return n.then(function(n){e(n),e.end(!0)}),e},f.flattenPromise=function(n){return c(function(n,e){n().then(e)},[n])},j.prototype["@@transducer/init"]=function(){},j.prototype["@@transducer/result"]=function(){},j.prototype["@@transducer/step"]=function(n,e){return e},f}); diff --git a/lib/index.js b/lib/index.js index bedbbb8..e2f5651 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,45 @@ 'use strict'; -var curryN = require('ramda/src/curryN'); - // Utility +var slice = Array.prototype.slice; +var concat = Array.prototype.concat; + +// This syntax should work in modern ES, but the test runner has problems with it. +// function curryN(n, func) { +// return (...args) => args.length >= n ? +// func(...args) : +// curryN(n - args.length, (...inner) => func(...args, ...inner)); +// } + +/** + * @function curryN + * @param {Integer} n + * @param {Function} func + * @returns {Function} + * @description Not entirely sure why dynamic currying was needed to begin with. + * Inside the library all of the functions are called with specific airity and the + * dynamic curry airity depth feature doesn't seem to be used anywhere. Regardless, + * this function is a drop in replacement for Ramda's curryN function which was + * previously being imported from the dependency, for backwards compatibility. + */ +function curryN(n, func) { + return function() { + var curargs = slice.call(arguments); + + if (curargs.length >= n) { + return func.apply(null, curargs); + } + + return curryN(n - curargs.length, function() { + return func.apply(null, concat.call(curargs, slice.call(arguments))); + }); + } +} + +function curry(func) { + return curryN(func.length, func); +} + function isFunction(obj) { return !!(obj && obj.constructor && obj.call && obj.apply); } @@ -189,7 +226,7 @@ flyd.endsOn = function(endS, s) { function map(f, s) { return combine(function(s, self) { self(f(s.val)); }, [s]); } -flyd.map = curryN(2, map) +flyd.map = curryN(2, map); /** * Chain a stream @@ -367,7 +404,8 @@ flyd.transduce = curryN(2, function(xform, source) { * var a = flyd.curryN(2, add); * a(2)(4) // => 6 */ -flyd.curryN = curryN +flyd.curryN = curryN; +flyd.curry = curry; /** * Returns a new stream identical to the original except every @@ -643,7 +681,7 @@ function updateStream(s) { * @param {stream} stream */ function updateListeners(s) { - var i, o, list + var i, o, list; var listeners = s.listeners; for (i = 0; i < listeners.length; ++i) { list = listeners[i]; diff --git a/package-lock.json b/package-lock.json index b4dfed4..2da0e0d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -224,10 +224,13 @@ "dev": true }, "asn1": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", - "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=", - "dev": true + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", + "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", + "dev": true, + "requires": { + "safer-buffer": "~2.1.0" + } }, "asn1.js": { "version": "4.10.1", @@ -301,11 +304,10 @@ "dev": true }, "bcrypt-pbkdf": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", - "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", "dev": true, - "optional": true, "requires": { "tweetnacl": "^0.14.3" } @@ -832,9 +834,9 @@ "dev": true }, "concat-stream": { - "version": "1.4.10", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.4.10.tgz", - "integrity": "sha1-rMO79WAsuMyYDGrIQPp9hgPj7zY=", + "version": "1.4.11", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.4.11.tgz", + "integrity": "sha512-X3JMh8+4je3U1cQpG87+f9lXHDrqcb2MVLg9L7o8b1UZ0DzhRrUpdn65ttzu10PpJPPI3MQNkis+oha6TSA9Mw==", "dev": true, "requires": { "inherits": "~2.0.1", @@ -894,6 +896,14 @@ "log-driver": "1.2.5", "minimist": "1.2.0", "request": "2.79.0" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + } } }, "create-ecdh": { @@ -1223,13 +1233,13 @@ "dev": true }, "ecc-jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", - "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", "dev": true, - "optional": true, "requires": { - "jsbn": "~0.1.0" + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" } }, "elegant-spinner": { @@ -1721,18 +1731,27 @@ "once": "^1.3.0", "path-is-absolute": "^1.0.0" } + }, + "minimatch": { + "version": "2.0.10", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz", + "integrity": "sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=", + "dev": true, + "requires": { + "brace-expansion": "^1.0.0" + } } } }, "fill-range": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-2.2.3.tgz", - "integrity": "sha1-ULd9/X5Gm8dJJHCWNpn+eoSFpyM=", + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-2.2.4.tgz", + "integrity": "sha512-cnrcCbj01+j2gTG921VZPnHbjmdAf8oQV/iGeV2kZxGSyfYjjTyY79ErsK1WJWMpw6DaApEX72binqJE+/d+5Q==", "dev": true, "requires": { "is-number": "^2.1.0", "isobject": "^2.0.0", - "randomatic": "^1.1.3", + "randomatic": "^3.0.0", "repeat-element": "^1.1.2", "repeat-string": "^1.5.2" } @@ -1803,10 +1822,13 @@ "dev": true }, "generate-function": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz", - "integrity": "sha1-aFj+fAlpt9TpCTM3ZHrHn2DfvnQ=", - "dev": true + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "dev": true, + "requires": { + "is-property": "^1.0.2" + } }, "generate-object-property": { "version": "1.2.0", @@ -1856,6 +1878,17 @@ "inherits": "2", "minimatch": "^2.0.1", "once": "^1.3.0" + }, + "dependencies": { + "minimatch": { + "version": "2.0.10", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz", + "integrity": "sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=", + "dev": true, + "requires": { + "brace-expansion": "^1.0.0" + } + } } }, "glob-base": { @@ -2087,9 +2120,9 @@ "dev": true }, "hosted-git-info": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.5.0.tgz", - "integrity": "sha512-pNgbURSuab90KbTqvRPsseaTxOJCZBD0a7t+haSN33piP9cCM4l0CqdzAif2hUqm716UovKB2ROmiabGAKVXyg==", + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "dev": true }, "htmlescape": { @@ -2193,9 +2226,9 @@ "dev": true }, "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, "inline-source-map": { @@ -2342,15 +2375,15 @@ "dev": true }, "is-my-json-valid": { - "version": "2.17.2", - "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.17.2.tgz", - "integrity": "sha512-IBhBslgngMQN8DDSppmgDv7RNrlFotuuDsKcrCP3+HbFaVivIBU7u9oiiErw8sH4ynx3+gOGQ3q2otkgiSi6kg==", + "version": "2.20.6", + "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.20.6.tgz", + "integrity": "sha512-1JQwulVNjx8UqkPE/bqDaxtH4PXCe/2VRh/y3p99heOV87HG4Id5/VfDswd+YiAfHcRTfDlWgISycnHuhZq1aw==", "dev": true, "requires": { "generate-function": "^2.0.0", "generate-object-property": "^1.1.0", "is-my-ip-valid": "^1.0.0", - "jsonpointer": "^4.0.0", + "jsonpointer": "^5.0.0", "xtend": "^4.0.0" } }, @@ -2583,8 +2616,7 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "dev": true, - "optional": true + "dev": true }, "json-parse-better-errors": { "version": "1.0.1", @@ -2593,9 +2625,9 @@ "dev": true }, "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", "dev": true }, "json-stable-stringify": { @@ -2626,20 +2658,20 @@ "dev": true }, "jsonpointer": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz", - "integrity": "sha1-T9kss04OnbPInIYi7PUfm5eMbLk=", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-5.0.0.tgz", + "integrity": "sha512-PNYZIdMjVIvVgDSYKTT63Y+KZ6IZvGRNNWcxwD+GNnUz1MKPfv30J8ueCjdwcN0nDx2SlshgyB7Oy0epAzVRRg==", "dev": true }, "jsprim": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", + "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", "dev": true, "requires": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", - "json-schema": "0.2.3", + "json-schema": "0.4.0", "verror": "1.10.0" }, "dependencies": { @@ -3008,9 +3040,9 @@ } }, "lodash": { - "version": "4.17.5", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", - "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==", + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, "lodash.memoize": { @@ -3135,6 +3167,12 @@ "integrity": "sha1-plzSkIepJZi4eRJXpSPgISIqwfk=", "dev": true }, + "math-random": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.4.tgz", + "integrity": "sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A==", + "dev": true + }, "md5.js": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz", @@ -3238,19 +3276,10 @@ "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=", "dev": true }, - "minimatch": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz", - "integrity": "sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=", - "dev": true, - "requires": { - "brace-expansion": "^1.0.0" - } - }, "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "dev": true }, "minimist-options": { @@ -3264,20 +3293,12 @@ } }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", "dev": true, "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - } + "minimist": "^1.2.5" } }, "mocha": { @@ -3339,6 +3360,21 @@ "sigmund": "~1.0.0" } }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, "ms": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", @@ -3917,9 +3953,9 @@ "dev": true }, "path-parse": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", - "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, "path-platform": { @@ -4065,48 +4101,33 @@ "dev": true }, "ramda": { - "version": "0.25.0", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.25.0.tgz", - "integrity": "sha512-GXpfrYVPwx3K7RQ6aYT8KPS8XViSXUVJT1ONhoKPE9VAleW42YE+U+8VEyGWt41EnEQW7gwecYJriTI0pKoecQ==" + "version": "0.27.1", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.27.1.tgz", + "integrity": "sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw==", + "dev": true }, "randomatic": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz", - "integrity": "sha512-D5JUjPyJbaJDkuAazpVnSfVkLlpeO3wDlPROTMLGKG1zMFNFRgrciKo1ltz/AzNTkqE0HzDx655QOL51N06how==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz", + "integrity": "sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw==", "dev": true, "requires": { - "is-number": "^3.0.0", - "kind-of": "^4.0.0" + "is-number": "^4.0.0", + "kind-of": "^6.0.0", + "math-random": "^1.0.1" }, "dependencies": { "is-number": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", - "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", - "dev": true, - "requires": { - "kind-of": "^3.0.2" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-4.0.0.tgz", + "integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==", + "dev": true }, "kind-of": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-4.0.0.tgz", - "integrity": "sha1-IIE989cSkosgc3hpGkUGb65y3Vc=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "dev": true } } }, @@ -4240,9 +4261,9 @@ } }, "registry-auth-token": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-3.3.2.tgz", - "integrity": "sha512-JL39c60XlzCVgNrO+qq68FoNb56w/m7JYvGR2jT5iR1xBrUA3Mfx5Twk5rqTThPmQKMWydGmq8oFtDlxfrmxnQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-3.4.0.tgz", + "integrity": "sha512-4LM6Fw8eBQdwMYcES4yTnn2TqIasbXuwDx3um+QRs7S55aMKCBKBxvPXl2RiUjHwuJLTyYfxSpmfSAjQpcuP+A==", "dev": true, "requires": { "rc": "^1.1.6", @@ -4542,6 +4563,12 @@ "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", "dev": true }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true + }, "semver": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", @@ -4677,9 +4704,9 @@ "dev": true }, "sshpk": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", - "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", "dev": true, "requires": { "asn1": "~0.2.3", @@ -4689,6 +4716,7 @@ "ecc-jsbn": "~0.1.1", "getpass": "^0.1.1", "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", "tweetnacl": "~0.14.0" }, "dependencies": { @@ -5056,8 +5084,7 @@ "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", - "dev": true, - "optional": true + "dev": true }, "type-check": { "version": "0.3.2", diff --git a/package.json b/package.json index 6ad1b4c..8aee06a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "test": "test" }, "dependencies": { - "ramda": "^0.25.0", "whatwg-fetch": "^3.0.0" }, "devDependencies": { @@ -22,6 +21,7 @@ "mocha": "^2.2.1", "mocha-lcov-reporter": "0.0.2", "np": "^2.19.0", + "ramda": "^0.27.1", "rollup": "^0.56.2", "rollup-plugin-commonjs": "^8.3.0", "rollup-plugin-node-resolve": "^3.0.3",