diff --git a/README.md b/README.md index 0bf57d5..e2539fe 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ Lamb it's also delivered on a CDN, courtesy of [jsDelivr](https://www.jsdelivr.c The URLs above will retrieve the latest version, but you can target a specific one: ```html - + ``` ```html - + ``` Please note that Lamb is served by jsDelivr since version 0.42.0. @@ -105,6 +105,12 @@ You can check the [recent](#recent_changes) or the [full](https://ascartabelli.g ## Recent changes You can also check the [full changelog](https://ascartabelli.github.io/lamb/changelog.html). +- **v0.43.0 - *2016/11/03*** + - **Fully compatible with versions down to 0.40.x** + - Added `pathExists` and `pathExistsIn` + - Improved performance of `setIn`, `setKey`, `updateIn` and `updateKey` + - Improved performance of `setPath`, `setPathIn`, `updatePath` and `updatePathIn` + - **v0.42.0 - *2016/10/25*** - **Fully compatible with versions down to 0.40.x** - Added `unless` and `when` @@ -133,10 +139,3 @@ You can also check the [full changelog](https://ascartabelli.github.io/lamb/chan - Made `intersection` use `everyIn` instead of the native method - Updated doc comments, examples and tests for `uniques` - Minor performance improvement of `uniques` - -- **v0.38.0 - *2016/08/19*** - - **Fully compatible with versions down to 0.37.x** - - Improved performance of `flatMap`, `flatMapWith`, `flatten` and `shallowFlatten` - - Greatly improved performance of all grouping functions - - Greatly improved performance of `transpose`, improved performance of `zip` as a consequence - - Greatly improved performance of `getArgAt` diff --git a/dist/lamb.js b/dist/lamb.js index 56747ad..8e2275d 100644 --- a/dist/lamb.js +++ b/dist/lamb.js @@ -1,7 +1,7 @@ /** * @overview lamb - A lightweight, and docile, JavaScript library to help embracing functional programming. * @author Andrea Scartabelli - * @version 0.43.0-alpha.8 + * @version 0.43.0 * @module lamb * @license MIT * @preserve @@ -18,7 +18,7 @@ * @category Core * @type String */ - lamb._version = "0.43.0-alpha.8"; + lamb._version = "0.43.0"; // alias used as a placeholder argument for partial application var _ = lamb; diff --git a/dist/lamb.min.js b/dist/lamb.min.js index cd9382b..9b7ed2f 100644 --- a/dist/lamb.min.js +++ b/dist/lamb.min.js @@ -1,10 +1,10 @@ /** * @overview lamb - A lightweight, and docile, JavaScript library to help embracing functional programming. * @author Andrea Scartabelli - * @version 0.43.0-alpha.8 + * @version 0.43.0 * @module lamb * @license MIT * @preserve */ -!function(n){"use strict";function r(n){return function(){return n}}function t(){var n=arguments;return function(){for(var r=arguments,t=n.length;t--;)r=[n[t].apply(this,r)];return r[0]}}function e(n){return n}function u(n){var r=Hr.apply(null,arguments);return function(){for(var t,e=0,u=[],i=r.length,o=0;or||n!==n?t=1:(n1&&e?o:1),a=Array(f),l=0;l=r?n.apply(this,t?a.reverse():a):c(n,r,t,e,a)}}function l(n,r,t,e){return r>>>0!==r&&(r=n.length),r>1?c(n,r,t,e,[]):n}function h(n,r,t,e){for(var u,i,o,f=0,a=n.length;f>1,o=t({value:r,index:i},{value:n[i],index:i});return u-e<=1?o<0?i:i+1:o<0?p(n,r,t,e,i):0===o?i+1:p(n,r,t,i,u)}function s(n,r){var t=n.length;return k(r)&&k(t)&&on(r,-t,t-1)===r?r<0?r+t:r:void 0}function v(n,r,t){var e=0,u=n.length;for(3===arguments.length&&(r=r.bind(t));e>>0,f=1===n?0:o-1;if(3===arguments.length)u=o,i=e;else{if(0===o)throw new TypeError("Reduce of empty array-like with no initial value");i=r[f],f+=n,u=o-1}for(;u--;f+=n)i=t(i,r[f],f,r);return i}}function K(n,r){return new TypeError("Cannot convert "+mn(n).toLowerCase()+" to "+r)}function M(n){return ft(Hr.apply(null,arguments),function(r,t){return C(n(t),function(n){r[n]=t[n]}),r},{})}function E(n){return function(r,t){var e=2===arguments.length?n:or(n);return u(e,Gr,r,t)}}function T(n){var r=[];for(var t in n)r.push(t);return r}function V(n,r,t){var e={};for(var u in n)e[u]=n[u];return e[r]=t,e}function N(n,r,t,e){var u=ht(n),i=s(u,r);return bn(i)||(u[i]=4===arguments.length?e(n[i]):t),u}function R(n,r,t){var e,u=r[0];if(1===r.length)e=t;else{var i=d(n,u,!1);e=R(bn(i)?i:n[i],ht(r,1),t)}return O(n,u)?N(n,+u,e):V(n,u,e)}function S(n,r,t){return{isDescending:r===!0,compare:function(r,u){return"function"==typeof n&&n!==e&&(r=n(r),u=n(u)),("function"==typeof t?t:f)(r,u)}}}function D(n,r){return String(n).split(r||".")}function z(n,r){return function(t){return G(t,n,r)}}function L(n,r,t){var e=n.length,u=[];3===arguments.length&&(r=r.bind(t));for(var i=0;i>>0;e>>0,i=n.length;u>>0,u=Array(e);3===arguments.length&&(r=r.bind(t));for(var i=0;ir}function X(n,r){return n>=r}function Y(n,r){return nt?t:n}function fn(n,r){return n/r}function an(n,r,t,e){var u=[n];4===arguments.length&&(t=t.bind(e));for(var i=0,o=r-1;i>>0;if(0===t)return r;for(var e,u=n[0].length>>>0,i=1;i0;i++)e=n[i].length>>>0,e0)for(;e=r&&(e=u,t=n.apply(this,arguments)),t}}function Ar(n){return function(r){return n.call(this,r)}}function Or(n,r,t,e){return function(i){var o=u(jn,i,Gr,e);return n.apply(i,q(t,o))?[]:[r,t]}}function xr(n){var r={};return C(n,function(n){r[n[0]]=n[1]}),r}function kr(n,r){return"object"==typeof n||bn(n)||(n=Object(n)),r in n}function wr(n){return function(r){return kr(r,n)}}function jr(n,r){return function(t){return nn(r,t[n])}}function Ir(n){return function(r){return Bt(r,n)}}function Wr(n,r,t){return function(e){var u=y(e,D(n,t),!0);return u.isValid&&nn(u.target,r)}}function Pr(n){return m(n,[])}function Kr(n,r){for(var t={},e=r.length,u=0,i=n.length;ur||n!==n?t=1:(n1&&e?o:1),a=Array(f),l=0;l=r?n.apply(this,t?a.reverse():a):c(n,r,t,e,a)}}function l(n,r,t,e){return r>>>0!==r&&(r=n.length),r>1?c(n,r,t,e,[]):n}function h(n,r,t,e){for(var u,i,o,f=0,a=n.length;f>1,o=t({value:r,index:i},{value:n[i],index:i});return u-e<=1?o<0?i:i+1:o<0?p(n,r,t,e,i):0===o?i+1:p(n,r,t,i,u)}function s(n,r){var t=n.length;return k(r)&&k(t)&&on(r,-t,t-1)===r?r<0?r+t:r:void 0}function v(n,r,t){var e=0,u=n.length;for(3===arguments.length&&(r=r.bind(t));e>>0,f=1===n?0:o-1;if(3===arguments.length)u=o,i=e;else{if(0===o)throw new TypeError("Reduce of empty array-like with no initial value");i=r[f],f+=n,u=o-1}for(;u--;f+=n)i=t(i,r[f],f,r);return i}}function K(n,r){return new TypeError("Cannot convert "+mn(n).toLowerCase()+" to "+r)}function M(n){return ft(Hr.apply(null,arguments),function(r,t){return C(n(t),function(n){r[n]=t[n]}),r},{})}function E(n){return function(r,t){var e=2===arguments.length?n:or(n);return u(e,Gr,r,t)}}function T(n){var r=[];for(var t in n)r.push(t);return r}function V(n,r,t){var e={};for(var u in n)e[u]=n[u];return e[r]=t,e}function N(n,r,t,e){var u=ht(n),i=s(u,r);return bn(i)||(u[i]=4===arguments.length?e(n[i]):t),u}function R(n,r,t){var e,u=r[0];if(1===r.length)e=t;else{var i=d(n,u,!1);e=R(bn(i)?i:n[i],ht(r,1),t)}return O(n,u)?N(n,+u,e):V(n,u,e)}function S(n,r,t){return{isDescending:r===!0,compare:function(r,u){return"function"==typeof n&&n!==e&&(r=n(r),u=n(u)),("function"==typeof t?t:f)(r,u)}}}function D(n,r){return String(n).split(r||".")}function z(n,r){return function(t){return G(t,n,r)}}function L(n,r,t){var e=n.length,u=[];3===arguments.length&&(r=r.bind(t));for(var i=0;i>>0;e>>0,i=n.length;u>>0,u=Array(e);3===arguments.length&&(r=r.bind(t));for(var i=0;ir}function X(n,r){return n>=r}function Y(n,r){return nt?t:n}function fn(n,r){return n/r}function an(n,r,t,e){var u=[n];4===arguments.length&&(t=t.bind(e));for(var i=0,o=r-1;i>>0;if(0===t)return r;for(var e,u=n[0].length>>>0,i=1;i0;i++)e=n[i].length>>>0,e0)for(;e=r&&(e=u,t=n.apply(this,arguments)),t}}function Ar(n){return function(r){return n.call(this,r)}}function Or(n,r,t,e){return function(i){var o=u(jn,i,Gr,e);return n.apply(i,q(t,o))?[]:[r,t]}}function xr(n){var r={};return C(n,function(n){r[n[0]]=n[1]}),r}function kr(n,r){return"object"==typeof n||bn(n)||(n=Object(n)),r in n}function wr(n){return function(r){return kr(r,n)}}function jr(n,r){return function(t){return nn(r,t[n])}}function Ir(n){return function(r){return Bt(r,n)}}function Wr(n,r,t){return function(e){var u=y(e,D(n,t),!0);return u.isValid&&nn(u.target,r)}}function Pr(n){return m(n,[])}function Kr(n,r){for(var t={},e=r.length,u=0,i=n.length;u\n * @version 0.43.0-alpha.8\n * @module lamb\n * @license MIT\n * @preserve\n */\n(function (host) {\n \"use strict\";\n\n var lamb = Object.create(null);\n\n /**\n * The current module version.\n * @memberof module:lamb\n * @private\n * @category Core\n * @type String\n */\n lamb._version = \"0.43.0-alpha.8\";\n\n // alias used as a placeholder argument for partial application\n var _ = lamb;\n\n // some prototype shortcuts for internal use\n var _arrayProto = Array.prototype;\n var _objectProto = Object.prototype;\n var _reProto = RegExp.prototype;\n\n /**\n * Builds a function that returns a constant value.\n * It's actually the simplest form of the K combinator or Kestrel.\n * @example\n * var truth = _.always(true);\n *\n * truth() // => true\n * truth(false) // => true\n * truth(1, 2) // => true\n *\n * // the value being returned is actually the\n * // very same value passed to the function\n * var foo = {bar: \"baz\"};\n * var alwaysFoo = _.always(foo);\n *\n * alwaysFoo() === foo // => true\n *\n * @memberof module:lamb\n * @category Core\n * @see [SKI combinator calculus]{@link https://en.wikipedia.org/wiki/SKI_combinator_calculus}\n * @param {*} value\n * @returns {Function}\n */\n function always (value) {\n return function () {\n return value;\n };\n }\n\n /**\n * Returns a function that is the composition of the functions given as parameters.\n * Each function consumes the result of the function that follows.\n * @example\n * var sayHi = function (name) { return \"Hi, \" + name; };\n * var capitalize = function (s) {\n * return s[0].toUpperCase() + s.substr(1).toLowerCase();\n * };\n * var fixNameAndSayHi = _.compose(sayHi, capitalize);\n *\n * sayHi(\"bOb\") // => \"Hi, bOb\"\n * fixNameAndSayHi(\"bOb\") // \"Hi, Bob\"\n *\n * var getName = _.getKey(\"name\");\n * var users = [{name: \"fred\"}, {name: \"bOb\"}];\n * var sayHiToUser = _.compose(fixNameAndSayHi, getName);\n *\n * users.map(sayHiToUser) // [\"Hi, Fred\", \"Hi, Bob\"]\n *\n * @memberof module:lamb\n * @category Function\n * @param {...Function} fn\n * @returns {Function}\n */\n function compose () {\n var functions = arguments;\n\n return function () {\n var args = arguments;\n var len = functions.length;\n\n while (len--) {\n args = [functions[len].apply(this, args)];\n }\n\n return args[0];\n };\n }\n\n /**\n * Creates generic functions out of methods.\n * @memberof module:lamb\n * @category Core\n * @author A very little change on a great idea by [Irakli Gozalishvili]{@link https://github.com/Gozala/}.\n * Thanks for this *beautiful* one-liner (never liked your \"unbind\" naming choice, though).\n * @function\n * @example\n * // Lamb's \"slice\" is actually implemented like this\n * var slice = _.generic(Array.prototype.slice);\n *\n * slice([\"foo\", \"bar\", \"baz\"], 0, -1) // => [\"foo\", \"bar\"]\n *\n * // the function will work with any array-like object\n * slice(\"fooBAR\", 0, 3) // => [\"f\", \"o\", \"o\"]\n *\n * @param {Function} method\n * @returns {Function}\n */\n var generic = Function.bind.bind(Function.call);\n\n /**\n * The I combinator. Any value passed to the function is simply returned as it is.\n * @example\n * var foo = {bar: \"baz\"};\n *\n * _.identity(foo) === foo // true\n *\n * @memberof module:lamb\n * @category Core\n * @see [SKI combinator calculus]{@link https://en.wikipedia.org/wiki/SKI_combinator_calculus}\n * @param {*} value\n * @returns {*} The value passed as parameter.\n */\n function identity (value) {\n return value;\n }\n\n /**\n * Builds a partially applied function. The lamb object itself can be used\n * as a placeholder argument and it's useful to alias it with a short symbol such as _.\n * @example\n * var weights = [\"2 Kg\", \"10 Kg\", \"1 Kg\", \"7 Kg\"];\n * var parseInt10 = _.partial(parseInt, _, 10);\n *\n * weights.map(parseInt10) // => [2, 10, 1, 7]\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.asPartial|asPartial}\n * @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}\n * @param {Function} fn\n * @param {...*} args\n * @returns {Function}\n */\n function partial (fn) {\n var args = _argsTail.apply(null, arguments);\n\n return function () {\n var lastIdx = 0;\n var newArgs = [];\n var argsLen = args.length;\n\n for (var i = 0, boundArg; i < argsLen; i++) {\n boundArg = args[i];\n newArgs[i] = boundArg === _ ? arguments[lastIdx++] : boundArg;\n }\n\n for (var len = arguments.length; lastIdx < len; lastIdx++) {\n newArgs[i++] = arguments[lastIdx];\n }\n\n return fn.apply(this, newArgs);\n };\n }\n\n lamb.always = always;\n lamb.compose = compose;\n lamb.generic = generic;\n lamb.identity = identity;\n lamb.partial = partial;\n\n /**\n * Builds an array with the received arguments excluding the first one.
\n * To be used with the arguments object, which needs to be passed to the apply\n * method of this function.\n * @private\n * @function\n * @param {...*} value\n * @returns {Array}\n */\n var _argsTail = _argsToArrayFrom(1);\n\n /**\n * Builds helper functions to extract portions of the arguments\n * object rather efficiently without having to write for loops\n * manually for each case.
\n * The arguments object needs to be passed to the apply method\n * of the generated function.\n * @private\n * @param {Number} idx\n * @returns {Function}\n */\n function _argsToArrayFrom (idx) {\n return function () {\n var argsLen = arguments.length || idx;\n var len = argsLen - idx;\n var result = Array(len);\n\n for (var i = 0; i < len; i++) {\n result[i] = arguments[i + idx];\n }\n\n return result;\n };\n }\n\n /**\n * Keeps building a partial application of the received function as long\n * as it's called with placeholders; applies the original function with\n * the collected parameters otherwise.\n * @private\n * @param {Function} fn\n * @param {Array} argsHolder\n * @returns {Function|*}\n */\n function _asPartial (fn, argsHolder) {\n return function () {\n var argsHolderLen = argsHolder.length;\n var argsLen = arguments.length;\n var lastIdx = 0;\n var newArgs = [];\n var canApply = true;\n\n for (var i = 0; i < argsLen; i++) {\n if (arguments[i] === _) {\n canApply = false;\n break;\n }\n }\n\n for (var idx = 0, boundArg; idx < argsHolderLen; idx++) {\n boundArg = argsHolder[idx];\n newArgs[idx] = lastIdx < argsLen && boundArg === _ ? arguments[lastIdx++] : boundArg;\n }\n\n while (lastIdx < argsLen) {\n newArgs[idx++] = arguments[lastIdx++];\n }\n\n return canApply ? fn.apply(this, newArgs) : _asPartial(fn, newArgs);\n };\n }\n\n /**\n * The default comparer for sorting functions.
\n * If the given values are of different types they\n * will be both converted to strings.
\n * Uses the SameValueZero comparison.\n * @private\n * @param {*} a\n * @param {*} b\n * @returns {Number} -1 | 0 | 1\n */\n function _comparer (a, b) {\n var result = 0;\n\n if (typeof a !== typeof b) {\n a = String(a);\n b = String(b);\n }\n\n /* eslint-disable no-self-compare */\n\n if (!isSVZ(a, b)) {\n if (a > b || a !== a) {\n result = 1;\n } else if (a < b || b !== b) {\n result = -1;\n }\n }\n\n /* eslint-enable no-self-compare */\n\n return result;\n }\n\n /**\n * Accepts a list of sorting criteria and builds a function that compares\n * two values with such criteria.\n * @private\n * @param {Sorter[]} criteria\n * @returns {Function}\n */\n function _compareWith (criteria) {\n var len = criteria.length;\n\n return function (a, b) {\n var result = 0;\n var isDescSort;\n var criterion;\n\n for (var i = 0; i < len; i++) {\n criterion = criteria[i];\n result = criterion.compare(a.value, b.value);\n\n if (result !== 0) {\n isDescSort = criteria[i].isDescending;\n break;\n }\n }\n\n if (result === 0) {\n isDescSort = criteria[len - 1].isDescending;\n result = a.index - b.index;\n }\n\n return isDescSort ? -result : result;\n };\n }\n\n /**\n * Used by curry functions to collect arguments until the arity is consumed,\n * then applies the original function.\n * @private\n * @param {Function} fn\n * @param {Number} arity\n * @param {Boolean} isRightCurry\n * @param {Boolean} isAutoCurry\n * @param {Array} argsHolder\n * @returns {Function}\n */\n function _currier (fn, arity, isRightCurry, isAutoCurry, argsHolder) {\n return function () {\n var holderLen = argsHolder.length;\n var argsLen = arguments.length;\n var newArgsLen = holderLen + (argsLen > 1 && isAutoCurry ? argsLen : 1);\n var newArgs = Array(newArgsLen);\n\n for (var i = 0; i < holderLen; i++) {\n newArgs[i] = argsHolder[i];\n }\n\n for (; i < newArgsLen; i++) {\n newArgs[i] = arguments[i - holderLen];\n }\n\n if (newArgsLen >= arity) {\n return fn.apply(this, isRightCurry ? newArgs.reverse() : newArgs);\n } else {\n return _currier(fn, arity, isRightCurry, isAutoCurry, newArgs);\n }\n };\n }\n\n /**\n * Prepares a function for currying by setting the proper arity for\n * the _currier function.\n * If the desumed arity isn't greater than one, it will return the received\n * function itself, instead.\n * @private\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @param {Boolean} isRightCurry\n * @param {Boolean} isAutoCurry\n * @returns {Function}\n */\n function _curry (fn, arity, isRightCurry, isAutoCurry) {\n if (arity >>> 0 !== arity) {\n arity = fn.length;\n }\n\n return arity > 1 ? _currier(fn, arity, isRightCurry, isAutoCurry, []) : fn;\n }\n\n /**\n * Flattens an array.\n * @private\n * @param {Array} array - The source array\n * @param {Boolean} isDeep - Whether to perform a deep flattening or not\n * @param {Array} output - An array to collect the result\n * @param {Number} idx - The next index to be filled in the output\n * @returns {Array} The output array filled with the results\n */\n function _flatten (array, isDeep, output, idx) {\n for (var i = 0, len = array.length, value, j, vLen; i < len; i++) {\n value = array[i];\n\n if (!Array.isArray(value)) {\n output[idx++] = value;\n } else if (isDeep) {\n _flatten(value, true, output, idx);\n idx = output.length;\n } else {\n vLen = value.length;\n output.length += vLen;\n\n for (j = 0; j < vLen; j++) {\n output[idx++] = value[j];\n }\n }\n }\n\n return output;\n }\n\n /**\n * Establishes at which index an element should be inserted in a sorted array to respect\n * the array order. Needs the comparer used to sort the array.\n * @private\n * @param {Array} array\n * @param {*} element\n * @param {Function} comparer\n * @param {Number} start\n * @param {Number} end\n * @returns {Number}\n */\n function _getInsertionIndex (array, element, comparer, start, end) {\n if (array.length === 0) {\n return 0;\n }\n\n var pivot = (start + end) >> 1;\n var result = comparer({\n value: element,\n index: pivot\n }, {\n value: array[pivot],\n index: pivot\n });\n\n if (end - start <= 1) {\n return result < 0 ? pivot : pivot + 1;\n } else if (result < 0) {\n return _getInsertionIndex(array, element, comparer, start, pivot);\n } else if (result === 0) {\n return pivot + 1;\n } else {\n return _getInsertionIndex(array, element, comparer, pivot, end);\n }\n }\n\n /**\n * Checks if the given index, even negative, exists in the target object, if\n * it's an array-like, and transforms it to a natural number.\n * Returns undefined otherwise.\n * @private\n * @param {ArrayLike} target\n * @param {Number} index\n * @returns {Number|Undefined}\n */\n function _getNaturalIndex (target, index) {\n var len = target.length;\n\n if (_isInteger(index) && _isInteger(len)) {\n return clamp(index, -len, len - 1) === index ? index < 0 ? index + len : index : void 0;\n } else {\n return void 0;\n }\n }\n\n /**\n * Gets the number of consecutive elements satisfying a predicate in an array-like object.\n * @private\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Number}\n */\n function _getNumConsecutiveHits (arrayLike, predicate, predicateContext) {\n var idx = 0;\n var len = arrayLike.length;\n\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n while (idx < len && predicate(arrayLike[idx], idx, arrayLike)) {\n idx++;\n }\n\n return idx;\n }\n\n /**\n * Builds the prefix or suffix to be used when padding a string.\n * @private\n * @param {String} source\n * @param {String} char\n * @param {Number} len\n * @returns {String}\n */\n function _getPadding (source, char, len) {\n if (!isNil(source) && type(source) !== \"String\") {\n source = String(source);\n }\n\n return repeat(Object(char)[0] || \" \", Math.ceil(len - source.length));\n }\n\n /**\n * Checks if a path is valid in the given object and retrieves the path target.\n * @private\n * @param {Object} obj\n * @param {String[]} parts\n * @param {Boolean} walkNonEnumerables\n * @returns {Object}\n */\n function _getPathInfo (obj, parts, walkNonEnumerables) {\n if (isNil(obj)) {\n throw _makeTypeErrorFor(obj, \"object\");\n }\n\n var target = obj;\n var i = -1;\n var len = parts.length;\n var key;\n\n while (++i < len) {\n key = _getPathKey(target, parts[i], walkNonEnumerables);\n\n if (isUndefined(key)) {\n break;\n }\n\n target = target[key];\n }\n\n return i === len ? {isValid: true, target: target} : {isValid: false, target: void 0};\n }\n\n /**\n * Helper to retrieve the correct key while evaluating a path.\n * @private\n * @param {Object} target\n * @param {String} key\n * @param {Boolean} includeNonEnumerables\n * @returns {String|Number|Undefined}\n */\n function _getPathKey (target, key, includeNonEnumerables) {\n if (includeNonEnumerables && key in Object(target) || _isEnumerable(target, key)) {\n return key;\n }\n\n var keyAsNumber = Number(key);\n\n if (keyAsNumber < 0) {\n return _getNaturalIndex(target, keyAsNumber);\n } else if (Array.isArray(target) && keyAsNumber < target.length) {\n return keyAsNumber;\n }\n\n return void 0;\n }\n\n /**\n * Builds a \"grouping function\" for an array-like object.\n * @private\n * @param {Function} makeValue\n * @returns {Function}\n */\n function _groupWith (makeValue) {\n return function (arrayLike, iteratee, iterateeContext) {\n if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n var result = {};\n var len = arrayLike.length;\n\n for (var i = 0, element, key; i < len; i++) {\n element = arrayLike[i];\n key = iteratee(element, i, arrayLike);\n result[key] = makeValue(result[key], element);\n }\n\n return result;\n };\n }\n\n /**\n * Makes an object immutable by recursively calling Object.freeze\n * on its members.\n * @private\n * @param {Object} obj\n * @param {Array} seen\n * @returns {Object} The obj parameter itself, not a copy.\n */\n function _immutable (obj, seen) {\n if (seen.indexOf(obj) === -1) {\n seen.push(Object.freeze(obj));\n\n forEach(Object.getOwnPropertyNames(obj), function (key) {\n var value = obj[key];\n\n if (typeof value === \"object\" && !isNull(value)) {\n _immutable(value, seen);\n }\n });\n }\n\n return obj;\n }\n\n /**\n * If a method with the given name exists on the target, applies it with the provided\n * arguments and returns the result. Returns undefined otherwise.
\n * The arguments for the method are built by concatenating the array of bound arguments,\n * optionally received by {@link module:lamb.invoker|invoker}, with the final set of, also\n * optional, args.\n * @private\n * @param {Array} boundArgs\n * @param {String} methodName\n * @param {Object} target\n * @param {...*} [args]\n * @returns {*}\n */\n function _invoker (boundArgs, methodName, target) {\n var method = target[methodName];\n\n if (typeof method !== \"function\") {\n return void 0;\n }\n\n var boundArgsLen = boundArgs.length;\n var ofs = 3 - boundArgsLen;\n var len = arguments.length - ofs;\n var args = Array(len);\n\n for (var i = 0; i < boundArgsLen; i++) {\n args[i] = boundArgs[i];\n }\n\n for (; i < len; i++) {\n args[i] = arguments[i + ofs];\n }\n\n return method.apply(target, args);\n }\n\n /**\n * Accepts a target object and a key name and verifies that the target is an array and that\n * the key is an existing index.\n * @private\n * @param {Object} target\n * @param {String|Number} key\n * @returns {Boolean}\n */\n function _isArrayIndex (target, key) {\n var n = Number(key);\n\n return Array.isArray(target) && _isInteger(n) && !(n < 0 && _isEnumerable(target, key));\n }\n\n /**\n * Checks whether the specified key is an enumerable property of the given object or not.\n * @private\n * @param {Object} obj\n * @param {String} key\n * @returns {Boolean}\n */\n function _isEnumerable (obj, key) {\n return key in Object(obj) && (_isOwnEnumerable(obj, key) || ~_safeEnumerables(obj).indexOf(key));\n }\n\n /**\n * Checks if the given value is an integer.\n * @private\n * @param {*} n\n * @returns {Boolean}\n */\n function _isInteger (n) {\n return Math.floor(n) === n;\n }\n\n /**\n * Checks whether the specified key is a own enumerable property of the given object or not.\n * @private\n * @function\n * @param {Object} obj\n * @param {String} key\n * @returns {Boolean}\n */\n var _isOwnEnumerable = generic(_objectProto.propertyIsEnumerable);\n\n /**\n * Accepts an object and build a function expecting a key to create a \"pair\" with the key\n * and its value.\n * @private\n * @param {Object} obj\n * @returns {Function}\n */\n function _keyToPairIn (obj) {\n return function (key) {\n return [key, obj[key]];\n };\n }\n\n /**\n * Helper to build the {@link module:lamb.everyIn|everyIn} or the\n * {@link module:lamb.someIn|someIn} function.\n * @private\n * @param {Boolean} defaultResult\n * @returns {Function}\n */\n function _makeArrayChecker (defaultResult) {\n return function (arrayLike, predicate, predicateContext) {\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n for (var i = 0, len = arrayLike.length; i < len; i++) {\n if (defaultResult ^ !!predicate(arrayLike[i], i, arrayLike)) {\n return !defaultResult;\n }\n }\n\n return defaultResult;\n };\n }\n\n /**\n * Builds a list of sorting criteria from a list of sorter functions. Returns a list containing\n * a single default sorting criterion if the sorter list is empty.\n * @private\n * @param {Function[]} sorters\n * @returns {Sorter[]}\n */\n function _makeCriteria (sorters) {\n return sorters.length ? map(sorters, _makeCriterion) : [_sorter()];\n }\n\n /**\n * Converts a sorting function to a sorting criterion if necessary.\n * @private\n * @param {Function} criterion\n * @returns {Sorter}\n */\n function _makeCriterion (criterion) {\n return typeof Object(criterion).compare === \"function\" ? criterion : _sorter(criterion);\n }\n\n /**\n * Builds a reduce function. The step parameter must be 1\n * to build {@link module:lamb.reduce|reduce} and -1 to build\n * {@link module:lamb.reduceRight|reduceRight}.\n * @private\n * @param {Number} step\n * @returns {Function}\n */\n function _makeReducer (step) {\n return function (arrayLike, accumulator, initialValue) {\n var len = arrayLike.length >>> 0;\n var idx = step === 1 ? 0 : len - 1;\n var nCalls;\n var result;\n\n if (arguments.length === 3) {\n nCalls = len;\n result = initialValue;\n } else {\n if (len === 0) {\n throw new TypeError(\"Reduce of empty array-like with no initial value\");\n }\n\n result = arrayLike[idx];\n idx += step;\n nCalls = len - 1;\n }\n\n for (; nCalls--; idx += step) {\n result = accumulator(result, arrayLike[idx], idx, arrayLike);\n }\n\n return result;\n };\n }\n\n /**\n * Builds a TypeError stating that it's not possible to convert the given value to the\n * desired type.\n * @private\n * @param {*} value\n * @param {String} desiredType\n * @returns {TypeError}\n */\n function _makeTypeErrorFor (value, desiredType) {\n return new TypeError(\"Cannot convert \" + type(value).toLowerCase() + \" to \" + desiredType);\n }\n\n /**\n * Merges the received objects using the provided functions to retrieve their keys.\n * @private\n * @param {Function} getKeys\n * @param {...Object} source\n * @returns {Object}\n */\n function _merge (getKeys) {\n return reduce(_argsTail.apply(null, arguments), function (result, source) {\n forEach(getKeys(source), function (key) {\n result[key] = source[key];\n });\n\n return result;\n }, {});\n }\n\n /**\n * Using the provided function to retrieve the keys of an object, builds\n * a function expecting an object to create a list of key / value pairs.\n * @private\n * @function\n * @param {Function} getKeys\n * @returns {Function}\n */\n var _pairsFrom = _curry(function (getKeys, obj) {\n return map(getKeys(obj), _keyToPairIn(obj));\n });\n\n /**\n * Builds a partial application of a function expecting an iteratee and an\n * optional argument other than its main data parameter.
\n * The optional argument is passed to the function only when is explicitly given\n * a value.
\n * The optional argument is usually the iteratee context, but reduce functions\n * pass their initial value instead.\n * @private\n * @param {Function} fn\n * @returns {Function}\n */\n function _partialWithIteratee (fn) {\n return function (iteratee, optionalArgument) {\n var f = arguments.length === 2 ? fn : binary(fn);\n\n return partial(f, _, iteratee, optionalArgument);\n };\n }\n\n /**\n * Builds a list of the enumerable properties of an object.\n * The function is null-safe, unlike the public one.\n * @private\n * @param {Object} obj\n * @returns {String[]}\n */\n function _safeEnumerables (obj) {\n var result = [];\n\n for (var key in obj) {\n result.push(key);\n }\n\n return result;\n }\n\n /**\n * A null-safe version of Object.keys.\n * @private\n * @param {Object} obj\n * @returns {String[]}\n */\n var _safeKeys = compose(Object.keys, Object);\n\n /**\n * Sets, or creates, a property in a copy of the provided object to the desired value.\n * @param {Object} source\n * @param {String} key\n * @param {*} value\n * @returns {Object}\n */\n function _setIn (source, key, value) {\n var result = {};\n\n for (var prop in source) {\n result[prop] = source[prop];\n }\n\n result[key] = value;\n\n return result;\n }\n\n /**\n * Sets an index in an array-like object.
\n * If provided with an updater function it will use it to update the current value,\n * otherwise sets the index to the specified value.\n * @private\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @param {*} [value]\n * @param {Function} [updater]\n * @returns {Array}\n */\n function _setIndex (arrayLike, index, value, updater) {\n var result = slice(arrayLike);\n var idx = _getNaturalIndex(result, index);\n\n if (!isUndefined(idx)) {\n result[idx] = arguments.length === 4 ? updater(arrayLike[idx]) : value;\n }\n\n return result;\n }\n\n /**\n * Sets the object's property targeted by the given path to the desired value.
\n * Works with arrays and is able to set their indexes, even negative ones.\n * @private\n * @param {Object|Array} obj\n * @param {String[]} parts\n * @param {*} value\n * @returns {Object|Array}\n */\n function _setPathIn (obj, parts, value) {\n var key = parts[0];\n var v;\n\n if (parts.length === 1) {\n v = value;\n } else {\n var targetKey = _getPathKey(obj, key, false);\n\n v = _setPathIn(\n isUndefined(targetKey) ? targetKey : obj[targetKey],\n slice(parts, 1),\n value\n );\n }\n\n return _isArrayIndex(obj, key) ? _setIndex(obj, +key, v) : _setIn(obj, key, v);\n }\n\n /**\n * Builds a sorting criterion. If the comparer function is missing, the default\n * comparer will be used instead.\n * @private\n * @param {Function} reader\n * @param {Boolean} isDescending\n * @param {Function} [comparer]\n * @returns {Sorter}\n */\n function _sorter (reader, isDescending, comparer) {\n return {\n isDescending: isDescending === true,\n compare: function (a, b) {\n if (typeof reader === \"function\" && reader !== identity) {\n a = reader(a);\n b = reader(b);\n }\n\n return (typeof comparer === \"function\" ? comparer : _comparer)(a, b);\n }\n };\n }\n\n /**\n * Using the provided function to retrieve the keys of an object, builds\n * a function expecting an object to create an array containing a list\n * of the keys in its first index and the corresponding list of values\n * in the second one.\n * @private\n * @function\n * @param {Function} getKeys\n * @returns {Function}\n */\n var _tearFrom = _curry(function (getKeys, obj) {\n return reduce(getKeys(obj), function (result, key) {\n result[0].push(key);\n result[1].push(obj[key]);\n\n return result;\n }, [[], []]);\n });\n\n /**\n * Splits a sting path using the provided separator and returns an array\n * of path parts.\n * @private\n * @param {String} path\n * @param {String} separator\n * @returns {String[]}\n */\n function _toPathParts (path, separator) {\n return String(path).split(separator || \".\");\n }\n\n /**\n * Creates a non-null-safe version of the provided \"getKeys\" function.\n * @private\n * @function\n * @param {Function} getKeys\n * @returns {Function}\n */\n var _unsafeKeyListFrom = _curry(function (getKeys, obj) {\n if (isNil(obj)) {\n throw _makeTypeErrorFor(obj, \"object\");\n }\n\n return getKeys(obj);\n });\n\n /**\n * Using the provided function to retrieve the keys of an object, builds\n * a function expecting an object to create the list of values for such keys.\n * @private\n * @function\n * @param {Function} getKeys\n * @returns {Function}\n */\n var _valuesFrom = _curry(function (getKeys, obj) {\n return map(getKeys(obj), partial(getIn, obj));\n });\n\n /**\n * Builds a predicate to check if an array-like object contains the given value.
\n * Please note that the equality test is made with {@link module:lamb.isSVZ|isSVZ}; so you can\n * check for NaN, but 0 and -0 are the same value.
\n * See also {@link module:lamb.isIn|isIn} for an uncurried version.\n * @example\n * var containsNaN = _.contains(NaN, 0);\n *\n * containsNaN([0, 1, 2, 3, NaN]) // => true\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.isIn|isIn}\n * @param {*} value\n * @param {Number} [fromIndex=0] The position at which to begin searching for the given value.\n * @returns {Function}\n */\n function contains (value, fromIndex) {\n return function (arrayLike) {\n return isIn(arrayLike, value, fromIndex);\n };\n }\n\n /**\n * Checks if all the elements in an array-like object satisfy the given predicate.
\n * The function will stop calling the predicate as soon as it returns a falsy value.
\n * Note that an empty array-like will always produce a true result regardless of the\n * predicate because of [vacuous truth]{@link https://en.wikipedia.org/wiki/Vacuous_truth}.
\n * Also note that unlike the native\n * [Array.prototype.every]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every},\n * this function won't skip deleted or unassigned indexes.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"age\": 12, active: true},\n * {\"name\": \"John\", \"age\": 40, active: true},\n * {\"name\": \"Mario\", \"age\": 17, active: true},\n * {\"name\": \"Paolo\", \"age\": 15, active: true}\n * ];\n * var isAdult = function (user) { return user.age >= 18; };\n * var isActive = _.hasKeyValue(\"active\", true);\n *\n * _.everyIn(persons, isAdult) // => false\n * _.everyIn(persons, isActive) // => true\n *\n * @example Showing the difference with Array.prototype.every:\n * var isDefined = _.not(_.isUndefined);\n * var arr = new Array(5);\n * arr[3] = 99;\n *\n * arr.every(isDefined) // => true\n * _.everyIn(arr, isDefined) // => false\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.every|every}\n * @see {@link module:lamb.some|some}, {@link module:lamb.someIn|someIn}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Boolean}\n */\n var everyIn = _makeArrayChecker(true);\n\n /**\n * A curried version of {@link module:lamb.everyIn|everyIn} expecting a predicate and its optional\n * context to build a function waiting for the array-like to act upon.\n * @example\n * var data = [2, 3, 5, 6, 8];\n * var isEven = function (n) { return n % 2 === 0; };\n * var isInteger = function (n) { return Math.floor(n) === n; };\n * var allEvens = _.every(isEven);\n * var allIntegers = _.every(isInteger);\n *\n * allEvens(data) // => false\n * allIntegers(data) // => true\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.everyIn|everyIn}\n * @see {@link module:lamb.some|some}, {@link module:lamb.someIn|someIn}\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Function}\n */\n var every = _partialWithIteratee(everyIn);\n\n /**\n * Builds an array comprised of all values of the array-like object passing the predicate\n * test.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.filter]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @example\n * var isLowerCase = function (s) { return s.toLowerCase() === s; };\n *\n * _.filter([\"Foo\", \"bar\", \"baZ\"], isLowerCase) // => [\"bar\"]\n *\n * // the function will work with any array-like object\n * _.filter(\"fooBAR\", isLowerCase) // => [\"f\", \"o\", \"o\"]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.filterWith|filterWith}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Array}\n */\n function filter (arrayLike, predicate, predicateContext) {\n var len = arrayLike.length;\n var result = [];\n\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n for (var i = 0; i < len; i++) {\n predicate(arrayLike[i], i, arrayLike) && result.push(arrayLike[i]);\n }\n\n return result;\n }\n\n /**\n * Returns a partial application of {@link module:lamb.filter|filter} that uses the given predicate and\n * the optional context to build a function expecting the array-like object to act upon.\n * @example\n * var isLowerCase = function (s) { return s.toLowerCase() === s; };\n * var getLowerCaseEntries = _.filterWith(isLowerCase);\n *\n * getLowerCaseEntries([\"Foo\", \"bar\", \"baZ\"]) // => [\"bar\"]\n *\n * // array-like objects can be used as well\n * getLowerCaseEntries(\"fooBAR\") // => [\"f\", \"o\", \"o\"]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.filter|filter}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var filterWith = _partialWithIteratee(filter);\n\n /**\n * Searches for an element satisfying the predicate in the given array-like object and returns it if\n * the search is successful. Returns undefined otherwise.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"age\": 12},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"age\": 18},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"age\": 40}\n * ];\n *\n * _.find(persons, _.hasKeyValue(\"age\", 40)) // => {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40}\n * _.find(persons, _.hasKeyValue(\"age\", 41)) // => undefined\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.findWhere|findWhere}\n * @see {@link module:lamb.findIndex|findIndex}, {@link module:lamb.findIndexWhere|findIndexWhere}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {*}\n */\n function find (arrayLike, predicate, predicateContext) {\n var idx = arguments.length === 3 ?\n findIndex(arrayLike, predicate, predicateContext) :\n findIndex(arrayLike, predicate);\n\n return idx === -1 ? void 0 : arrayLike[idx];\n }\n\n /**\n * Searches for an element satisfying the predicate in the given array-like object and returns its\n * index if the search is successful. Returns -1 otherwise.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"age\": 12},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"age\": 18},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"age\": 40}\n * ];\n *\n * _.findIndex(persons, _.hasKeyValue(\"age\", 40)) // => 1\n * _.findIndex(persons, _.hasKeyValue(\"age\", 41)) // => -1\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.findIndexWhere|findIndexWhere}\n * @see {@link module:lamb.find|find}, {@link module:lamb.findWhere|findWhere}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Number}\n */\n function findIndex (arrayLike, predicate, predicateContext) {\n var result = -1;\n\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n for (var i = 0, len = arrayLike.length; i < len; i++) {\n if (predicate(arrayLike[i], i, arrayLike)) {\n result = i;\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Builds a partial application of {@link module:lamb.findIndex|findIndex} expecting the array-like\n * object to search.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var findEvenIdx = _.findIndexWhere(isEven);\n *\n * findEvenIdx([1, 3, 4, 5, 7]) // => 2\n * findEvenIdx([1, 3, 5, 7]) // => -1\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.findIndex|findIndex}\n * @see {@link module:lamb.find|find}, {@link module:lamb.findWhere|findWhere}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var findIndexWhere = _partialWithIteratee(findIndex);\n\n /**\n * Builds a partial application of {@link module:lamb.find|find} expecting the array-like object\n * to search.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var findEven = _.findWhere(isEven);\n *\n * findEven([1, 3, 4, 5, 7]) // => 4\n * findEven([1, 3, 5, 7]) // => undefined\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.find|find}\n * @see {@link module:lamb.findIndex|findIndex}, {@link module:lamb.findIndexWhere|findIndexWhere}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var findWhere = _partialWithIteratee(find);\n\n /**\n * Executes the provided iteratee for each element of the given array-like object.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.forEach]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @example Adding a CSS class to all elements of a NodeList in a browser environment\n * var addClass = _.curry(function (className, element) {\n * element.classList.add(className);\n * });\n * var paragraphs = document.querySelectorAll(\"#some-container p\");\n *\n * _.forEach(paragraphs, addClass(\"main\"));\n * // each \"p\" element in the container will have the \"main\" class now\n *\n * @memberof module:lamb\n * @category Array\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Undefined}\n */\n function forEach (arrayLike, iteratee, iterateeContext) {\n if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n for (var i = 0, len = arrayLike.length >>> 0; i < len; i++) {\n iteratee(arrayLike[i], i, arrayLike);\n }\n }\n\n /**\n * Checks if an array-like object contains the given value.
\n * Please note that the equality test is made with {@link module:lamb.isSVZ|isSVZ}; so you can\n * check for NaN, but 0 and -0 are the same value.
\n * See also {@link module:lamb.contains|contains} for a curried version building a predicate.\n * @example\n * var numbers = [0, 1, 2, 3, NaN];\n *\n * _.isIn(numbers, 1) // => true\n * _.isIn(numbers, 0) // => true\n * _.isIn(numbers, -0) // => true\n * _.isIn(numbers, NaN) // => true\n * _.isIn(numbers, 2, 3) // => false\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.contains|contains}\n * @param {ArrayLike} arrayLike\n * @param {*} value\n * @param {Number} [fromIndex=0] The position at which to begin searching for the given value.\n * @returns {Boolean}\n */\n function isIn (arrayLike, value, fromIndex) {\n var result = false;\n\n for (var i = fromIndex >>> 0, len = arrayLike.length; i < len; i++) {\n if (isSVZ(value, arrayLike[i])) {\n result = true;\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Builds a new array by applying the iteratee function to each element of the\n * received array-like object.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.map]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @example\n * _.map([\"Joe\", \"Mario\", \"Jane\"], _.invoker(\"toUpperCase\")) // => [\"JOE\", \"MARIO\", \"JANE\"]\n *\n * _.map([4, 9, 16], Math.sqrt); // => [2, 3, 4]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.mapWith|mapWith}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Array}\n */\n function map (arrayLike, iteratee, iterateeContext) {\n var len = arrayLike.length >>> 0;\n var result = Array(len);\n\n if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n for (var i = 0; i < len; i++) {\n result[i] = iteratee(arrayLike[i], i, arrayLike);\n }\n\n return result;\n }\n\n /**\n * Builds a partial application of {@link module:lamb.map|map} using the given iteratee and the\n * optional context. The resulting function expects the array-like object to act upon.\n * @example\n * var square = function (n) { return n * n; };\n * var getSquares = _.mapWith(square);\n *\n * getSquares([1, 2, 3, 4, 5]) // => [1, 4, 9, 16, 25]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.map|map}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {function}\n */\n var mapWith = _partialWithIteratee(map);\n\n /**\n * Reduces (or folds) the values of an array-like object, starting from the first, to a new\n * value using the provided accumulator function.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.reduce]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @example\n * _.reduce([1, 2, 3, 4], _.add) // => 10\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.reduceRight|reduceRight}\n * @see {@link module:lamb.reduceWith|reduceWith}, {@link module:lamb.reduceRightWith|reduceRightWith}\n * @param {ArrayLike} arrayLike\n * @param {AccumulatorCallback} accumulator\n * @param {*} [initialValue]\n * @returns {*}\n */\n var reduce = _makeReducer(1);\n\n /**\n * Same as {@link module:lamb.reduce|reduce}, but starts the fold operation from the last\n * element instead.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.reduceRight]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.reduce|reduce}\n * @see {@link module:lamb.reduceWith|reduceWith}, {@link module:lamb.reduceRightWith|reduceRightWith}\n * @param {ArrayLike} arrayLike\n * @param {AccumulatorCallback} accumulator\n * @param {*} [initialValue]\n * @returns {*}\n */\n var reduceRight = _makeReducer(-1);\n\n /**\n * A partial application of {@link module:lamb.reduce|reduceRight} that uses the\n * provided accumulator and the optional initialValue to\n * build a function expecting the array-like object to act upon.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.reduceRightWith(_.add)(arr) // => 15\n * _.reduceRightWith(_.subtract)(arr) // => -5\n * _.reduceRightWith(_.subtract, 0)(arr) // => -15\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.reduceWith|reduceWith}\n * @see {@link module:lamb.reduce|reduce}, {@link module:lamb.reduce|reduceRight}\n * @param {AccumulatorCallback} accumulator\n * @param {*} [initialValue]\n * @returns {Function}\n */\n var reduceRightWith = _partialWithIteratee(reduceRight);\n\n /**\n * A partial application of {@link module:lamb.reduce|reduce} that uses the\n * provided accumulator and the optional initialValue to\n * build a function expecting the array-like object to act upon.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.reduceWith(_.add)(arr) // => 15\n * _.reduceWith(_.subtract)(arr) // => -13\n * _.reduceWith(_.subtract, 0)(arr) // => -15\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.reduceRightWith|reduceRightWith}\n * @see {@link module:lamb.reduce|reduce}, {@link module:lamb.reduce|reduceRight}\n * @param {AccumulatorCallback} accumulator\n * @param {*} [initialValue]\n * @returns {Function}\n */\n var reduceWith = _partialWithIteratee(reduce);\n\n /**\n * Builds an array by extracting a portion of an array-like object.
\n * It's a generic version of [Array.prototype.slice]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice}.\n * @example\n * _.slice([\"foo\", \"bar\", \"baz\"], 0, 2) // => [\"foo\", \"bar\"]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {ArrayLike} arrayLike - Any array like object.\n * @param {Number} [start=0] - Zero-based index at which to begin extraction.\n * @param {Number} [end=arrayLike.length] - Zero-based index at which to end extraction.\n * Extracts up to but not including end.\n * @returns {Array}\n */\n var slice = generic(_arrayProto.slice);\n\n /**\n * Checks if at least one element in an array-like object satisfies the given predicate.
\n * The function will stop calling the predicate as soon as it returns a truthy value.
\n * Note that unlike the native\n * [Array.prototype.some]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some},\n * this function won't skip deleted or unassigned indexes.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"age\": 12, active: false},\n * {\"name\": \"John\", \"age\": 40, active: false},\n * {\"name\": \"Mario\", \"age\": 17, active: false},\n * {\"name\": \"Paolo\", \"age\": 15, active: false}\n * ];\n * var isAdult = function (user) { return user.age >= 18; };\n * var isActive = _.hasKeyValue(\"active\", true);\n *\n * _.someIn(persons, isAdult) // => true\n * _.someIn(persons, isActive) // => false\n *\n * @example Showing the difference with Array.prototype.some:\n * var arr = new Array(5);\n * arr[3] = 99;\n *\n * arr.some(_.isUndefined) // => false\n * _.someIn(arr, _.isUndefined) // => true\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.some|some}\n * @see {@link module:lamb.every|every}, {@link module:lamb.everyIn|everyIn}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Boolean}\n */\n var someIn = _makeArrayChecker(false);\n\n /**\n * A curried version of {@link module:lamb.someIn|someIn} expecting a predicate and its optional\n * context to build a function waiting for the array-like to act upon.\n * @example\n * var data = [1, 3, 5, 6, 7, 8];\n * var isEven = function (n) { return n % 2 === 0; };\n * var isInteger = function (n) { return Math.floor(n) === n; };\n * var containsEvens = _.some(isEven);\n * var containsStrings = _.some(_.isType(\"String\"));\n *\n * containsEvens(data) // => true\n * containsStrings(data) // => false\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.someIn|someIn}\n * @see {@link module:lamb.every|every}, {@link module:lamb.everyIn|everyIn}\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Function}\n */\n var some = _partialWithIteratee(someIn);\n\n lamb.contains = contains;\n lamb.every = every;\n lamb.everyIn = everyIn;\n lamb.filter = filter;\n lamb.filterWith = filterWith;\n lamb.find = find;\n lamb.findIndex = findIndex;\n lamb.findIndexWhere = findIndexWhere;\n lamb.findWhere = findWhere;\n lamb.forEach = forEach;\n lamb.isIn = isIn;\n lamb.map = map;\n lamb.mapWith = mapWith;\n lamb.reduce = reduce;\n lamb.reduceRight = reduceRight;\n lamb.reduceRightWith = reduceRightWith;\n lamb.reduceWith = reduceWith;\n lamb.slice = slice;\n lamb.some = some;\n lamb.someIn = someIn;\n\n /**\n * Accepts a series of functions and builds a function that applies the received\n * arguments to each one and returns the first non-undefined value.
\n * Meant to work in sinergy with {@link module:lamb.condition|condition} and\n * {@link module:lamb.invoker|invoker}, can be useful as a strategy pattern for functions,\n * to mimic conditional logic and also to build polymorphic functions.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var filterString = _.compose(_.invoker(\"join\", \"\"), _.filter);\n * var filterAdapter = _.adapter(\n * _.invoker(\"filter\"),\n * _.condition(_.isType(\"String\"), filterString)\n * );\n *\n * filterAdapter([1, 2, 3, 4, 5, 6], isEven) // => [2, 4, 6]\n * filterAdapter(\"123456\", isEven) // => \"246\"\n * filterAdapter({}, isEven) // => undefined\n *\n * // obviously it's composable\n * var filterWithDefault = _.adapter(filterAdapter, _.always(\"Not implemented\"));\n *\n * filterWithDefault([1, 2, 3, 4, 5, 6], isEven) // => [2, 4, 6]\n * filterWithDefault(\"123456\", isEven) // => \"246\"\n * filterWithDefault({}, isEven) // => \"Not implemented\"\n *\n * @memberof module:lamb\n * @category Logic\n * @param {...Function} fn\n * @returns {Function}\n */\n function adapter () {\n var functions = list.apply(null, arguments);\n\n return function () {\n var len = functions.length;\n var result;\n\n for (var i = 0; i < len; i++) {\n result = functions[i].apply(this, arguments);\n\n if (!isUndefined(result)) {\n break;\n }\n }\n\n return result;\n };\n }\n\n /**\n * Accepts a series of predicates and builds a new one that returns true if they are all satisfied\n * by the same arguments. The functions in the series will be applied one at a time until a\n * false value is produced, which is returned immediately.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var isPositive = function (n) { return n > 0; };\n * var isPositiveEven = _.allOf(isEven, isPositive);\n *\n * isPositiveEven(-2) // => false\n * isPositiveEven(11) // => false\n * isPositiveEven(6) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.anyOf|anyOf}\n * @param {...Function} predicate\n * @returns {Function}\n */\n function allOf () {\n var predicates = list.apply(null, arguments);\n\n return function () {\n for (var i = 0, len = predicates.length; i < len; i++) {\n if (!predicates[i].apply(this, arguments)) {\n return false;\n }\n }\n\n return true;\n };\n }\n\n /**\n * Accepts a series of predicates and builds a new one that returns true if at least one of them is\n * satisfied by the received arguments. The functions in the series will be applied one at a time\n * until a true value is produced, which is returned immediately.\n * @example\n * var users = [\n * {id: 1, name: \"John\", group: \"guest\"},\n * {id: 2, name: \"Jane\", group: \"root\"},\n * {id: 3, name: \"Mario\", group: \"admin\"}\n * ];\n * var isInGroup = _.partial(_.hasKeyValue, \"group\");\n * var isSuperUser = _.anyOf(isInGroup(\"admin\"), isInGroup(\"root\"));\n *\n * isSuperUser(users[0]) // => false\n * isSuperUser(users[1]) // => true\n * isSuperUser(users[2]) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.allOf|allOf}\n * @param {...Function} predicate\n * @returns {Function}\n */\n function anyOf () {\n var predicates = list.apply(null, arguments);\n\n return function () {\n for (var i = 0, len = predicates.length; i < len; i++) {\n if (predicates[i].apply(this, arguments)) {\n return true;\n }\n }\n\n return false;\n };\n }\n\n /**\n * Builds a function that will apply the received arguments to trueFn,\n * if the predicate is satisfied with the same arguments, or to falseFn otherwise.
\n * If falseFn isn't provided and the predicate isn't satisfied the function\n * will return undefined.
\n * Although you can use other conditions as trueFn or falseFn,\n * it's probably better to use {@link module:lamb.adapter|adapter} to build more complex behaviours.
\n * See also {@link module:lamb.unless|unless} and {@link module:lamb.when|when} as they are\n * shortcuts to common use cases.\n * @example\n * var isEven = function (n) { return n % 2 === 0};\n * var halve = function (n) { return n / 2; };\n * var double = function (n) { return n * 2; };\n * var halveEvenAndDoubleOdd = _.condition(isEven, halve, double);\n *\n * halveEvenAndDoubleOdd(5) // => 10\n * halveEvenAndDoubleOdd(6) // => 3\n *\n * var halveIfNumber = _.condition(_.isType(\"Number\"), halve);\n *\n * halveIfNumber(2) // => 1\n * halveIfNumber(\"2\") // => undefined\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.unless|unless}\n * @see {@link module:lamb.when|when}\n * @param {Function} predicate\n * @param {Function} trueFn\n * @param {Function} [falseFn]\n * @returns {Function}\n */\n function condition (predicate, trueFn, falseFn) {\n return function () {\n if (predicate.apply(this, arguments)) {\n return trueFn.apply(this, arguments);\n } else if (falseFn) {\n return falseFn.apply(this, arguments);\n } else {\n return void 0;\n }\n };\n }\n\n /**\n * Verifies that the two supplied values are the same value using the \"SameValue\" comparison.
\n * Note that this doesn't behave as the strict equality operator, but rather as a shim of ES6's\n * [Object.is]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is}.\n * Differences are that 0 and -0 aren't the same value and, finally,\n * NaN is equal to itself.
\n * See also {@link module:lamb.isSVZ|isSVZ} which performs the check using the \"SameValueZero\" comparison.\n * @example\n * var testObject = {};\n *\n * _.is({}, testObject) // => false\n * _.is(testObject, testObject) // => true\n * _.is(\"foo\", \"foo\") // => true\n * _.is(0, -0) // => false\n * _.is(0 / 0, NaN) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @see [SameValue comparison]{@link http://www.ecma-international.org/ecma-262/6.0/#sec-samevalue}\n * @see [SameValueZero comparison]{@link http://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero}\n * @param {*} a\n * @param {*} b\n * @returns {Boolean}\n */\n function is (a, b) {\n return a === 0 && b === 0 ? 1 / a === 1 / b : isSVZ(a, b);\n }\n\n /**\n * Verifies that the first given value is greater than the second.\n * @example\n * var pastDate = new Date(2010, 2, 12);\n * var today = new Date();\n *\n * _.isGT(today, pastDate) // => true\n * _.isGT(pastDate, today) // => false\n * _.isGT(3, 4) // => false\n * _.isGT(3, 3) // => false\n * _.isGT(3, 2) // => true\n * _.isGT(0, -0) // => false\n * _.isGT(-0, 0) // => false\n * _.isGT(\"a\", \"A\") // => true\n * _.isGT(\"b\", \"a\") // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Number|String|Date|Boolean} a\n * @param {Number|String|Date|Boolean} b\n * @returns {Boolean}\n */\n function isGT (a, b) {\n return a > b;\n }\n\n /**\n * Verifies that the first given value is greater than or equal to the second.\n * Regarding equality, beware that this is simply a wrapper for the native operator,\n * so -0 === 0.\n * @example\n * _.isGTE(3, 4) // => false\n * _.isGTE(3, 3) // => true\n * _.isGTE(3, 2) // => true\n * _.isGTE(0, -0) // => true\n * _.isGTE(-0, 0) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Number|String|Date|Boolean} a\n * @param {Number|String|Date|Boolean} b\n * @returns {Boolean}\n */\n function isGTE (a, b) {\n return a >= b;\n }\n\n /**\n * Verifies that the first given value is less than the second.\n * @example\n * var pastDate = new Date(2010, 2, 12);\n * var today = new Date();\n *\n * _.isLT(today, pastDate) // => false\n * _.isLT(pastDate, today) // => true\n * _.isLT(3, 4) // => true\n * _.isLT(3, 3) // => false\n * _.isLT(3, 2) // => false\n * _.isLT(0, -0) // => false\n * _.isLT(-0, 0) // => false\n * _.isLT(\"a\", \"A\") // => false\n * _.isLT(\"a\", \"b\") // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Number|String|Date|Boolean} a\n * @param {Number|String|Date|Boolean} b\n * @returns {Boolean}\n */\n function isLT (a, b) {\n return a < b;\n }\n\n /**\n * Verifies that the first given value is less than or equal to the second.\n * Regarding equality, beware that this is simply a wrapper for the native operator,\n * so -0 === 0.\n * @example\n * _.isLTE(3, 4) // => true\n * _.isLTE(3, 3) // => true\n * _.isLTE(3, 2) // => false\n * _.isLTE(0, -0) // => true\n * _.isLTE(-0, 0) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Number|String|Date|Boolean} a\n * @param {Number|String|Date|Boolean} b\n * @returns {Boolean}\n */\n function isLTE (a, b) {\n return a <= b;\n }\n\n /**\n * A simple negation of {@link module:lamb.is|is}, exposed for convenience.\n * @example\n * _.isNot(\"foo\", \"foo\") // => false\n * _.isNot(0, -0) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @function\n * @param {*} valueA\n * @param {*} valueB\n * @returns {Boolean}\n */\n var isNot = not(is);\n\n /**\n * Verifies that the two supplied values are the same value using the \"SameValueZero\" comparison.
\n * With this comparison NaN is equal to itself, but 0 and -0 are\n * considered the same value.
\n * See also {@link module:lamb.is|is} to perform a \"SameValue\" comparison.\n * @example\n * var testObject = {};\n *\n * _.isSVZ({}, testObject) // => false\n * _.isSVZ(testObject, testObject) // => true\n * _.isSVZ(\"foo\", \"foo\") // => true\n * _.isSVZ(0, -0) // => true\n * _.isSVZ(0 / 0, NaN) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @see [SameValue comparison]{@link http://www.ecma-international.org/ecma-262/6.0/#sec-samevalue}\n * @see [SameValueZero comparison]{@link http://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero}\n * @param {*} a\n * @param {*} b\n * @returns {Boolean}\n */\n function isSVZ (a, b) {\n // eslint-disable-next-line no-self-compare\n return a !== a ? b !== b : a === b;\n }\n\n /**\n * Returns a predicate that negates the given one.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var isOdd = _.not(isEven);\n *\n * isOdd(5) // => true\n * isOdd(4) // => false\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Function} predicate\n * @returns {Function}\n */\n function not (predicate) {\n return function () {\n return !predicate.apply(this, arguments);\n };\n }\n\n /**\n * Builds a unary function that will check its argument against the given predicate.\n * If the predicate isn't satisfied, the provided fn function will be\n * applied to the same value. The received argument is returned as it is otherwise.
\n * See {@link module:lamb.when|when} for the opposite behaviour.
\n * It's a shortcut for a common use case of {@link module:lamb.condition|condition},\n * where its trueFn parameter is the [identity function]{@link module:lamb.identity}.\n * @example\n * var isEven = function (n) { return n % 2 === 0};\n * var halve = function (n) { return n / 2; };\n * var halveUnlessIsEven = _.unless(isEven, halve);\n *\n * halveUnlessIsEven(5) // => 2.5\n * halveUnlessIsEven(6) // => 6\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.condition|condition}\n * @see {@link module:lamb.when|when}\n * @param {Function} predicate\n * @param {Function} fn\n * @returns {Function}\n */\n function unless (predicate, fn) {\n return function (value) {\n return predicate.call(this, value) ? value : fn.call(this, value);\n };\n }\n\n /**\n * Builds a unary function that will check its argument against the given predicate.\n * If the predicate is satisfied, the provided fn function will be\n * applied to the same value. The received argument is returned as it is otherwise.
\n * See {@link module:lamb.unless|unless} for the opposite behaviour.
\n * It's a shortcut for a common use case of {@link module:lamb.condition|condition},\n * where its falseFn parameter is the [identity function]{@link module:lamb.identity}.\n * @example\n * var isEven = function (n) { return n % 2 === 0};\n * var halve = function (n) { return n / 2; };\n * var halveIfEven = _.when(isEven, halve);\n *\n * halveIfEven(5) // => 5\n * halveIfEven(6) // => 3\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.condition|condition}\n * @see {@link module:lamb.unless|unless}\n * @param {Function} predicate\n * @param {Function} fn\n * @returns {Function}\n */\n function when (predicate, fn) {\n return function (value) {\n return predicate.call(this, value) ? fn.call(this, value) : value;\n };\n }\n\n lamb.adapter = adapter;\n lamb.allOf = allOf;\n lamb.anyOf = anyOf;\n lamb.condition = condition;\n lamb.is = is;\n lamb.isGT = isGT;\n lamb.isGTE = isGTE;\n lamb.isLT = isLT;\n lamb.isLTE = isLTE;\n lamb.isNot = isNot;\n lamb.isSVZ = isSVZ;\n lamb.not = not;\n lamb.unless = unless;\n lamb.when = when;\n\n /**\n * Adds two numbers.\n * @example\n * _.add(4, 5) // => 9\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function add (a, b) {\n return a + b;\n }\n\n /**\n * \"Clamps\" a number within the given limits.\n * @example\n * _.clamp(-5, 0, 10) // => 0\n * _.clamp(5, 0, 10) // => 5\n * _.clamp(15, 0, 10) // => 10\n * _.clamp(0, 0, 10) // => 0\n * _.clamp(10, 0, 10) // => 10\n * _.is(_.clamp(-0, 0, 10), -0) // => true\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} n\n * @param {Number} min\n * @param {Number} max\n * @returns {Number}\n */\n function clamp (n, min, max) {\n return n < min ? min : n > max ? max : n;\n }\n\n /**\n * Divides two numbers.\n * @example\n * _.divide(5, 2) // => 2.5\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function divide (a, b) {\n return a / b;\n }\n\n /**\n * Generates a sequence of values of the desired length with the provided iteratee.\n * The values being iterated, and received by the iteratee, are the results generated so far.\n * @example\n * var fibonacci = function (n, idx, results) {\n * return n + (results[idx - 1] || 0);\n * };\n *\n * _.generate(1, 10, fibonacci) // => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n *\n * @memberof module:lamb\n * @category Math\n * @param {*} start - The starting value\n * @param {Number} len - The desired length for the sequence\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Array}\n */\n function generate (start, len, iteratee, iterateeContext) {\n var result = [start];\n\n if (arguments.length === 4) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n for (var i = 0, limit = len - 1; i < limit; i++) {\n result.push(iteratee(result[i], i, result));\n }\n\n return result;\n }\n\n /**\n * Performs the modulo operation and should not be confused with the\n * {@link module:lamb.remainder|remainder}.\n * The function performs a floored division to calculate the result and not\n * a truncated one, hence the sign of the dividend is not kept, unlike the\n * {@link module:lamb.remainder|remainder}.\n * @example\n * _.modulo(5, 3) // => 2\n * _.remainder(5, 3) // => 2\n *\n * _.modulo(-5, 3) // => 1\n * _.remainder(-5, 3) // => -2\n *\n * @memberof module:lamb\n * @category Math\n * @see {@link http://en.wikipedia.org/wiki/Modulo_operation}\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function modulo (a, b) {\n return a - (b * Math.floor(a / b));\n }\n\n /**\n * Multiplies two numbers.\n * @example\n * _.multiply(5, 3) // => 15\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function multiply (a, b) {\n return a * b;\n }\n\n /**\n * Generates a random integer between two given integers, both included.\n * Note that no safety measure is taken if the provided arguments aren't integers, so\n * you may end up with unexpected (not really) results.\n * For example randomInt(0.1, 1.2) could be 2.\n * @example\n *\n * _.randomInt(1, 10) // => an integer >=1 && <= 10\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} min\n * @param {Number} max\n * @returns {Number}\n */\n function randomInt (min, max) {\n return Math.floor(Math.random() * (max - min + 1) + min);\n }\n\n /**\n * Generates an arithmetic progression of numbers starting from start up to,\n * but not including, limit, using the given step.\n * @example\n * _.range(2, 10) // => [2, 3, 4, 5, 6, 7, 8, 9]\n * _.range(2, 10, 0) // => [2]\n * _.range(1, -10, -2) // => [1, -1, -3, -5, -7, -9]\n * _.range(1, -10, 2) // => [1]\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} start\n * @param {Number} limit\n * @param {Number} [step=1]\n * @returns {Number[]}\n */\n function range (start, limit, step) {\n if (step === 0 || arguments.length < 2) {\n return [start];\n }\n\n if (!step) {\n step = 1;\n }\n\n var len = Math.max(Math.ceil((limit - start) / step), 0);\n\n return generate(start, len, partial(add, step));\n }\n\n /**\n * Gets the remainder of the division of two numbers.\n * Not to be confused with the {@link module:lamb.modulo|modulo} as the remainder\n * keeps the sign of the dividend and may lead to some unexpected results.\n * @example\n * // example of wrong usage of the remainder\n * // (in this case the modulo operation should be used)\n * var isOdd = function (n) { return _.remainder(n, 2) === 1; };\n * isOdd(-3) // => false as -3 % 2 === -1\n *\n * @memberof module:lamb\n * @category Math\n * @see {@link http://en.wikipedia.org/wiki/Modulo_operation}\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function remainder (a, b) {\n return a % b;\n }\n\n /**\n * Subtracts two numbers.\n * @example\n * _.subtract(5, 3) // => 2\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function subtract (a, b) {\n return a - b;\n }\n\n lamb.add = add;\n lamb.clamp = clamp;\n lamb.divide = divide;\n lamb.generate = generate;\n lamb.modulo = modulo;\n lamb.multiply = multiply;\n lamb.randomInt = randomInt;\n lamb.range = range;\n lamb.remainder = remainder;\n lamb.subtract = subtract;\n\n /**\n * Verifies if a value is null or undefined.\n * @example\n * _.isNil(NaN) // => false\n * _.isNil({}) // => false\n * _.isNil(null) // => true\n * _.isNil(void 0) // => true\n * _.isNil() // => true\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.isNull|isNull}\n * @see {@link module:lamb.isUndefined|isUndefined}\n * @param {*} value\n * @returns {Boolean}\n */\n function isNil (value) {\n return isNull(value) || isUndefined(value);\n }\n\n /**\n * Verifies if a value is null.\n * @example\n * _.isNull(null) // => true\n * _.isNull(void 0) // => false\n * _.isNull(false) // => false\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.isNil|isNil} if you want to check for undefined too.\n * @param {*} value\n * @returns {Boolean}\n */\n function isNull (value) {\n return value === null;\n }\n\n /**\n * Builds a predicate that expects a value to check against the specified type.\n * @example\n * var isString = _.isType(\"String\");\n *\n * isString(\"Hello\") // => true\n * isString(new String(\"Hi\")) // => true\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.type|type}\n * @param {String} typeName\n * @returns {Function}\n */\n function isType (typeName) {\n return function (value) {\n return type(value) === typeName;\n };\n }\n\n /**\n * Verifies if a value is undefined.\n * @example\n * _.isUndefined(null) // => false\n * _.isUndefined(void 0) // => true\n * _.isUndefined(false) // => false\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.isNil|isNil} if you want to check for null too.\n * @param {*} value\n * @returns {Boolean}\n */\n function isUndefined (value) {\n return value === void 0;\n }\n\n /**\n * Retrieves the \"type tag\" from the given value.\n * @example\n * var x = 5;\n * var y = new Number(5);\n *\n * typeof x // => \"number\"\n * typeof y // => \"object\"\n * _.type(x) // => \"Number\"\n * _.type(y) // => \"Number\"\n *\n * _.type(Object.prototype.toString) // => \"Function\"\n * _.type(/a/) // => \"RegExp\"\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.isType|isType}\n * @param {*} value\n * @returns {String}\n */\n function type (value) {\n return _objectProto.toString.call(value).slice(8, -1);\n }\n\n lamb.isNil = isNil;\n lamb.isNull = isNull;\n lamb.isType = isType;\n lamb.isUndefined = isUndefined;\n lamb.type = type;\n\n /**\n * A curried version of {@link module:lamb.getIndex|getIndex} that uses the provided index\n * to build a function expecting the array-like object holding the element we want to retrieve.\n * @example\n * var getFifthElement = _.getAt(4);\n *\n * getFifthElement([1, 2, 3, 4, 5]) // => 5\n * getFifthElement(\"foo bar\") // => \"b\"\n * getFifthElement([]) // => undefined\n * getFifthElement(\"foo\") // => undefined\n *\n * @example Using negative indexes\n * _.getAt(-2)([1, 2, 3]) // => 2\n * _.getAt(-3)(\"foo\") // => \"f\"\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.getIndex|getIndex}\n * @see {@link module:lamb.head|head} and {@link module:lamb.last|last} for common use cases shortcuts.\n * @param {Number} index\n * @returns {Function}\n */\n function getAt (index) {\n return function (arrayLike) {\n return getIndex(arrayLike, index);\n };\n }\n\n /**\n * Returns the value of the object property with the given key.\n * @example\n * var user = {name: \"John\"};\n *\n * _.getIn(user, \"name\") // => \"John\";\n * _.getIn(user, \"surname\") // => undefined\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.getKey|getKey}\n * @see {@link module:lamb.getPath|getPath}, {@link module:lamb.getPathIn|getPathIn}\n * @param {Object} obj\n * @param {String} key\n * @returns {*}\n */\n function getIn (obj, key) {\n return obj[key];\n }\n\n /**\n * Retrieves the element at the given index in an array-like object.
\n * Like {@link module:lamb.slice|slice} the index can be negative.
\n * If the index isn't supplied, or if its value isn't an integer within the array-like bounds,\n * the function will return undefined.
\n * getIndex will throw an exception when receives null or\n * undefined in place of an array-like object, but returns undefined\n * for any other value.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.getIndex(arr, 1) // => 2\n * _.getIndex(arr, -1) // => 5\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.getAt|getAt}\n * @see {@link module:lamb.head|head} and {@link module:lamb.last|last} for common use cases shortcuts.\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @returns {*}\n */\n function getIndex (arrayLike, index) {\n var idx = _getNaturalIndex(arrayLike, index);\n\n return isUndefined(idx) ? idx : arrayLike[idx];\n }\n\n /**\n * A curried version of {@link module:lamb.getIn|getIn}.
\n * Receives a property name and builds a function expecting the object from which we want to retrieve\n * the property.\n * @example\n * var user1 = {name: \"john\"};\n * var user2 = {name: \"jane\"};\n * var getName = _.getKey(\"name\");\n *\n * getName(user1) // => \"john\"\n * getName(user2) // => \"jane\"\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.getIn|getIn}\n * @see {@link module:lamb.getPath|getPath}, {@link module:lamb.getPathIn|getPathIn}\n * @param {String} key\n * @returns {Function}\n */\n function getKey (key) {\n return function (obj) {\n return getIn(obj, key);\n };\n }\n\n /**\n * Builds a partial application of {@link module:lamb.getPathIn|getPathIn} with the given\n * path and separator, expecting the object to act upon.
\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * login: {\n * \"user.name\": \"jdoe\",\n * password: \"abc123\"\n * }\n * };\n *\n * var getPwd = _.getPath(\"login.password\");\n * var getUsername = _.getPath(\"login/user.name\", \"/\");\n *\n * getPwd(user) // => \"abc123\";\n * getUsername(user) // => \"jdoe\"\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.getPathIn|getPathIn}\n * @see {@link module:lamb.getIn|getIn}, {@link module:lamb.getKey|getKey}\n * @param {String} path\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function getPath (path, separator) {\n return partial(getPathIn, _, path, separator);\n }\n\n /**\n * Gets a nested property value from an object using the given path.
\n * The path is a string with property names separated by dots by default, but\n * it can be customised with the optional third parameter.
\n * You can use integers in the path, even negative ones, to refer to array-like\n * object indexes, but the priority will be given to existing object keys:\n * the last example explains this particular case.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * login: {\n * \"user.name\": \"jdoe\",\n * password: \"abc123\"\n * },\n * scores: [\n * {id: 1, value: 10},\n * {id: 2, value: 20},\n * {id: 3, value: 30}\n * ]\n * };\n *\n * _.getPathIn(user, \"name\") // => \"John\"\n * _.getPathIn(user, \"login.password\") // => \"abc123\";\n * _.getPathIn(user, \"login/user.name\", \"/\") // => \"jdoe\"\n * _.getPathIn(user, \"name.foo\") // => undefined\n * _.getPathIn(user, \"name.foo.bar\") // => undefined\n *\n * @example Accessing array-like objects indexes:\n * _.getPathIn(user, \"login.password.1\") // => \"b\"\n * _.getPathIn(user, \"scores.0\") // => {id: 1, value: 10}\n * _.getPathIn(user, \"scores.-1.value\") // => 30\n *\n * @example Priority will be given to existing object keys over indexes:\n * _.getPathIn(user, \"scores.-1\") // => {id: 3, value: 30}\n *\n * // let's do something funny\n * user.scores[\"-1\"] = \"foo bar\";\n *\n * _.getPathIn(user, \"scores.-1\") // => \"foo bar\";\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.getPath|getPath}\n * @see {@link module:lamb.getIn|getIn}, {@link module:lamb.getKey|getKey}\n * @param {Object|ArrayLike} obj\n * @param {String} path\n * @param {String} [separator=\".\"]\n * @returns {*}\n */\n function getPathIn (obj, path, separator) {\n var pathInfo = _getPathInfo(obj, _toPathParts(path, separator), true);\n\n return pathInfo.target;\n }\n\n /**\n * Retrieves the first element of an array-like object.
\n * Just a common use case of {@link module:lamb.getAt|getAt} exposed for convenience.\n * @example\n * _.head([1, 2, 3]) // => 1\n * _.head(\"hello\") // => \"h\"\n * _.head([]) // => undefined\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.last|last}\n * @see {@link module:lamb.getIndex|getIndex}, {@link module:lamb.getAt|getAt}\n * @param {ArrayLike} arrayLike\n * @returns {*}\n */\n var head = getAt(0);\n\n /**\n * Retrieves the last element of an array-like object.
\n * Just a common use case of {@link module:lamb.getAt|getAt} exposed for convenience.\n * @example\n * _.last([1, 2, 3]) // => 3\n * _.last(\"hello\") // => \"o\"\n * _.last([]) // => undefined\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.head|head}\n * @see {@link module:lamb.getIndex|getIndex}, {@link module:lamb.getAt|getAt}\n * @param {ArrayLike} arrayLike\n * @returns {*}\n */\n var last = getAt(-1);\n\n /**\n * Builds a function that creates a copy of an array-like object with the given\n * index changed to the desired value.
\n * If the index is not an integer or if it's out of bounds, the function\n * will return a copy of the original array.
\n * Negative indexes are allowed.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.setAt(2, 99)(arr) // => [1, 2, 99, 4, 5]\n * arr // => [1, 2, 3, 4, 5]\n *\n * _.setAt(10, 99)(arr) // => [1, 2, 3, 4, 5] (not a reference to `arr`)\n *\n * @example Using negative indexes\n * _.setAt(-1, 99)(arr) // => [1, 2, 3, 4, 99]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.setIndex|setIndex}\n * @param {Number} index\n * @param {*} value\n * @returns {Function}\n */\n function setAt (index, value) {\n return function (arrayLike) {\n return _setIndex(arrayLike, index, value);\n };\n }\n\n /**\n * Sets the specified key to the given value in a copy of the provided object.
\n * All the remaining enumerable keys of the source object will be simply copied in the\n * result object without breaking references.
\n * If the specified key is not part of the source object, it will be added to the\n * result.
\n * The main purpose of the function is to work on simple plain objects used as\n * data structures, such as JSON objects, and makes no effort to play nice with\n * objects created from an OOP perspective (it's not worth it).
\n * For example the prototype of the result will be Object's regardless\n * of the source's one.\n * @example\n * var user = {name: \"John\", surname: \"Doe\", age: 30};\n *\n * _.setIn(user, \"name\", \"Jane\") // => {name: \"Jane\", surname: \"Doe\", age: 30}\n * _.setIn(user, \"gender\", \"male\") // => {name: \"John\", surname: \"Doe\", age: 30, gender: \"male\"}\n *x\n * // `user` still is {name: \"John\", surname: \"Doe\", age: 30}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.setKey|setKey}\n * @see {@link module:lamb.setPath|setPath}, {@link module:lamb.setPathIn|setPathIn}\n * @param {Object} source\n * @param {String} key\n * @param {*} value\n * @returns {Object}\n */\n function setIn (source, key, value) {\n if (isNil(source)) {\n throw _makeTypeErrorFor(source, \"object\");\n }\n\n return _setIn(source, key, value);\n }\n\n /**\n * Creates a copy of an array-like object with the given index changed to\n * the desired value.
\n * If the index is not an integer or if it's out of bounds, the function\n * will return a copy of the original array.
\n * Negative indexes are allowed.\n * @example\n * var arr = [1, 2, 3];\n *\n * _.setIndex(arr, 1, 99) // => [1, 99, 3]\n * _.setIndex(arr, -1, 99) // => [1, 2, 99]\n * _.setIndex(arr, 10, 99) // => [1, 2, 3] (not a reference to `arr`)\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.setAt|setAt}\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @param {*} value\n * @returns {Array}\n */\n var setIndex = aritize(_setIndex, 3);\n\n /**\n * Builds a partial application of {@link module:lamb.setIn|setIn} with the provided\n * key and value.
\n * The resulting function expects the object to act upon.
\n * Please refer to {@link module:lamb.setIn|setIn}'s description for explanations about\n * how the copy of the source object is made.\n * @example\n * var user = {name: \"John\", surname: \"Doe\", age: 30};\n * var setAgeTo40 = _.setKey(\"age\", 40);\n *\n * setAgeTo40(user) // => {name: \"john\", surname: \"doe\", age: 40}\n *\n * // `user` still is {name: \"John\", surname: \"Doe\", age: 30}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.setIn|setIn}\n * @see {@link module:lamb.setPath|setPath}, {@link module:lamb.setPathIn|setPathIn}\n * @param {String} key\n * @param {*} value\n * @returns {Function}\n */\n function setKey (key, value) {\n return partial(setIn, _, key, value);\n }\n\n /**\n * Builds a partial application of {@link module:lamb.setPathIn|setPathIn} expecting the\n * object to act upon.
\n * See {@link module:lamb.setPathIn|setPathIn} for more details and examples.\n * @example\n * var user = {id: 1, status: {active: false}};\n * var activate = _.setPath(\"status.active\", true);\n *\n * activate(user) // => {id: 1, status: {active: true}}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.setPathIn|setPathIn}\n * @see {@link module:lamb.setIn|setIn}, {@link module:lamb.setKey|setKey}\n * @param {String} path\n * @param {*} value\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function setPath (path, value, separator) {\n return partial(setPathIn, _, path, value, separator);\n }\n\n /**\n * Allows to change a nested value in a copy of the provided object.
\n * The function will delegate the \"set action\" to {@link module:lamb.setIn|setIn} or\n * {@link module:lamb.setAt|setAt} depending on the value encountered in the path,\n * so please refer to the documentation of those functions for specifics about the\n * implementation.
\n * Note anyway that the distinction will be between Arrays, delegated\n * to {@link module:lamb.setAt|setAt}, and everything else (including array-like objects),\n * which will be delegated to {@link module:lamb.setIn|setIn}.
\n * As a result of that, array-like objects will be converted to objects having numbers as keys\n * and paths targeting non-object values will be converted to empty objects.
\n * You can anyway target array elements using integers in the path, even negative ones, but\n * the priority will be given to existing, and enumerable, object keys.
\n * Non-enumerable properties encountered in the path will be considered as non-existent properties.
\n * Like {@link module:lamb.getPathIn|getPathIn} or {@link module:lamb.getPath|getPath} you can\n * use custom path separators.\n * @example\n * var user = {id: 1, status: {active : false, scores: [2, 4, 6]}};\n *\n * _.setPathIn(user, \"status.active\", true) // => {id: 1, status: {active : true, scores: [2, 4, 6]}}\n *\n * @example Targeting arrays\n * _.setPathIn(user, \"status.scores.0\", 8) // => {id: 1, status: {active : false, scores: [8, 4, 6]}}\n *\n * // you can use negative indexes as well\n * _.setPathIn(user, \"status.scores.-1\", 8) // => {id: 1, status: {active : false, scores: [2, 4, 8]}}\n *\n * @example Arrays can also be part of the path and not necessarily its target\n * var user = {id: 1, scores: [\n * {value: 2, year: \"2000\"},\n * {value: 4, year: \"2001\"},\n * {value: 6, year: \"2002\"}\n * ]};\n *\n * var newUser = _.setPathIn(user, \"scores.0.value\", 8);\n * // \"newUser\" holds:\n * // {id: 1, scores: [\n * // {value: 8, year: \"2000\"},\n * // {value: 4, year: \"2001\"},\n * // {value: 6, year: \"2002\"}\n * // ]}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.setPath|setPath}\n * @see {@link module:lamb.setIn|setIn}, {@link module:lamb.setKey|setKey}\n * @param {Object|Array} source\n * @param {String} path\n * @param {*} value\n * @param {String} [separator=\".\"]\n * @returns {Object|Array}\n */\n function setPathIn (source, path, value, separator) {\n if (isNil(source)) {\n throw _makeTypeErrorFor(source, \"object\");\n }\n\n return _setPathIn(source, _toPathParts(path, separator), value);\n }\n\n /**\n * Builds a function that creates a copy of an array-like object with the given index\n * changed by applying the provided function to its value.
\n * If the index is not an integer or if it's out of bounds, the function will return\n * a copy of the original array.
\n * Negative indexes are allowed.\n * @example\n * var arr = [\"a\", \"b\", \"c\"];\n * var toUpperCase = _.invoker(\"toUpperCase\");\n *\n * _.updateAt(1, toUpperCase)(arr) // => [\"a\", \"B\", \"c\"]\n * _.updateAt(-1, toUpperCase)(arr) // => [\"a\", \"b\", \"C\"]\n * _.updateAt(10, toUpperCase)(arr) // => [\"a\", \"b\", \"c\"] (not a reference to `arr`)\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.updateIndex|updateIndex}\n * @param {Number} index\n * @param {Function} updater\n * @returns {Function}\n */\n function updateAt (index, updater) {\n return function (arrayLike) {\n return _setIndex(arrayLike, index, null, updater);\n };\n }\n\n /**\n * Creates a copy of the given object having the desired key value updated by applying\n * the provided function to it.
\n * This function is meant for updating existing enumerable properties, and for those it\n * will delegate the \"set action\" to {@link module:lamb.setIn|setIn}; a copy of the\n * source is returned otherwise.\n * @example\n * var user = {name: \"John\", visits: 2};\n * var toUpperCase = _.invoker(\"toUpperCase\");\n *\n * _.updateIn(user, \"name\", toUpperCase) // => {name: \"JOHN\", visits: 2}\n * _.updateIn(user, \"surname\", toUpperCase) // => {name: \"John\", visits: 2}\n *\n * @example Non-enumerable properties will be treated as non-existent:\n * var user = Object.create({name: \"John\"}, {visits: {value: 2}});\n * var increment = _.partial(_.add, 1);\n *\n * _.updateIn(user, \"visits\", increment) // => {name: \"John\", visits: 2}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.updateKey|updateKey}\n * @see {@link module:lamb.updatePath|updatePath}, {@link module:lamb.updatePathIn|updatePathIn}\n * @param {Object} source\n * @param {String} key\n * @param {Function} updater\n * @returns {Object}\n */\n function updateIn (source, key, updater) {\n return _isEnumerable(source, key) ?\n _setIn(source, key, updater(source[key])) :\n _merge(enumerables, source);\n }\n\n /**\n * Creates a copy of an array-like object with the given index changed by applying the\n * provided function to its value.
\n * If the index is not an integer or if it's out of bounds, the function will return\n * a copy of the original array.
\n * Negative indexes are allowed.\n * @example\n * var arr = [\"a\", \"b\", \"c\"];\n * var toUpperCase = _.invoker(\"toUpperCase\");\n *\n * _.updateIndex(arr, 1, toUpperCase) // => [\"a\", \"B\", \"c\"]\n * _.updateIndex(arr, -1, toUpperCase) // => [\"a\", \"b\", \"C\"]\n * _.updateIndex(arr, 10, toUpperCase) // => [\"a\", \"b\", \"c\"] (not a reference to `arr`)\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.updateAt|updateAt}\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @param {Function} updater\n * @returns {Array}\n */\n var updateIndex = partial(_setIndex, _, _, null, _);\n\n /**\n * Builds a partial application of {@link module:lamb.updateIn|updateIn} with the provided\n * key and updater, expecting the object to act upon.\n * @example\n * var user = {name: \"John\", visits: 2};\n * var increment = _.partial(_.add, 1);\n * var incrementVisits = _.updateKey(\"visits\", increment);\n *\n * incrementVisits(user) // => {name: \"John\", visits: 3}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.updateIn|updateIn}\n * @see {@link module:lamb.updatePath|updatePath}, {@link module:lamb.updatePathIn|updatePathIn}\n * @param {String} key\n * @param {Function} updater\n * @returns {Function}\n */\n function updateKey (key, updater) {\n return partial(updateIn, _, key, updater);\n }\n\n /**\n * Builds a partial application of {@link module:lamb.updateIn|updateIn} expecting the object to act upon.\n * @example\n * var user = {id: 1, status: {scores: [2, 4, 6], visits: 0}};\n * var increment = _.partial(_.add, 1);\n * var incrementScores = _.updatePath(\"status.scores\", _.mapWith(increment))\n *\n * incrementScores(user) // => {id: 1, status: {scores: [3, 5, 7], visits: 0}}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.updatePathIn|updatePathIn}\n * @see {@link module:lamb.updateIn|updateIn}, {@link module:lamb.updateKey|updateKey}\n * @param {String} path\n * @param {Function} updater\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function updatePath (path, updater, separator) {\n return partial(updatePathIn, _, path, updater, separator);\n }\n\n /**\n * Allows to change a nested value in a copy of the given object by applying the provided\n * function to it.
\n * This function is meant for updating existing enumerable properties, and for those it\n * will delegate the \"set action\" to {@link module:lamb.setPathIn|setPathIn}; a copy of the\n * source is returned otherwise.
\n * Like the other \"path\" functions, negative indexes can be used to access array elements, but\n * the priority will be given to existing, and enumerable, object keys.
\n * @example\n * var user = {id: 1, status: {scores: [2, 4, 6], visits: 0}};\n * var inc = _.partial(_.add, 1);\n *\n * _.updatePathIn(user, \"status.visits\", inc) // => {id: 1, status: {scores: [2, 4, 6]}, visits: 1}\n *\n * @example Targeting arrays\n * _.updatePathIn(user, \"status.scores.0\", inc) // => {id: 1, status: {scores: [3, 4, 6], visits: 0}}\n *\n * // you can use negative indexes as well\n * _.updatePathIn(user, \"status.scores.-1\", inc) // => {id: 1, status: {scores: [2, 4, 7], visits: 0}}\n *\n * @example Arrays can also be part of the path and not necessarily its target\n * var user = {id: 1, scores: [\n * {value: 2, year: \"2000\"},\n * {value: 4, year: \"2001\"},\n * {value: 6, year: \"2002\"}\n * ]};\n *\n * var newUser = _.updatePathIn(user, \"scores.0.value\", increment);\n * // \"newUser\" holds:\n * // {id: 1, scores: [\n * // {value: 3, year: \"2000\"},\n * // {value: 4, year: \"2001\"},\n * // {value: 6, year: \"2002\"}\n * // ]}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.updatePath|updatePath}\n * @see {@link module:lamb.updateIn|updateIn}, {@link module:lamb.updateKey|updateKey}\n * @param {Object|Array} source\n * @param {String} path\n * @param {Function} updater\n * @param {String} [separator=\".\"]\n * @returns {Object|Array}\n */\n function updatePathIn (source, path, updater, separator) {\n var parts = _toPathParts(path, separator);\n var pathInfo = _getPathInfo(source, parts, false);\n\n if (pathInfo.isValid) {\n return _setPathIn(source, parts, updater(pathInfo.target));\n } else {\n return Array.isArray(source) ? slice(source) : _merge(enumerables, source);\n }\n }\n\n lamb.getAt = getAt;\n lamb.getIn = getIn;\n lamb.getIndex = getIndex;\n lamb.getKey = getKey;\n lamb.getPath = getPath;\n lamb.getPathIn = getPathIn;\n lamb.head = head;\n lamb.last = last;\n lamb.setAt = setAt;\n lamb.setIn = setIn;\n lamb.setIndex = setIndex;\n lamb.setKey = setKey;\n lamb.setPath = setPath;\n lamb.setPathIn = setPathIn;\n lamb.updateAt = updateAt;\n lamb.updateIn = updateIn;\n lamb.updateIndex = updateIndex;\n lamb.updateKey = updateKey;\n lamb.updatePath = updatePath;\n lamb.updatePathIn = updatePathIn;\n\n /**\n * Returns an array of items present only in the first of the given arrays.
\n * Note that this function uses the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.\n * @example\n * var a1 = [1, 2, 3, 4];\n * var a2 = [2, 4, 5];\n * var a3 = [4, 5, 3, 1];\n *\n * _.difference(a1, a2) // => [1, 3]\n * _.difference(a1, a2, a3) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @param {Array} array\n * @param {...Array} other\n * @returns {Array}\n */\n function difference (array) {\n var rest = shallowFlatten(map(_argsTail.apply(null, arguments), unary(slice)));\n var isInRest = partial(isIn, rest, _, 0);\n\n return filter(array, not(isInRest));\n }\n\n /**\n * Builds an array without the first n elements of the given array or array-like object.\n * Note that, being this only a shortcut for a specific use case of {@link module:lamb.slice|slice},\n * n can be a negative number.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.drop(arr, 2) // => [3, 4, 5]\n * _.drop(arr, -1) // => [5]\n * _.drop(arr, -10) // => [1, 2, 3, 4, 5]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.dropN|dropN}\n * @see {@link module:lamb.take|take}, {@link module:lamb.takeN|takeN}\n * @see {@link module:lamb.takeWhile|takeWhile}, {@link module:lamb.dropWhile|dropWhile}\n * @param {ArrayLike} arrayLike\n * @param {Number} n\n * @returns {Array}\n */\n var drop = binary(slice);\n\n /**\n * A curried version of {@link module:lamb.drop|drop} that expects the number of elements\n * to drop to build a function waiting for the list to take the elements from.\n * See the note and examples for {@link module:lamb.drop|drop} about passing a negative n.\n * @example\n * var drop2 = _.dropN(2);\n *\n * drop2([1, 2, 3, 4, 5]) // => [3, 4, 5]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.drop|drop}\n * @see {@link module:lamb.take|take}, {@link module:lamb.takeN|takeN}\n * @see {@link module:lamb.takeWhile|takeWhile}, {@link module:lamb.dropWhile|dropWhile}\n * @param {Number} n\n * @returns {Function}\n */\n function dropN (n) {\n return function (arrayLike) {\n return slice(arrayLike, n);\n };\n }\n\n /**\n * Builds a function that drops the first n elements satisfying a predicate\n * from an array or array-like object.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var dropWhileIsEven = _.dropWhile(isEven);\n *\n * dropWhileIsEven([2, 4, 6, 8]) // => []\n * dropWhileIsEven([2, 4, 7, 8]) // => [7, 8]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.takeWhile|takeWhile}\n * @see {@link module:lamb.drop|drop}, {@link module:lamb.dropN|dropN}\n * @see {@link module:lamb.take|take}, {@link module:lamb.takeN|takeN}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n function dropWhile (predicate, predicateContext) {\n var fn = arguments.length === 2 ? _getNumConsecutiveHits : binary(_getNumConsecutiveHits);\n\n return function (arrayLike) {\n return slice(arrayLike, fn(arrayLike, predicate, predicateContext));\n };\n }\n\n /**\n * Similar to {@link module:lamb.map|map}, but if the mapping function returns an array this will\n * be concatenated, rather than pushed, to the final result.\n * @example showing the difference with map\n * var words = [\"foo\", \"bar\"];\n * var toCharArray = function (s) { return s.split(\"\"); };\n *\n * _.map(words, toCharArray) // => [[\"f\", \"o\", \"o\"], [\"b\", \"a\", \"r\"]]\n * _.flatMap(words, toCharArray) // => [\"f\", \"o\", \"o\", \"b\", \"a\", \"r\"]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.flatMapWith|flatMapWith}\n * @param {Array} array\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Array}\n */\n function flatMap (array, iteratee, iterateeContext) {\n if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n return reduce(array, function (result, el, idx, arr) {\n var v = iteratee(el, idx, arr);\n\n if (!Array.isArray(v)) {\n v = [v];\n }\n\n for (var i = 0, len = v.length, rLen = result.length; i < len; i++) {\n result[rLen + i] = v[i];\n }\n\n return result;\n }, []);\n }\n\n /**\n * Builds a partial application of {@link module:lamb.flatMap|flatMap} using the given iteratee\n * and the optional context. The resulting function expects the array to act upon.\n * @example\n * var toCharArray = function (s) { return s.split(\"\"); };\n * var wordsToCharArray = _.flatMapWith(toCharArray);\n *\n * wordsToCharArray([\"foo\", \"bar\"]) // => [\"f\", \"o\", \"o\", \"b\", \"a\", \"r\"]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.flatMap|flatMap}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Function}\n */\n var flatMapWith = _partialWithIteratee(flatMap);\n\n /**\n * Flattens an array.\n * @example showing the difference with shallowFlatten\n * var arr = [1, 2, [3, 4, [5, 6]], 7, 8];\n *\n * _.flatten(arr) // => [1, 2, 3, 4, 5, 6, 7, 8]\n * _.shallowFlatten(arr) // => [1, 2, 3, 4, [5, 6], 7, 8]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.shallowFlatten|shallowFlatten}\n * @param {Array} array\n * @returns {Array}\n */\n function flatten (array) {\n return Array.isArray(array) ? _flatten(array, true, [], 0) : slice(array);\n }\n\n /**\n * Returns a copy of the given array-like object without the last element.\n * @example\n * _.init([1, 2, 3, 4]) // => [1, 2, 3]\n * _.init([1]) // => []\n * _.init([]) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.tail|tail}\n * @see {@link module:lamb.head|head}, {@link module:lamb.last|last}\n * @param {ArrayLike} arrayLike\n * @returns {Array}\n */\n var init = partial(slice, _, 0, -1);\n\n /**\n * Inserts the provided element in a copy of an array-like object at the\n * specified index.
\n * If the index is greater than the length of the array-like, the element\n * will be appended at the end.
\n * Negative indexes are allowed; when a negative index is out of bounds\n * the element will be inserted at the start of the resulting array.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.insert(arr, 3, 99) // => [1, 2, 3, 99, 4, 5]\n * _.insert(arr, -2, 99) // => [1, 2, 3, 99, 4, 5]\n * _.insert(arr, 10, 99) // => [1, 2, 3, 4, 5, 99]\n * _.insert(arr, -10, 99) // => [99, 1, 2, 3, 4, 5]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.insertAt|insertAt}\n * @see {@link module:lamb.sortedInsert|sortedInsert}\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @param {*} element\n * @returns {Array}\n */\n function insert (arrayLike, index, element) {\n var result = slice(arrayLike);\n\n result.splice(index, 0, element);\n\n return result;\n }\n\n /**\n * Builds a partial application of {@link module:lamb.insert|insert}\n * expecting the array-like object to act upon.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.insertAt(3, 99)(arr) // => [1, 2, 3, 99, 4, 5]\n * _.insertAt(-2, 99)(arr) // => [1, 2, 3, 99, 4, 5]\n * _.insertAt(10, 99)(arr) // => [1, 2, 3, 4, 5, 99]\n * _.insertAt(-10, 99)(arr) // => [99, 1, 2, 3, 4, 5]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.insert|insert}\n * @see {@link module:lamb.sortedInsert|sortedInsert}\n * @param {Number} index\n * @param {*} element\n * @returns {Function}\n */\n function insertAt (index, element) {\n return partial(insert, _, index, element);\n }\n\n /**\n * Returns an array of every item that is included in all given arrays.
\n * Note that this function uses the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.\n * @example\n * var a1 = [1, 2, 3, 4];\n * var a2 = [2, 5, 4, 6];\n * var a3 = [5, 6, 7];\n *\n * _.intersection(a1, a2) // => [2, 4]\n * _.intersection(a1, a3) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @param {...Array} array\n * @returns {Array}\n */\n function intersection () {\n var rest = _argsTail.apply(null, arguments);\n\n return filter(uniques(arguments[0]), function (item) {\n return everyIn(rest, contains(item));\n });\n }\n\n /**\n * Generates an array with the values passed as arguments.\n * @example\n * _.list(1, 2, 3) // => [1, 2, 3]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {...*} value\n * @returns {Array}\n */\n var list = _argsToArrayFrom(0);\n\n /**\n * Splits an array-like object in two lists: the first with the elements satisfying the given predicate,\n * the others with the remaining elements.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n *\n * _.partition(numbers, isEven) // => [[2, 4, 6, 8, 10], [1, 3, 5, 7, 9]]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.partitionWith|partitionWith}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Array, Array<*>>}\n */\n function partition (arrayLike, predicate, predicateContext) {\n var result = [[], []];\n var len = arrayLike.length;\n\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n for (var i = 0, el; i < len; i++) {\n el = arrayLike[i];\n result[predicate(el, i, arrayLike) ? 0 : 1].push(el);\n }\n\n return result;\n }\n\n /**\n * Builds a partial application of {@link module:lamb.partition|partition} using the given\n * predicate and the optional context.\n * The resulting function expects the array-like object to act upon.\n * @example\n * var users = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"active\": false},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"active\": true},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"active\": true},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"active\": false}\n * ];\n * var isActive = _.hasKeyValue(\"active\", true);\n * var splitByActiveStatus = _.partitionWith(isActive);\n *\n * splitByActiveStatus(users) // =>\n * // [[\n * // {\"name\": \"John\", \"surname\": \"Doe\", \"active\": true},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\", \"active\": true}\n * // ], [\n * // {\"name\": \"Jane\", \"surname\": \"Doe\", \"active\": false},\n * // {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"active\": false}\n * // ]]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.partition|partition}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var partitionWith = _partialWithIteratee(partition);\n\n /**\n * \"Plucks\" the values of the specified key from a list of objects.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"age\": 12},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"age\": 18},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"age\": 15}\n * ];\n *\n * _.pluck(persons, \"age\") // => [12, 40, 18, 15]\n *\n * var lists = [\n * [1, 2],\n * [3, 4, 5],\n * [6]\n * ];\n *\n * _.pluck(lists, \"length\") // => [2, 3, 1]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.pluckKey|pluckKey}\n * @param {ArrayLike} arrayLike\n * @param {String} key\n * @returns {Array}\n */\n function pluck (arrayLike, key) {\n return map(arrayLike, getKey(key));\n }\n\n /**\n * A curried version of {@link module:lamb.pluck|pluck} expecting the key to retrieve to\n * build a function waiting for the array-like object to act upon.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"age\": 12},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"age\": 18},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"age\": 15}\n * ];\n * var getAges = _.pluckKey(\"age\");\n *\n * getAges(persons) // => [12, 40, 18, 15]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.pluck|pluck}\n * @function\n * @param {String} key\n * @returns {Function}\n */\n var pluckKey = compose(mapWith, getKey);\n\n /**\n * Reverses a copy of the given array-like object.\n * @example\n * var arr = [1, 2, 3];\n *\n * _.reverse(arr) // => [3, 2, 1];\n *\n * // `arr` still is [1, 2, 3]\n *\n * @memberof module:lamb\n * @category Array\n * @param {ArrayLike} arrayLike\n * @returns {Array}\n */\n function reverse (arrayLike) {\n return slice(arrayLike).reverse();\n }\n\n /**\n * Flattens the \"first level\" of an array.\n * @example showing the difference with flatten\n * var arr = [1, 2, [3, 4, [5, 6]], 7, 8];\n *\n * _.flatten(arr) // => [1, 2, 3, 4, 5, 6, 7, 8]\n * _.shallowFlatten(arr) // => [1, 2, 3, 4, [5, 6], 7, 8]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.flatten|flatten}\n * @param {Array} array\n * @returns {Array}\n */\n function shallowFlatten (array) {\n return Array.isArray(array) ? _flatten(array, false, [], 0) : slice(array);\n }\n\n /**\n * Returns a copy of the given array-like object without the first element.\n * @example\n * _.tail([1, 2, 3, 4]) // => [2, 3, 4]\n * _.tail([1]) // => []\n * _.tail([]) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.init|init}\n * @see {@link module:lamb.head|head}, {@link module:lamb.last|last}\n * @param {ArrayLike} arrayLike\n * @returns {Array}\n */\n var tail = partial(slice, _, 1, void 0);\n\n /**\n * Retrieves the first n elements from an array or array-like object.
\n * Note that, being this a shortcut for a common use case of {@link module:lamb.slice|slice},\n * n can be a negative number.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.take(arr, 3) // => [1, 2, 3]\n * _.take(arr, -1) // => [1, 2, 3, 4]\n * _.take(arr, -10) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.takeN|takeN}\n * @see {@link module:lamb.drop|drop}, {@link module:lamb.dropN|dropN}\n * @see {@link module:lamb.takeWhile|takeWhile}, {@link module:lamb.dropWhile|dropWhile}\n * @param {ArrayLike} arrayLike\n * @param {Number} n\n * @returns {Array}\n */\n function take (arrayLike, n) {\n return slice(arrayLike, 0, +n);\n }\n\n /**\n * A curried version of {@link module:lamb.take|take} that expects the number of elements\n * to retrieve to build a function waiting for the list to take the elements from.\n * See the note and examples for {@link module:lamb.take|take} about passing a negative n.\n * @example\n * var take2 = _.takeN(2);\n *\n * take2([1, 2, 3, 4, 5]) // => [1, 2]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.take|take}\n * @see {@link module:lamb.drop|drop}, {@link module:lamb.dropN|dropN}\n * @see {@link module:lamb.takeWhile|takeWhile}, {@link module:lamb.dropWhile|dropWhile}\n * @param {Number} n\n * @returns {Function}\n */\n function takeN (n) {\n return function (arrayLike) {\n return slice(arrayLike, 0, +n);\n };\n }\n\n /**\n * Builds a function that takes the first n elements satisfying a predicate from\n * an array or array-like object.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var takeWhileIsEven = _.takeWhile(isEven);\n *\n * takeWhileIsEven([1, 2, 4, 6, 8]) // => []\n * takeWhileIsEven([2, 4, 7, 8]) // => [2, 4]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.dropWhile|dropWhile}\n * @see {@link module:lamb.take|take}, {@link module:lamb.takeN|takeN}\n * @see {@link module:lamb.drop|drop}, {@link module:lamb.dropN|dropN}\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Function}\n */\n function takeWhile (predicate, predicateContext) {\n var fn = arguments.length === 2 ? _getNumConsecutiveHits : binary(_getNumConsecutiveHits);\n\n return function (arrayLike) {\n return slice(arrayLike, 0, fn(arrayLike, predicate, predicateContext));\n };\n }\n\n /**\n * Transposes a matrix. Can also be used to reverse a {@link module:lamb.zip|zip} operation.
\n * Just like {@link module:lamb.zip|zip}, the received array-like objects will be truncated to the\n * shortest length.\n * @example transposing a matrix\n * _.transpose([\n * [1, 2, 3],\n * [4, 5, 6],\n * [7, 8, 9]\n * ]) // =>\n * // [\n * // [1, 4, 7],\n * // [2, 5, 8],\n * // [3, 6, 9]\n * // ]\n *\n * @example showing the relationship with zip\n * var zipped = _.zip([\"a\", \"b\", \"c\"], [1, 2, 3]); // => [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n *\n * _.transpose(zipped) // => [[\"a\", \"b\", \"c\"], [1, 2, 3]]\n *\n * @memberof module:lamb\n * @category Array\n * @param {ArrayLike>} arrayLike\n * @returns {Array>}\n */\n function transpose (arrayLike) {\n var result = [];\n var len = arrayLike.length >>> 0;\n\n if (len === 0) {\n return result;\n }\n\n var minLen = arrayLike[0].length >>> 0;\n\n for (var j = 1, elementLen; j < len && minLen > 0; j++) {\n elementLen = arrayLike[j].length >>> 0;\n\n if (elementLen < minLen) {\n minLen = elementLen;\n }\n }\n\n for (var i = 0, el; i < minLen; i++) {\n el = result[i] = Array(len);\n\n for (j = 0; j < len; j++) {\n el[j] = arrayLike[j][i];\n }\n }\n\n return result;\n }\n\n /**\n * Returns a list of every unique element present in the given array-like objects.\n * @example\n * _.union([1, 2, 3, 2], [3, 4], [1, 5]) // => [1, 2, 3, 4, 5]\n * _.union(\"abc\", \"bcd\", \"cde\") // => [\"a\", \"b\", \"c\", \"d\", \"e\"]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {...ArrayLike} arrayLike\n * @returns {Array}\n */\n var union = compose(uniques, flatMapWith(unary(slice)), list);\n\n /**\n * Returns an array comprised of the unique elements of the given array-like object.
\n * Can work with lists of complex objects if supplied with an iteratee.
\n * Note that this function uses the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.
\n * When two values are considered equal, the first occurence will be the one included\n * in the result array.\n * @example With simple values:\n * _.uniques([-0, 1, 2, 0, 2, 3, 4, 3, 5, 1]) // => [-0, 1, 2, 3, 4, 5]\n *\n * @example With complex values:\n * var data = [\n * {id: \"1\", name: \"John\"},\n * {id: \"4\", name: \"Jane\"},\n * {id: \"5\", name: \"Joe\"},\n * {id: \"1\", name: \"Mario\"},\n * {id: \"5\", name: \"Paolo\"},\n * ];\n *\n * _.uniques(data, _.getKey(\"id\")) // =>\n * // [\n * // {id: \"1\", name: \"John\"},\n * // {id: \"4\", name: \"Jane\"},\n * // {id: \"5\", name: \"Joe\"}\n * // ]\n *\n * @memberof module:lamb\n * @category Array\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} [iteratee={@link module:lamb.identity|identity}]\n * @param {Object} [iterateeContext]\n * @returns {Array}\n */\n function uniques (arrayLike, iteratee, iterateeContext) {\n if (typeof iteratee !== \"function\") {\n iteratee = identity;\n } else if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n var result = [];\n var len = arrayLike.length;\n\n for (var i = 0, seen = [], hasNaN = false, value; i < len; i++) {\n value = iteratee(arrayLike[i], i, arrayLike);\n\n // eslint-disable-next-line no-self-compare\n if (value === value) {\n if (seen.indexOf(value) === -1) {\n seen[seen.length] = value;\n result[result.length] = arrayLike[i];\n }\n } else if (!hasNaN) {\n hasNaN = true;\n result[result.length] = arrayLike[i];\n }\n }\n\n return result;\n }\n\n /**\n * Builds a list of arrays out of the given array-like objects by pairing items with the same index.
\n * The received array-like objects will be truncated to the shortest length.
\n * See also {@link module:lamb.zipWithIndex|zipWithIndex} and {@link module:lamb.transpose|transpose}\n * for the reverse operation.\n * @example\n * _.zip(\n * [\"a\", \"b\", \"c\"],\n * [1, 2, 3],\n * [true, false, true]\n * ) // => [[\"a\", 1, true], [\"b\", 2, false], [\"c\", 3, true]]\n *\n * _.zip([1, 2, 3, 4], [5, 6, 7]) // => [[1, 5], [2, 6], [3, 7]]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {...ArrayLike} arrayLike\n * @returns {Array>}\n */\n var zip = compose(transpose, list);\n\n /**\n * \"{@link module:lamb.zip|Zips}\" an array-like object by pairing its values with their index.\n * @example\n * _.zipWithIndex([\"a\", \"b\", \"c\"]) // => [[\"a\", 0], [\"b\", 1], [\"c\", 2]]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {ArrayLike} arrayLike\n * @returns {Array>}\n */\n var zipWithIndex = mapWith(binary(list));\n\n lamb.difference = difference;\n lamb.drop = drop;\n lamb.dropN = dropN;\n lamb.dropWhile = dropWhile;\n lamb.flatMap = flatMap;\n lamb.flatMapWith = flatMapWith;\n lamb.flatten = flatten;\n lamb.init = init;\n lamb.insert = insert;\n lamb.insertAt = insertAt;\n lamb.intersection = intersection;\n lamb.list = list;\n lamb.partition = partition;\n lamb.partitionWith = partitionWith;\n lamb.pluck = pluck;\n lamb.pluckKey = pluckKey;\n lamb.reverse = reverse;\n lamb.shallowFlatten = shallowFlatten;\n lamb.tail = tail;\n lamb.take = take;\n lamb.takeN = takeN;\n lamb.takeWhile = takeWhile;\n lamb.transpose = transpose;\n lamb.union = union;\n lamb.uniques = uniques;\n lamb.zip = zip;\n lamb.zipWithIndex = zipWithIndex;\n\n /**\n * Transforms an array-like object in a lookup table with the keys generated by the provided\n * iteratee, having as values the count of matches for the key.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"age\": 12},\n * {\"name\": \"John\", \"age\": 40},\n * {\"name\": \"Mario\", \"age\": 17},\n * {\"name\": \"Paolo\", \"age\": 15}\n * ];\n * var getAgeStatus = function (person) { return person.age >= 18 ? \"adult\" : \"minor\"; };\n *\n * _.count(persons, getAgeStatus) // => {\"adult\": 1, \"minor\": 3}\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.group|group}, {@link module:lamb.groupBy|groupBy}\n * @see {@link module:lamb.index|index}, {@link module:lamb.indexBy|indexBy}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Object}\n */\n var count = _groupWith(function (a) {\n return a ? ++a : 1;\n });\n\n /**\n * Using the provided iteratee, and its optional context, builds a partial application of\n * {@link module:lamb.count|count} expecting the array-like object to act upon.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"city\": \"New York\"},\n * {\"name\": \"John\", \"city\": \"New York\"},\n * {\"name\": \"Mario\", \"city\": \"Rome\"},\n * {\"name\": \"Paolo\"}\n * ];\n * var getCityOrUnknown = _.adapter(_.getKey(\"city\"), _.always(\"Unknown\"));\n * var countByCity = _.countBy(getCityOrUnknown);\n *\n * countByCity(persons) // => {\"New York\": 2, \"Rome\": 1, \"Unknown\": 1}\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.count|count}\n * @see {@link module:lamb.group|group}, {@link module:lamb.groupBy|groupBy}\n * @see {@link module:lamb.index|index}, {@link module:lamb.indexBy|indexBy}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Function}\n */\n var countBy = _partialWithIteratee(count);\n\n /**\n * Transforms an array-like object into a lookup table using the provided iteratee as a grouping\n * criterion to generate keys and values.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"city\": \"New York\"},\n * {\"name\": \"John\", \"city\": \"New York\"},\n * {\"name\": \"Mario\", \"city\": \"Rome\"},\n * {\"name\": \"Paolo\"}\n * ];\n * var getCity = _.getKey(\"city\");\n * var personsByCity = _.group(persons, getCity);\n *\n * // \"personsByCity\" holds:\n * // {\n * // \"New York\": [\n * // {\"name\": \"Jane\", \"city\": \"New York\"},\n * // {\"name\": \"John\", \"city\": \"New York\"}\n * // ],\n * // \"Rome\": [\n * // {\"name\": \"Mario\", \"city\": \"Rome\"}\n * // ],\n * // \"undefined\": [\n * // {\"name\": \"Paolo\"}\n * // ]\n * // }\n *\n * @example Adding a custom value for missing keys\n *\n * var getCityOrUnknown = _.adapter(getCity, _.always(\"Unknown\"));\n *\n * var personsByCity = _.group(persons, getCityOrUnknown);\n *\n * // \"personsByCity\" holds:\n * // {\n * // \"New York\": [\n * // {\"name\": \"Jane\", \"city\": \"New York\"},\n * // {\"name\": \"John\", \"city\": \"New York\"}\n * // ],\n * // \"Rome\": [\n * // {\"name\": \"Mario\", \"city\": \"Rome\"}\n * // ],\n * // \"Unknown\": [\n * // {\"name\": \"Paolo\"}\n * // ]\n * // }\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.groupBy|groupBy}\n * @see {@link module:lamb.count|count}, {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.index|index}, {@link module:lamb.indexBy|indexBy}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Object}\n */\n var group = _groupWith(function (a, b) {\n if (!a) {\n return [b];\n }\n\n a[a.length] = b;\n\n return a;\n });\n\n /**\n * Using the provided iteratee, and its optional context, builds a partial application\n * of {@link module:lamb.group|group} expecting the array-like object to act upon.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"age\": 12},\n * {\"name\": \"John\", \"age\": 40},\n * {\"name\": \"Mario\", \"age\": 18},\n * {\"name\": \"Paolo\", \"age\": 15}\n * ];\n *\n * var getAgeStatus = function (person) { return person.age > 20 ? \"over 20\" : \"under 20\"; };\n * var groupByAgeStatus = _.groupBy(getAgeStatus);\n *\n * var personsByAgeStatus = groupByAgeStatus(persons);\n *\n * // \"personsByAgeStatus\" holds:\n * // {\n * // \"under 20\": [\n * // {\"name\": \"Jane\", \"age\": 12},\n * // {\"name\": \"Mario\", \"age\": 18},\n * // {\"name\": \"Paolo\", \"age\": 15}\n * // ],\n * // \"over 20\": [\n * // {\"name\": \"John\", \"age\": 40}\n * // ]\n * // }\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.group|group}\n * @see {@link module:lamb.count|count}, {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.index|index}, {@link module:lamb.indexBy|indexBy}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Function}\n */\n var groupBy = _partialWithIteratee(group);\n\n /**\n * Similar to {@link module:lamb.group|group}, but the generated lookup table will have\n * only one element of the original array-like object for each value.
\n * Should be used only when you're sure that your iteratee won't produce\n * duplicate keys, otherwise only the last evaluated element will be in the result.\n * @example\n * var users = [\n * {id: 1, name: \"John\"},\n * {id: 2, name: \"Jane\"},\n * {id: 3, name: \"Mario\"},\n * {id: 4, name: \"John\"}\n * ];\n *\n * var indexedUsers = _.index(users, _.getKey(\"id\"));\n *\n * // \"indexedUsers\" holds:\n * // {\n * // \"1\": {id: 1, name: \"John\"},\n * // \"2\": {id: 2, name: \"Jane\"},\n * // \"3\": {id: 3, name: \"Mario\"},\n * // \"4\": {id: 4, name: \"John\"}\n * // }\n *\n * @example Result of an iteratee producing a duplicate key:\n * var users = [\n * {id: 1, name: \"John\"},\n * {id: 2, name: \"Jane\"},\n * {id: 3, name: \"Mario\"},\n * {id: 4, name: \"John\"}\n * ];\n *\n * var indexedUsers = _.index(users, _.getKey(\"name\"));\n *\n * // \"indexedUsers\" holds:\n * // {\n * // \"John\": {\"id\": 4, \"name\": \"John\"},\n * // \"Jane\": {\"id\": 2, \"name\": \"Jane\"},\n * // \"Mario\": {\"id\": 3, \"name\": \"Mario\"}\n * // }\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.indexBy|indexBy}\n * @see {@link module:lamb.count|count}, {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.group|group}, {@link module:lamb.groupBy|groupBy}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Object}\n */\n var index = _groupWith(function (a, b) {\n return b;\n });\n\n /**\n * Using the provided iteratee, and its optional context, builds a partial application\n * of {@link module:lamb.index|index} expecting the array-like object to act upon.\n * @example\n * var users = [\n * {id: 1, name: \"John\"},\n * {id: 2, name: \"Jane\"},\n * {id: 3, name: \"Mario\"}\n * ];\n * var indexByID = _.indexBy(_.getKey(\"id\"));\n *\n * var indexedUsers = indexByID(users);\n *\n * // \"indexedUsers\" holds:\n * // {\n * // \"1\": {id: 1, name: \"John\"},\n * // \"2\": {id: 2, name: \"Jane\"},\n * // \"3\": {id: 3, name: \"Mario\"}\n * // }\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.index|index}\n * @see {@link module:lamb.count|count}, {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.group|group}, {@link module:lamb.groupBy|groupBy}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Function}\n */\n var indexBy = _partialWithIteratee(index);\n\n lamb.count = count;\n lamb.countBy = countBy;\n lamb.group = group;\n lamb.groupBy = groupBy;\n lamb.index = index;\n lamb.indexBy = indexBy;\n\n /**\n * Returns a [stably]{@link https://en.wikipedia.org/wiki/Sorting_algorithm#Stability} sorted\n * copy of an array-like object using the given criteria.
\n * Sorting criteria are built using Lamb's {@link module:lamb.sorter|sorter} function, but you\n * can also pass simple \"reader\" functions and default ascending sorters will be built for you.
\n * A \"reader\" is a function that evaluates the array element and supplies the value to be used\n * in the comparison.
\n * Please note that if the arguments received by the default comparer aren't of the same type,\n * they will be compared as strings.\n *\n * @example Stable sort:\n * var persons = [\n * {\"name\": \"John\", \"surname\" :\"Doe\"},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\"},\n * {\"name\": \"John\", \"surname\" :\"Moe\"},\n * {\"name\": \"Jane\", \"surname\": \"Foe\"}\n * ];\n *\n * var personsByName = _.sort(persons, _.getKey(\"name\"));\n *\n * // personsByName holds:\n * // [\n * // {\"name\": \"Jane\", \"surname\": \"Foe\"},\n * // {\"name\": \"John\", \"surname\" :\"Doe\"},\n * // {\"name\": \"John\", \"surname\" :\"Moe\"},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * // ]\n *\n * @example Stable multi-sort:\n * var personsByNameAscSurnameDesc = _.sort(\n * persons,\n * _.getKey(\"name\"),\n * _.sorterDesc(_.getKey(\"surname\"))\n * );\n *\n * // personsByNameAscSurnameDesc holds:\n * // [\n * // {\"name\": \"Jane\", \"surname\": \"Foe\"},\n * // {\"name\": \"John\", \"surname\" :\"Moe\"},\n * // {\"name\": \"John\", \"surname\" :\"Doe\"},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * // ]\n *\n * @example Using custom comparers:\n * var localeSorter = new Intl.Collator(\"it\");\n * var chars = [\"a\", \"è\", \"à\", \"é\", \"c\", \"b\", \"e\"];\n *\n * _.sort(chars, localeSorter) // => [\"a\", \"à\", \"b\", \"c\", \"e\", \"é\", \"è\"]\n *\n * var localeSorterDesc = _.sorterDesc(_.identity, localeSorter.compare);\n *\n * _.sort(chars, localeSorterDesc) // => [\"è\", \"é\", \"e\", \"c\", \"b\", \"à\", \"a\"]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.sortWith|sortWith}\n * @see {@link module:lamb.sorter|sorter}, {@link module:lamb.sorterDesc|sorterDesc}\n * @param {ArrayLike} arrayLike\n * @param {...(Sorter|Function)} [sorter={@link module:lamb.sorter|sorter()}]\n * @returns {Array}\n */\n function sort (arrayLike) {\n var criteria = _makeCriteria(_argsTail.apply(null, arguments));\n var data = [];\n var result = [];\n var len = arrayLike.length;\n\n for (var i = 0; i < len; i++) {\n data.push({\n value: arrayLike[i],\n index: i\n });\n }\n\n data.sort(_compareWith(criteria));\n\n for (i = 0; i < len; i++) {\n result.push(data[i].value);\n }\n\n return result;\n }\n\n /**\n * Inserts an element in a copy of a sorted array respecting the sort order.\n * @example with simple values\n * _.sortedInsert([], 1) // => [1]\n * _.sortedInsert([2, 4, 6], 5) // => [2, 4, 5, 6]\n * _.sortedInsert([4, 2, 1], 3, _.sorterDesc()) // => [4, 3, 2, 1]\n *\n * @example with complex values\n * var persons = [\n * {\"name\": \"jane\", \"surname\": \"doe\"},\n * {\"name\": \"John\", \"surname\": \"Doe\"},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * ];\n *\n * var getLowerCaseName = _.compose(\n * _.invoker(\"toLowerCase\"),\n * _.getKey(\"name\")\n * );\n *\n * var result = _.sortedInsert(\n * persons,\n * {\"name\": \"marco\", \"surname\": \"Rossi\"},\n * getLowerCaseName\n * );\n *\n * // `result` holds:\n * // [\n * // {\"name\": \"jane\", \"surname\": \"doe\"},\n * // {\"name\": \"John\", \"surname\": \"Doe\"},\n * // {\"name\": \"marco\", \"surname\": \"Rossi\"},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * // ]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.sort|sort}, {@link module:lamb.sortWith|sortWith}\n * @see {@link module:lamb.sorter|sorter}, {@link module:lamb.sorterDesc|sorterDesc}\n * @see {@link module:lamb.insert|insert}, {@link module:lamb.insertAt|insertAt} to insert the element\n * at a specific index\n * @param {ArrayLike} arrayLike\n * @param {*} element\n * @param {...(Sorter|Function)} [sorter={@link module:lamb.sorter|sorter()}] - The sorting criteria\n * used to sort the array.\n * @returns {Array}\n */\n function sortedInsert (arrayLike, element) {\n var result = slice(arrayLike);\n\n if (arguments.length === 1) {\n return result;\n }\n\n var len = arguments.length - 2;\n var sorters = Array(len);\n\n for (var i = 0; i < len; i++) {\n sorters[i] = arguments[i + 2];\n }\n\n var criteria = _makeCriteria(sorters);\n var idx = _getInsertionIndex(result, element, _compareWith(criteria), 0, result.length);\n\n result.splice(idx, 0, element);\n\n return result;\n }\n\n /**\n * Creates an ascending sort criterion with the provided reader and\n * comparer.
\n * See {@link module:lamb.sort|sort} for various examples.\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.sortedInsert|sortedInsert}\n * @see {@link module:lamb.sort|sort}, {@link module:lamb.sortWith|sortWith}\n * @see {@link module:lamb.sorterDesc|sorterDesc}\n * @param {Function} [reader={@link module:lamb.identity|identity}] A function meant to generate a\n * simple value from a complex one. The function should evaluate the array element and supply the\n * value to be passed to the comparer.\n * @param {Function} [comparer] An optional custom comparer function.\n * @returns {Sorter}\n */\n var sorter = partial(_sorter, _, false, _);\n\n /**\n * Creates a descending sort criterion with the provided reader and\n * comparer.
\n * See {@link module:lamb.sort|sort} for various examples.\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.sortedInsert|sortedInsert}\n * @see {@link module:lamb.sort|sort}, {@link module:lamb.sortWith|sortWith}\n * @see {@link module:lamb.sorter|sorter}\n * @param {Function} [reader={@link module:lamb.identity|identity}] A function meant to generate a\n * simple value from a complex one. The function should evaluate the array element and supply the\n * value to be passed to the comparer.\n * @param {Function} [comparer] An optional custom comparer function.\n * @returns {Sorter}\n */\n var sorterDesc = partial(_sorter, _, true, _);\n\n /**\n * Builds a partial application of {@link module:lamb.sort|sort} using the provided criteria.\n * The returned function expects the array-like object to sort.\n * As usual, sorting criteria are built using Lamb's {@link module:lamb.sorter|sorter} function,\n * but you can also pass simple \"reader\" functions and default ascending sorters will be built.
\n * A \"reader\" is a function that evaluates the array element and supplies the value to be used in\n * the comparison.
\n * See {@link module:lamb.sort|sort} for more examples.\n *\n * @example\n * var sortAsNumbers = _.sortWith(parseFloat);\n * var weights = [\"2 Kg\", \"10 Kg\", \"1 Kg\", \"7 Kg\"];\n *\n * sortAsNumbers(weights) // => [\"1 Kg\", \"2 Kg\", \"7 Kg\", \"10 Kg\"]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.sort|sort}\n * @see {@link module:lamb.sorter|sorter}, {@link module:lamb.sorterDesc|sorterDesc}\n * @param {...(Sorter|Function)} [sorter={@link module:lamb.sorter|sorter()}]\n * @returns {Function}\n */\n function sortWith () {\n var sorters = list.apply(null, arguments);\n\n return function (arrayLike) {\n return sort.apply(null, [arrayLike].concat(sorters));\n };\n }\n\n lamb.sort = sort;\n lamb.sortedInsert = sortedInsert;\n lamb.sorter = sorter;\n lamb.sorterDesc = sorterDesc;\n lamb.sortWith = sortWith;\n\n /**\n * Applies the passed function to the given argument list.\n * @example\n * _.apply(_.add, [3, 4]) // => 7\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {ArrayLike} args\n * @returns {*}\n */\n function apply (fn, args) {\n return fn.apply(this, Object(args));\n }\n\n /**\n * A curried version of {@link module:lamb.apply|apply}. Expects an array-like object to use as arguments\n * and builds a function waiting for the target of the application.\n * @example\n * var data = [3, 4];\n * var applyDataTo = _.applyArgs(data);\n *\n * applyDataTo(_.add) // => 7\n * applyDataTo(_.multiply) // => 12\n *\n * @memberof module:lamb\n * @category Function\n * @param {ArrayLike} args\n * @returns {Function}\n */\n function applyArgs (args) {\n return function (fn) {\n return fn.apply(this, Object(args));\n };\n }\n\n /**\n * Builds a function that passes only the specified amount of arguments to the given function.
\n * As {@link module:lamb.slice|slice} is used to extract the arguments, you can also\n * pass a negative arity.
\n * See also {@link module:lamb.binary|binary} and {@link module:lamb.unary|unary} for common use\n * cases shortcuts.\n * @example\n * function maxArgument () {\n * return Math.max.apply(null, arguments);\n * }\n *\n * maxArgument(10, 11, 45, 99) // => 99\n * _.aritize(maxArgument, 2)(10, 11, 45, 99) // => 11\n *\n * @example Using a negative arity:\n * _.aritize(maxArgument, -1)(10, 11, 45, 99) // => 45\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {Number} arity\n * @returns {Function}\n */\n function aritize (fn, arity) {\n return function () {\n var args = slice(list.apply(null, arguments), 0, arity);\n var argsLen = args.length;\n var n = Math.floor(arity);\n\n if (n > 0) {\n while (argsLen < n) {\n args[argsLen++] = void 0;\n }\n }\n\n return fn.apply(this, args);\n };\n }\n\n /**\n * Decorates the received function so that it can be called with\n * placeholders to build a partial application of it.
\n * The difference with {@link module:lamb.partial|partial} is that, as long as\n * you call the generated function with placeholders, another partial application\n * of the original function will be built.
\n * The final application will happen when one of the generated functions is\n * invoked without placeholders, using the parameters collected so far.
\n * This function comes in handy when you need to build different specialized\n * functions starting from a basic one, but it's also useful when dealing with\n * optional parameters as you can decide to apply the function even if its arity\n * hasn't been entirely consumed.\n * @example Explaining the function's behaviour:\n * var f = _.asPartial(function (a, b, c) {\n * return a + b + c;\n * });\n *\n * f(4, 3, 2) // => 9\n * f(4, _, 2)(3) // => 9\n * f(_, 3, _)(4, _)(2) // => 9\n *\n * @example Exploiting optional parameters: \n * var f = _.asPartial(function (a, b, c) {\n * return a + b + (c || 0);\n * });\n *\n * var addFive = f(5, _);\n * addFive(2) // => 7\n *\n * var addNine = addFive(4, _);\n * addNine(11) // => 20\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.partial|partial}\n * @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}\n * @param {Function} fn\n * @returns {Function}\n */\n function asPartial (fn) {\n return _asPartial(fn, []);\n }\n\n /**\n * Builds a function that passes only two arguments to the given function.
\n * It's simply a shortcut for a common use case of {@link module:lamb.aritize|aritize},\n * exposed for convenience.
\n * See also {@link module:lamb.unary|unary}.\n * @example\n * _.list(1, 2, 3, 4, 5) // => [1, 2, 3, 4, 5]\n * _.binary(_.list)(1, 2, 3, 4, 5) // => [1, 2]\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @returns {Function}\n */\n function binary (fn) {\n return function (a, b) {\n return fn.call(this, a, b);\n };\n }\n\n /**\n * Accepts a series of functions and builds a new function. The functions in the series\n * will then be applied, in order, with the values received by the function built with\n * collect.
\n * The collected results will be returned in an array.\n * @example\n * var user = {\n * id: \"jdoe\",\n * name: \"John\",\n * surname: \"Doe\",\n * scores: [2, 4, 7]\n * };\n * var getIDAndLastScore = _.collect(_.getKey(\"id\"), _.getPath(\"scores.-1\"));\n *\n * getIDAndLastScore(user) // => [\"jdoe\", 7]\n *\n * @example\n * var minAndMax = _.collect(Math.min, Math.max);\n *\n * minAndMax(3, 1, -2, 5, 4, -1) // => [-2, 5]\n *\n * @memberof module:lamb\n * @category Function\n * @param {...Function} fn\n * @returns {Function}\n */\n function collect () {\n var functions = list.apply(null, arguments);\n\n return function () {\n return map(functions, applyArgs(arguments));\n };\n }\n\n /**\n * Transforms the evaluation of the given function in the evaluation of a sequence of functions\n * expecting only one argument. Each function of the sequence is a partial application of the\n * original one, which will be applied when the specified (or derived) arity is consumed.
\n * Currying will start from the leftmost argument: use {@link module:lamb.curryRight|curryRight}\n * for right currying.\n * @example\n * var multiplyBy = _.curry(_.multiply);\n * var multiplyBy10 = multiplyBy(10);\n *\n * multiplyBy10(5) // => 50\n * multiplyBy10(2) // => 20\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}\n * @see {@link module:lamb.partial|partial}, {@link module:lamb.asPartial|asPartial}\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @returns {Function}\n */\n function curry (fn, arity) {\n return _curry(fn, arity, false);\n }\n\n /**\n * Builds an auto-curried function. The resulting function can be called multiple times with\n * any number of arguments, and the original function will be applied only when the specified\n * (or derived) arity is consumed.
\n * Currying will start from the leftmost argument: use {@link module:lamb.curryableRight|curryableRight}\n * for right currying.\n * @example\n * var collectFourElements = _.curryable(_.list, 4);\n *\n * collectFourElements(2)(3)(4)(5) // => [2, 3, 4, 5]\n * collectFourElements(2)(3, 4)(5) // => [2, 3, 4, 5]\n * collectFourElements(2, 3, 4, 5) // => [2, 3, 4, 5]\n * collectFourElements(2, 3)(4, 5) // => [2, 3, 4, 5]\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.curryableRight|curryableRight}\n * @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.partial|partial}, {@link module:lamb.asPartial|asPartial}\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @returns {Function}\n */\n function curryable (fn, arity) {\n return _curry(fn, arity, false, true);\n }\n\n /**\n * Same as {@link module:lamb.curryable|curryable}, but currying starts from the rightmost argument.\n * @example\n * var collectFourElements = _.curryableRight(_.list, 4);\n *\n * collectFourElements(2)(3)(4)(5) // => [5, 4, 3, 2]\n * collectFourElements(2)(3, 4)(5) // => [5, 4, 3, 2]\n * collectFourElements(2, 3, 4, 5) // => [5, 4, 3, 2]\n * collectFourElements(2, 3)(4, 5) // => [5, 4, 3, 2]\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.curryable|curryable}\n * @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.partial|partial}, {@link module:lamb.asPartial|asPartial}\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @returns {Function}\n */\n function curryableRight (fn, arity) {\n return _curry(fn, arity, true, true);\n }\n\n /**\n * Same as {@link module:lamb.curry|curry}, but currying starts from the rightmost argument.\n * @example\n * var divideBy = _.curryRight(_.divide);\n * var halve = divideBy(2);\n * halve(3) // => 1.5\n * halve(3, 7) // => 1.5\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.curry|curry}\n * @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}\n * @see {@link module:lamb.partial|partial}, {@link module:lamb.asPartial|asPartial}\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @returns {Function}\n */\n function curryRight (fn, arity) {\n return _curry(fn, arity, true);\n }\n\n /**\n * Returns a function that will execute the given function only if it stops being called for the\n * specified timespan.
\n * See also {@link module:lamb.throttle|throttle} for a different behaviour where the first call\n * happens immediately.\n * @example A common use case of debounce in a browser environment\n * var updateLayout = function () {\n * // some heavy DOM operations here\n * };\n *\n * window.addEventListener(\"resize\", _.debounce(updateLayout, 200), false);\n *\n * // The resize event is fired repeteadly until the user stops resizing the\n * // window, while the `updateLayout` function is called only once: 200 ms\n * // after he stopped.\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {Number} timespan - Expressed in milliseconds\n * @returns {Function}\n */\n function debounce (fn, timespan) {\n var timeoutID;\n\n return function () {\n var args = arguments;\n var debounced = function () {\n timeoutID = null;\n fn.apply(this, args);\n }.bind(this);\n\n clearTimeout(timeoutID);\n timeoutID = setTimeout(debounced, timespan);\n };\n }\n\n /**\n * Returns a function that applies its arguments to the original function in reverse order.\n * @example\n * _.list(1, 2, 3) // => [1, 2, 3]\n * _.flip(_.list)(1, 2, 3) // => [3, 2, 1]\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @returns {Function}\n */\n function flip (fn) {\n return function () {\n var args = list.apply(null, arguments).reverse();\n\n return fn.apply(this, args);\n };\n }\n\n /**\n * Builds a function that returns the argument received at the given index.
\n * As with {@link module:lamb.getAt|getAt} negative indexes are allowed.
\n * The resulting function will return undefined if no arguments are\n * passed or if the index is out of bounds.\n * @example\n * var getFirstArg = getArgAt(0);\n * var getLastArg = getArgAt(-1);\n *\n * getFirstArg(1, 2, 3) // => 1\n * getLastArg(1, 2, 3) // => 3\n *\n * getArgAt()(1, 2, 3) // => undefined\n * getArgAt(6)(1, 2, 3) // => undefined\n * getArgAt(1)() // => undefined\n *\n * @memberof module:lamb\n * @category Function\n * @param {Number} idx\n * @returns {Function}\n */\n function getArgAt (idx) {\n return function () {\n return arguments[_getNaturalIndex({length: arguments.length}, idx)];\n };\n }\n\n /**\n * Builds a function that will invoke the given method name on any received object and return\n * the result. If no method with such name is found the function will return undefined.\n * Along with the method name it's possible to supply some arguments that will be bound to the\n * method call.
\n * Further arguments can also be passed when the function is actually called, and they will be\n * concatenated to the bound ones.
\n * If different objects share a method name it's possible to build polymorphic functions as you\n * can see in the example below.
\n * {@link module:lamb.condition|Condition} can be used to wrap invoker to avoid this\n * behaviour by adding a predicate, while {@link module:lamb.adapter|adapter} can build more complex\n * polymorphic functions without the need of homonymy.
\n * Returning undefined or checking for such value is meant to favor composition and\n * interoperability between the aforementioned functions: for a more standard behaviour see also\n * {@link module:lamb.generic|generic}.\n * See also {@link module:lamb.invokerOn|invokerOn}.\n * @example Basic polymorphism with invoker\n * var polySlice = _.invoker(\"slice\");\n *\n * polySlice([1, 2, 3, 4, 5], 1, 3) // => [2, 3]\n * polySlice(\"Hello world\", 1, 3) // => \"el\"\n *\n * @example With bound arguments\n * var substrFrom2 = _.invoker(\"substr\", 2);\n * substrFrom2(\"Hello world\") // => \"llo world\"\n * substrFrom2(\"Hello world\", 5) // => \"llo w\"\n *\n * @memberof module:lamb\n * @category Function\n * @param {String} methodName\n * @param {...*} [boundArg]\n * @returns {Function}\n */\n function invoker (methodName) {\n return partial(_invoker, _argsTail.apply(null, arguments), methodName);\n }\n\n /**\n * Accepts an object and builds a function expecting a method name, and optionally arguments,\n * to call on such object.\n * Like {@link module:lamb.invoker|invoker}, if no method with the given name is found the\n * function will return undefined.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var arr = [1, 2, 3, 4, 5];\n * var invokerOnArr = _.invokerOn(arr);\n *\n * invokerOnArr(\"filter\", isEven) // => [2, 4]\n * invokerOnArr(\"slice\", 1, 3) // => [2, 3]\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.invoker|invoker}\n * @param {Object} target\n * @returns {Function}\n */\n function invokerOn (target) {\n return partial(_invoker, [], _, target);\n }\n\n /**\n * Builds a function that allows to map over the received arguments before applying them\n * to the original one.\n * @example\n * var sumArray = _.reduceWith(_.add);\n * var sum = _.compose(sumArray, _.list);\n *\n * sum(1, 2, 3, 4, 5) // => 15\n *\n * var square = _.partial(Math.pow, _, 2);\n * var sumSquares = _.mapArgs(sum, square);\n *\n * sumSquares(1, 2, 3, 4, 5) // => 55\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {ListIteratorCallback} mapper\n * @returns {Function}\n */\n function mapArgs (fn, mapper) {\n return compose(partial(apply, fn), mapWith(mapper), list);\n }\n\n /**\n * Creates a pipeline of functions, where each function consumes the result of the previous one.
\n * See also {@link module:lamb.compose|compose}.\n * @example\n * var square = _.partial(Math.pow, _, 2);\n * var getMaxAndSquare = _.pipe(Math.max, square);\n *\n * getMaxAndSquare(3, 5) // => 25\n *\n * @memberof module:lamb\n * @category Function\n * @function\n * @param {...Function} fn\n * @returns {Function}\n */\n var pipe = flip(compose);\n\n /**\n * Builds a function that allows to \"tap\" into the arguments of the original one.\n * This allows to extract simple values from complex ones, transform arguments or simply intercept them.\n * If a \"tapper\" isn't found the argument is passed as it is.\n * @example\n * var someObject = {count: 5};\n * var someArrayData = [2, 3, 123, 5, 6, 7, 54, 65, 76, 0];\n * var getDataAmount = _.tapArgs(_.add, _.getKey(\"count\"), _.getKey(\"length\"));\n *\n * getDataAmount(someObject, someArrayData); // => 15\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {...?Function} [tapper]\n * @returns {Function}\n */\n function tapArgs (fn) {\n var tappers = _argsTail.apply(null, arguments);\n\n return function () {\n var len = arguments.length;\n var tappersLen = tappers.length;\n var args = [];\n\n for (var i = 0; i < len; i++) {\n args.push(i < tappersLen ? tappers[i](arguments[i]) : arguments[i]);\n }\n\n return fn.apply(this, args);\n };\n }\n\n /**\n * Returns a function that will invoke the passed function at most once in the given timespan.
\n * The first call in this case happens as soon as the function is invoked; see also\n * {@link module:lamb.debounce|debounce} for a different behaviour where the first call is delayed.\n * @example\n * var log = _.throttle(console.log.bind(console), 5000);\n *\n * log(\"Hi\"); // console logs \"Hi\"\n * log(\"Hi again\"); // nothing happens\n * // after five seconds\n * log(\"Hello world\"); // console logs \"Hello world\"\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {Number} timespan - Expressed in milliseconds.\n * @returns {Function}\n */\n function throttle (fn, timespan) {\n var result;\n var lastCall = 0;\n\n return function () {\n var now = Date.now();\n\n if (now - lastCall >= timespan) {\n lastCall = now;\n result = fn.apply(this, arguments);\n }\n\n return result;\n };\n }\n\n /**\n * Builds a function that passes only one argument to the given function.
\n * It's simply a shortcut for a common use case of {@link module:lamb.aritize|aritize},\n * exposed for convenience.
\n * See also {@link module:lamb.binary|binary}.\n * @example\n * var weights = [\"2 Kg\", \"10 Kg\", \"1 Kg\", \"7 Kg\"];\n *\n * weights.map(_.unary(parseInt)) // => [2, 10, 1, 7]\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @returns {Function}\n */\n function unary (fn) {\n return function (a) {\n return fn.call(this, a);\n };\n }\n\n /**\n * Wraps the function fn inside a wrapper function.
\n * This allows to conditionally execute fn, to tamper with its arguments\n * or return value and to run code before and after its execution.
\n * Being this nothing more than a \"{@link module:lamb.flip|flipped}\"\n * [partial application]{@link module:lamb.partial}, you can also easily build new\n * functions from existent ones.\n * @example\n * var arrayMax = _.wrap(Math.max, _.apply);\n *\n * arrayMax([4, 5, 2, 6, 1]) // => 6\n *\n * @memberof module:lamb\n * @category Function\n * @function\n * @param {Function} fn\n * @param {Function} wrapper\n * @returns {Function}\n */\n var wrap = binary(flip(partial));\n\n lamb.apply = apply;\n lamb.applyArgs = applyArgs;\n lamb.aritize = aritize;\n lamb.asPartial = asPartial;\n lamb.binary = binary;\n lamb.collect = collect;\n lamb.curry = curry;\n lamb.curryRight = curryRight;\n lamb.curryable = curryable;\n lamb.curryableRight = curryableRight;\n lamb.debounce = debounce;\n lamb.flip = flip;\n lamb.getArgAt = getArgAt;\n lamb.invoker = invoker;\n lamb.invokerOn = invokerOn;\n lamb.mapArgs = mapArgs;\n lamb.pipe = pipe;\n lamb.tapArgs = tapArgs;\n lamb.throttle = throttle;\n lamb.unary = unary;\n lamb.wrap = wrap;\n\n /**\n * Builds a checker function meant to be used with\n * {@link module:lamb.validate|validate}.
\n * Note that the function accepts multiple keyPaths as a means to\n * compare their values. In other words all the received keyPaths will be\n * passed as arguments to the predicate to run the test.
\n * If you want to run the same single property check with multiple properties, you should build\n * multiple checkers and combine them with {@link module:lamb.validate|validate}.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * login: {\n * username: \"jdoe\",\n * password: \"abc123\",\n * passwordConfirm: \"abc123\"\n * }\n * };\n * var pwdMatch = _.checker(\n * _.is,\n * \"Passwords don't match\",\n * [\"login.password\", \"login.passwordConfirm\"]\n * );\n *\n * pwdMatch(user) // => []\n *\n * var newUser = _.setPathIn(user, \"login.passwordConfirm\", \"avc123\");\n *\n * pwdMatch(newUser) // => [\"Passwords don't match\", [\"login.password\", \"login.passwordConfirm\"]]\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.validate|validate}, {@link module:lamb.validateWith|validateWith}\n * @param {Function} predicate - The predicate to test the object properties\n * @param {String} message - The error message\n * @param {String[]} keyPaths - The array of keys, or {@link module:lamb.getPathIn|paths}, to test.\n * @param {String} [pathSeparator=\".\"]\n * @returns {Function} A checker function which returns an error in the form\n * [\"message\", [\"propertyA\", \"propertyB\"]] or an empty array.\n */\n function checker (predicate, message, keyPaths, pathSeparator) {\n return function (obj) {\n var getValues = partial(getPathIn, obj, _, pathSeparator);\n\n return predicate.apply(obj, map(keyPaths, getValues)) ? [] : [message, keyPaths];\n };\n }\n\n /**\n * Creates an array with all the enumerable properties of the given object.\n * @example Showing the difference with {@link module:lamb.keys|keys}\n * var baseFoo = Object.create({a: 1}, {b: {value: 2}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3},\n * d: {value: 4, enumerable: true}\n * });\n *\n * _.keys(foo) // => [\"d\"]\n * _.enumerables(foo) // => [\"d\", \"a\"]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.keys|keys}\n * @param {Object} obj\n * @returns {String[]}\n */\n var enumerables = _unsafeKeyListFrom(_safeEnumerables);\n\n /**\n * Builds an object from a list of key / value pairs like the one\n * returned by [pairs]{@link module:lamb.pairs} or {@link module:lamb.ownPairs|ownPairs}.
\n * In case of duplicate keys the last key / value pair is used.\n * @example\n * _.fromPairs([[\"a\", 1], [\"b\", 2], [\"c\", 3]]) // => {\"a\": 1, \"b\": 2, \"c\": 3}\n * _.fromPairs([[\"a\", 1], [\"b\", 2], [\"a\", 3]]) // => {\"a\": 3, \"b\": 2}\n * _.fromPairs([[1], [void 0, 2], [null, 3]]) // => {\"1\": undefined, \"undefined\": 2, \"null\": 3}\n *\n * @memberof module:lamb\n * @category Object\n * @param {Array>} pairsList\n * @returns {Object}\n */\n function fromPairs (pairsList) {\n var result = {};\n\n forEach(pairsList, function (pair) {\n result[pair[0]] = pair[1];\n });\n\n return result;\n }\n\n /**\n * Verifies the existence of a property in an object.\n * @example\n * var user1 = {name: \"john\"};\n *\n * _.has(user1, \"name\") // => true\n * _.has(user1, \"surname\") // => false\n * _.has(user1, \"toString\") // => true\n *\n * var user2 = Object.create(null);\n *\n * // not inherited through the prototype chain\n * _.has(user2, \"toString\") // => false\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.hasKey|hasKey}\n * @see {@link module:lamb.hasOwn|hasOwn}, {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}, {@link module:lamb.pathExists|pathExists}\n * @param {Object} obj\n * @param {String} key\n * @returns {Boolean}\n */\n function has (obj, key) {\n if (typeof obj !== \"object\" && !isUndefined(obj)) {\n obj = Object(obj);\n }\n\n return key in obj;\n }\n\n /**\n * Curried version of {@link module:lamb.has|has}.
\n * Returns a function expecting the object to check against the given key.\n * @example\n * var user1 = {name: \"john\"};\n * var user2 = {};\n * var hasName = _.hasKey(\"name\");\n *\n * hasName(user1) // => true\n * hasName(user2) // => false\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.has|has}\n * @see {@link module:lamb.hasOwn|hasOwn}, {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}, {@link module:lamb.pathExists|pathExists}\n * @param {String} key\n * @returns {Function}\n */\n function hasKey (key) {\n return function (obj) {\n return has(obj, key);\n };\n }\n\n /**\n * Builds a predicate expecting an object to check against the given key / value pair.
\n * The value check is made with the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.\n * @example\n * var hasTheCorrectAnswer = _.hasKeyValue(\"answer\", 42);\n *\n * hasTheCorrectAnswer({answer: 2}) // false\n * hasTheCorrectAnswer({answer: 42}) // true\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.hasPathValue|hasPathValue}\n * @param {String} key\n * @param {*} value\n * @returns {Function}\n */\n function hasKeyValue (key, value) {\n return function (obj) {\n return isSVZ(value, obj[key]);\n };\n }\n\n /**\n * Verifies if an object has the specified property and that the property isn't inherited through\n * the prototype chain.
\n * @example Comparison with has.\n * var user = {name: \"john\"};\n *\n * _.has(user, \"name\") // => true\n * _.has(user, \"surname\") // => false\n * _.has(user, \"toString\") // => true\n *\n * _.hasOwn(user, \"name\") // => true\n * _.hasOwn(user, \"surname\") // => false\n * _.hasOwn(user, \"toString\") // => false\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.has|has}, {@link module:lamb.hasKey|hasKey}\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}, {@link module:lamb.pathExists|pathExists}\n * @param {Object} obj\n * @param {String} key\n * @returns {Boolean}\n */\n var hasOwn = generic(_objectProto.hasOwnProperty);\n\n /**\n * Curried version of {@link module:lamb.hasOwn|hasOwn}.
\n * Returns a function expecting the object to check against the given key.\n * @example\n * var user = {name: \"john\"};\n * var hasOwnName = _.hasOwnKey(\"name\");\n * var hasOwnToString = _.hasOwnToString(\"toString\");\n *\n * hasOwnName(user) // => true\n * hasOwnToString(user) // => false\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.hasOwn|hasOwn}\n * @see {@link module:lamb.has|has}, {@link module:lamb.hasKey|hasKey}\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}, {@link module:lamb.pathExists|pathExists}\n * @param {String} key\n * @returns {Function}\n */\n function hasOwnKey (key) {\n return function (obj) {\n return hasOwn(obj, key);\n };\n }\n\n /**\n * Builds a predicate to check if the given path exists in an object and holds the desired value.
\n * The value check is made with the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.
\n * Note that the function will check even non-enumerable properties.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * personal: {\n * age: 25,\n * gender: \"M\"\n * },\n * scores: [\n * {id: 1, value: 10, passed: false},\n * {id: 2, value: 20, passed: false},\n * {id: 3, value: 30, passed: true}\n * ]\n * };\n *\n * var isMale = _.hasPathValue(\"personal.gender\", \"M\");\n * var hasPassedFirstTest = _.hasPathValue(\"scores.0.passed\", true);\n * var hasPassedLastTest = _.hasPathValue(\"scores.-1.passed\", true);\n *\n * isMale(user) // => true\n * hasPassedFirstTest(user) // => false\n * hasPassedLastTest(user) // => true\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.hasKeyValue|hasKeyValue}\n * @param {String} path\n * @param {*} value\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function hasPathValue (path, value, separator) {\n return function (obj) {\n var pathInfo = _getPathInfo(obj, _toPathParts(path, separator), true);\n\n return pathInfo.isValid && isSVZ(pathInfo.target, value);\n };\n }\n\n /**\n * Makes an object immutable by recursively calling [Object.freeze]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze}\n * on its members.
\n * Any attempt to extend or modify the object can throw a TypeError or fail silently,\n * depending on the environment and the [strict mode]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode} directive.\n * @example\n * var user = _.immutable({\n * name: \"John\",\n * surname: \"Doe\",\n * login: {\n * username: \"jdoe\",\n * password: \"abc123\"\n * },\n * luckyNumbers: [13, 17]\n * });\n *\n * // All of these statements will fail and possibly\n * // throw a TypeError (see the function description)\n * user.name = \"Joe\";\n * delete user.name;\n * user.newProperty = [];\n * user.login.password = \"foo\";\n * user.luckyNumbers.push(-13);\n *\n * @memberof module:lamb\n * @category Object\n * @param {Object} obj\n * @returns {Object}\n */\n function immutable (obj) {\n return _immutable(obj, []);\n }\n\n /**\n * Retrieves the list of the own enumerable properties of an object.
\n * Although [Object.keys]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys}\n * is already present in ECMAScript 5, its behaviour changed in the subsequent specifications\n * of the standard.
\n * This function shims the ECMAScript 6 version, by forcing a conversion to\n * object for any value but null and undefined.\n * @example Showing the difference with {@link module:lamb.enumerables|enumerables}\n * var baseFoo = Object.create({a: 1}, {b: {value: 2}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3},\n * d: {value: 4, enumerable: true}\n * });\n *\n * _.enumerables(foo) // => [\"d\", \"a\"]\n * _.keys(foo) // => [\"d\"]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.enumerables|enumerables}\n * @param {Object} obj\n * @returns {String[]}\n */\n var keys = _unsafeKeyListFrom(_safeKeys);\n\n /**\n * Builds an object from the two given lists, using the first one as keys and the last\n * one as values.
\n * If the list of keys is longer than the values one, the keys will be created with\n * undefined values.
\n * If more values than keys are supplied, the extra values will be ignored.
\n * See also {@link module:lamb.tear|tear} and {@link module:lamb.tearOwn|tearOwn} for\n * the reverse operation.\n * @example\n * _.make([\"a\", \"b\", \"c\"], [1, 2, 3]) // => {a: 1, b: 2, c: 3}\n * _.make([\"a\", \"b\", \"c\"], [1, 2]) // => {a: 1, b: 2, c: undefined}\n * _.make([\"a\", \"b\"], [1, 2, 3]) // => {a: 1, b: 2}\n * _.make([null, void 0, 2], [1, 2, 3]) // => {\"null\": 1, \"undefined\": 2, \"2\": 3}\n *\n * @memberof module:lamb\n * @category Object\n * @param {String[]} names\n * @param {ArrayLike} values\n * @returns {Object}\n */\n function make (names, values) {\n var result = {};\n var valuesLen = values.length;\n\n for (var i = 0, len = names.length; i < len; i++) {\n result[names[i]] = i < valuesLen ? values[i] : void 0;\n }\n\n return result;\n }\n\n /**\n * Merges the enumerable properties of the provided sources into a new object.
\n * In case of key homonymy each source has precedence over the previous one.
\n * See also {@link module:lamb.mergeOwn|mergeOwn} for merging only own properties of\n * the given sources.\n * @example\n * _.merge({a: 1}, {b: 3, c: 4}, {b: 5}) // => {a: 1, b: 5, c: 4}\n *\n * @example Array-like objects will be transformed to objects with numbers as keys:\n * _.merge([1, 2], {a: 2}) // => {\"0\": 1, \"1\": 2, a: 2}\n * _.merge(\"foo\", {a: 2}) // => {\"0\": \"f\", \"1\": \"o\", \"2\": \"o\", a: 2}\n *\n * @example Every other value will be treated as an empty object:\n * _.merge({a: 2}, null, NaN) // => {a: 2}\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {...Object} source\n * @returns {Object}\n */\n var merge = partial(_merge, _safeEnumerables);\n\n /**\n * Same as {@link module:lamb.merge|merge}, but only the own properties of the\n * sources are taken into account.\n * @example showing the difference with merge:\n * var baseFoo = Object.create({a: 1}, {b: {value: 2, enumerable: true}, z: {value: 5}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3, enumerable: true}\n * });\n *\n * var bar = {d: 4};\n *\n * _.merge(foo, bar) // => {a: 1, b: 2, c: 3, d: 4}\n * _.mergeOwn(foo, bar) // => {c: 3, d: 4}\n *\n * @example Array-like objects will be transformed to objects with numbers as keys:\n * _.mergeOwn([1, 2], {a: 2}) // => {\"0\": 1, \"1\": 2, a: 2}\n * _.mergeOwn(\"foo\", {a: 2}) // => {\"0\": \"f\", \"1\": \"o\", \"2\": \"o\", a: 2}\n *\n * @example Every other value will be treated as an empty object:\n * _.mergeOwn({a: 2}, null, NaN) // => {a: 2}\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {...Object} source\n * @returns {Object}\n */\n var mergeOwn = partial(_merge, _safeKeys);\n\n /**\n * Same as {@link module:lamb.pairs|pairs}, but only the own enumerable properties of the object are\n * taken into account.
\n * See also {@link module:lamb.fromPairs|fromPairs} for the reverse operation.\n * @example showing the difference with pairs\n * var baseFoo = Object.create({a: 1}, {b: {value: 2, enumerable: true}, z: {value: 5}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3, enumerable: true}\n * });\n *\n * _.pairs(foo) // => [[\"c\", 3], [\"b\", 2], [\"a\", 1]]\n * _.ownPairs(foo) // => [[\"c\", 3]]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array>}\n */\n var ownPairs = _pairsFrom(keys);\n\n /**\n * Same as {@link module:lamb.values|values}, but only the own enumerable properties of the object are\n * taken into account.
\n * @example showing the difference with values\n * var baseFoo = Object.create({a: 1}, {b: {value: 2, enumerable: true}, z: {value: 5}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3, enumerable: true}\n * });\n *\n * _.values(foo) // => [3, 2, 1]\n * _.ownValues(foo) // => [3]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array}\n */\n var ownValues = _valuesFrom(keys);\n\n /**\n * Converts an object into an array of key / value pairs of its enumerable properties.
\n * See also {@link module:lamb.ownPairs|ownPairs} for picking only the own enumerable\n * properties and {@link module:lamb.fromPairs|fromPairs} for the reverse operation.\n * @example\n * _.pairs({a: 1, b: 2, c: 3}) // => [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array>}\n */\n var pairs = _pairsFrom(enumerables);\n\n /**\n * Builds a partial application of {@link module:lamb.pathExistsIn|pathExistsIn} using the given\n * path and the optional separator. The resulting function expects the object to check.
\n * Note that the function will check even non-enumerable properties.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * address: {\n * city: \"New York\"\n * },\n * scores: [10, 20, 15]\n * };\n *\n * var hasCity = _.pathExists(\"address.city\");\n * var hasCountry = _.pathExists(\"address.country\");\n * var hasAtLeastThreeScores = _.pathExists(\"scores.2\");\n *\n * hasCity(user) // => true\n * hasCountry(user) // => false\n * hasAtLeastThreeScores(user) // => true\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}\n * @param {String} path\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function pathExists (path, separator) {\n return function (obj) {\n return pathExistsIn(obj, path, separator);\n };\n }\n\n /**\n * Checks if the provided path exists in the given object.
\n * Note that the function will check even non-enumerable properties.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * address: {\n * city: \"New York\"\n * },\n * scores: [10, 20, 15]\n * };\n *\n * _.pathExistsIn(user, \"address.city\") // => true\n * _.pathExistsIn(user, \"address.country\") // => false\n * _.pathExistsIn(user, \"scores.1\") // => true\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.pathExists|pathExists}\n * @see {@link module:lamb.hasOwn|hasOwn}, {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.has|has}, {@link module:lamb.hasKey|hasKey}\n * @param {Object} obj\n * @param {String} path\n * @param {String} [separator=\".\"]\n * @returns {Boolean}\n */\n function pathExistsIn (obj, path, separator) {\n var pathInfo = _getPathInfo(obj, _toPathParts(path, separator), true);\n\n return pathInfo.isValid;\n }\n\n /**\n * Returns an object containing only the specified properties of the given object.
\n * Non existent properties will be ignored.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n *\n * _.pick(user, [\"name\", \"age\"]) // => {\"name\": \"john\", \"age\": 30};\n * _.pick(user, [\"name\", \"email\"]) // => {\"name\": \"john\"}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.pickIf|pickIf}, {@link module:lamb.pickKeys|pickKeys}\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipIf|skipIf}\n * @param {Object} source\n * @param {String[]} whitelist\n * @returns {Object}\n */\n function pick (source, whitelist) {\n var result = {};\n\n forEach(whitelist, function (key) {\n if (has(source, key)) {\n result[key] = source[key];\n }\n });\n\n return result;\n }\n\n /**\n * Builds a function expecting an object whose enumerable properties will be checked\n * against the given predicate.
\n * The properties satisfying the predicate will be included in the resulting object.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n * var pickIfIsString = _.pickIf(_.isType(\"String\"));\n *\n * pickIfIsString(user) // => {name: \"john\", surname: \"doe\"}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickKeys|pickKeys}\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipKeys|skipKeys},\n * {@link module:lamb.skipIf|skipIf}\n * @param {ObjectIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n function pickIf (predicate, predicateContext) {\n if (arguments.length === 2) {\n predicate = predicate.bind(predicateContext);\n }\n\n return function (source) {\n var result = {};\n\n forEach(enumerables(source), function (key) {\n if (predicate(source[key], key, source)) {\n result[key] = source[key];\n }\n });\n\n return result;\n };\n }\n\n /**\n * A curried version of {@link module:lamb.pick|pick}, expecting a whitelist of keys to build\n * a function waiting for the object to act upon.\n * @example\n * var user = {id: 1, name: \"Jane\", surname: \"Doe\", active: false};\n * var getUserInfo = _.pickKeys([\"id\", \"active\"]);\n *\n * getUserInfo(user) // => {id: 1, active: false}\n *\n * @example A useful composition with mapWith:\n * var users = [\n * {id: 1, name: \"Jane\", surname: \"Doe\", active: false},\n * {id: 2, name: \"John\", surname: \"Doe\", active: true},\n * {id: 3, name: \"Mario\", surname: \"Rossi\", active: true},\n * {id: 4, name: \"Paolo\", surname: \"Bianchi\", active: false}\n * ];\n * var select = _.compose(_.mapWith, _.pickKeys);\n * var selectUserInfo = select([\"id\", \"active\"]);\n *\n * selectUserInfo(users) // =>\n * // [\n * // {id: 1, active: false},\n * // {id: 2, active: true},\n * // {id: 3, active: true},\n * // {id: 4, active: false}\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickIf|pickIf}\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipKeys|skipKeys},\n * {@link module:lamb.skipIf|skipIf}\n * @param {String[]} whitelist\n * @returns {Function}\n */\n var pickKeys = _curry(pick, 2, true);\n\n /**\n * Creates a copy of the given object with its enumerable keys renamed as\n * indicated in the provided lookup table.\n * @example\n * var person = {\"firstName\": \"John\", \"lastName\": \"Doe\"};\n * var keysMap = {\"firstName\": \"name\", \"lastName\": \"surname\"};\n *\n * _.rename(person, keysMap) // => {\"name\": \"John\", \"surname\": \"Doe\"}\n *\n * @example It's safe using it to swap keys:\n * var keysMap = {\"firstName\": \"lastName\", \"lastName\": \"firstName\"};\n *\n * _.rename(person, keysMap) // => {\"lastName\": \"John\", \"firstName\": \"Doe\"}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.renameKeys|renameKeys}, {@link module:lamb.renameWith|renameWith}\n * @param {Object} source\n * @param {Object} keysMap\n * @returns {Object}\n */\n function rename (source, keysMap) {\n keysMap = Object(keysMap);\n var result = {};\n var oldKeys = enumerables(source);\n\n for (var prop in keysMap) {\n if (~oldKeys.indexOf(prop)) {\n result[keysMap[prop]] = source[prop];\n }\n }\n\n for (var i = 0, len = oldKeys.length, key; i < len; i++) {\n key = oldKeys[i];\n\n if (!(key in keysMap || key in result)) {\n result[key] = source[key];\n }\n }\n\n return result;\n }\n\n /**\n * A curried version of {@link module:lamb.rename|rename} expecting a\n * keysMap to build a function waiting for the object to act upon.\n * @example\n * var persons = [\n * {\"firstName\": \"John\", \"lastName\": \"Doe\"},\n * {\"first_name\": \"Mario\", \"last_name\": \"Rossi\"},\n * ];\n * var normalizeKeys = _.renameKeys({\n * \"firstName\": \"name\",\n * \"first_name\": \"name\",\n * \"lastName\": \"surname\",\n * \"last_name\": \"surname\"\n * });\n *\n * persons.map(normalizeKeys) // =>\n * // [\n * // {\"name\": \"John\", \"surname\": \"Doe\"},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.rename|rename}, {@link module:lamb.renameWith|renameWith}\n * @param {Object} keysMap\n * @returns {Function}\n */\n var renameKeys = _curry(rename, 2, true);\n\n /**\n * Uses the provided function as a keysMap generator and returns\n * a function expecting the object whose keys we want to {@link module:lamb.rename|rename}.\n * @example\n * var person = {\"NAME\": \"John\", \"SURNAME\": \"Doe\"};\n * var makeLowerKeysMap = function (source) {\n * var sourceKeys = _.keys(source);\n * return _.make(sourceKeys, sourceKeys.map(_.invoker(\"toLowerCase\")));\n * };\n * var lowerKeysFor = _.renameWith(makeLowerKeysMap);\n *\n * lowerKeysFor(person) // => {\"name\": \"John\", \"surname\": \"doe\"};\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.rename|rename}, {@link module:lamb.renameKeys|renameKeys}\n * @param {Function} fn\n * @returns {Function}\n */\n function renameWith (fn) {\n return function (source) {\n return rename(source, fn(source));\n };\n }\n\n /**\n * Returns a copy of the source object without the specified properties.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n *\n * _.skip(user, [\"name\", \"age\"]) // => {surname: \"doe\"};\n * _.skip(user, [\"name\", \"email\"]) // => {surname: \"doe\", age: 30};\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.skipKeys|skipKeys}, {@link module:lamb.skipIf|skipIf}\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickKeys|pickKeys},\n * {@link module:lamb.pickIf|pickIf}\n * @param {Object} source\n * @param {String[]} blacklist\n * @returns {Object}\n */\n function skip (source, blacklist) {\n var result = {};\n\n forEach(enumerables(source), function (key) {\n if (!isIn(blacklist, key)) {\n result[key] = source[key];\n }\n });\n\n return result;\n }\n\n /**\n * Builds a function expecting an object whose enumerable properties will be checked\n * against the given predicate.
\n * The properties satisfying the predicate will be omitted in the resulting object.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n * var skipIfIstring = _.skipIf(_.isType(\"String\"));\n *\n * skipIfIstring(user) // => {age: 30}\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipKeys|skipKeys}\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickKeys|pickKeys},\n * {@link module:lamb.pickIf|pickIf}\n * @param {ObjectIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var skipIf = tapArgs(pickIf, not);\n\n /**\n * A curried version of {@link module:lamb.skip|skip}, expecting a blacklist of keys to build\n * a function waiting for the object to act upon.\n * @example\n * var user = {id: 1, name: \"Jane\", surname: \"Doe\", active: false};\n * var getUserInfo = _.skipKeys([\"name\", \"surname\"]);\n *\n * getUserInfo(user) // => {id: 1, active: false}\n *\n * @example A useful composition with mapWith:\n * var users = [\n * {id: 1, name: \"Jane\", surname: \"Doe\", active: false},\n * {id: 2, name: \"John\", surname: \"Doe\", active: true},\n * {id: 3, name: \"Mario\", surname: \"Rossi\", active: true},\n * {id: 4, name: \"Paolo\", surname: \"Bianchi\", active: false}\n * ];\n * var discard = _.compose(_.mapWith, _.skipKeys);\n * var discardNames = discard([\"name\", \"surname\"]);\n *\n * discardNames(users) // =>\n * // [\n * // {id: 1, active: false},\n * // {id: 2, active: true},\n * // {id: 3, active: true},\n * // {id: 4, active: false}\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipIf|skipIf}\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickKeys|pickKeys},\n * {@link module:lamb.pickIf|pickIf}\n * @param {String[]} blacklist\n * @returns {Function}\n */\n var skipKeys = _curry(skip, 2, true);\n\n /**\n * Tears an object apart by transforming it in an array of two lists: one containing\n * its enumerable keys, the other containing the corresponding values.
\n * Although this \"tearing apart\" may sound as a rather violent process, the source\n * object will be unharmed.
\n * See also {@link module:lamb.tearOwn|tearOwn} for picking only the own enumerable properties and\n * {@link module:lamb.make|make} for the reverse operation.\n * @example\n * _.tear({a: 1, b: 2, c: 3}) // => [[\"a\", \"b\", \"c\"], [1, 2, 3]]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array, Array<*>>}\n */\n var tear = _tearFrom(enumerables);\n\n /**\n * Same as {@link module:lamb.tear|tear}, but only the own properties of the object are\n * taken into account.
\n * See also {@link module:lamb.make|make} for the reverse operation.\n * @example showing the difference with tear\n * var baseFoo = Object.create({a: 1}, {b: {value: 2, enumerable: true}, z: {value: 5}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3, enumerable: true}\n * });\n *\n * _.tear(foo) // => [[\"c\", \"b\", \"a\"], [3, 2, 1]]\n * _.tearOwn(foo) // => [[\"c\"], [3]]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array, Array<*>>}\n */\n var tearOwn = _tearFrom(keys);\n\n /**\n * Validates an object with the given list of {@link module:lamb.checker|checker} functions.\n * @example\n * var hasContent = function (s) { return s.trim().length > 0; };\n * var isAdult = function (age) { return age >= 18; };\n * var userCheckers = [\n * _.checker(hasContent, \"Name is required\", [\"name\"]),\n * _.checker(hasContent, \"Surname is required\", [\"surname\"]),\n * _.checker(isAdult, \"Must be at least 18 years old\", [\"age\"])\n * ];\n *\n * var user1 = {name: \"john\", surname: \"doe\", age: 30};\n * var user2 = {name: \"jane\", surname: \"\", age: 15};\n *\n * _.validate(user1, userCheckers) // => []\n * _.validate(user2, userCheckers) // =>\n * // [\n * // [\"Surname is required\", [\"surname\"]],\n * // [\"Must be at least 18 years old\", [\"age\"]]\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.validateWith|validateWith}\n * @see {@link module:lamb.checker|checker}\n * @param {Object} obj\n * @param {Function[]} checkers\n * @returns {Array>} An array of errors in the form returned by\n * {@link module:lamb.checker|checker}, or an empty array.\n */\n function validate (obj, checkers) {\n return reduce(checkers, function (errors, _checker) {\n var result = _checker(obj);\n\n result.length && errors.push(result);\n\n return errors;\n }, []);\n }\n\n /**\n * A curried version of {@link module:lamb.validate|validate} accepting a list of\n * {@link module:lamb.checker|checkers} and returning a function expecting the object to validate.\n * @example\n * var hasContent = function (s) { return s.trim().length > 0; };\n * var isAdult = function (age) { return age >= 18; };\n * var userCheckers = [\n * _.checker(hasContent, \"Name is required\", [\"name\"]),\n * _.checker(hasContent, \"Surname is required\", [\"surname\"]),\n * _.checker(isAdult, \"Must be at least 18 years old\", [\"age\"])\n * ];\n * var validateUser = _.validateWith(userCheckers);\n *\n * var user1 = {name: \"john\", surname: \"doe\", age: 30};\n * var user2 = {name: \"jane\", surname: \"\", age: 15};\n *\n * validateUser(user1) // => []\n * validateUser(user2) // =>\n * // [\n * // [\"Surname is required\", [\"surname\"]],\n * // [\"Must be at least 18 years old\", [\"age\"]]\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.validate|validate}\n * @see {@link module:lamb.checker|checker}\n * @function\n * @param {Function[]} checkers\n * @returns {Function}\n */\n var validateWith = _curry(validate, 2, true);\n\n /**\n * Generates an array with the values of the enumerable properties of the given object.
\n * See also {@link module:lamb.ownValues|ownValues} for picking only the own properties of the object.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n *\n * _.values(user) // => [\"john\", \"doe\", 30]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array}\n */\n var values = _valuesFrom(enumerables);\n\n lamb.checker = checker;\n lamb.enumerables = enumerables;\n lamb.fromPairs = fromPairs;\n lamb.has = has;\n lamb.hasKey = hasKey;\n lamb.hasKeyValue = hasKeyValue;\n lamb.hasOwn = hasOwn;\n lamb.hasOwnKey = hasOwnKey;\n lamb.hasPathValue = hasPathValue;\n lamb.immutable = immutable;\n lamb.keys = keys;\n lamb.make = make;\n lamb.merge = merge;\n lamb.mergeOwn = mergeOwn;\n lamb.ownPairs = ownPairs;\n lamb.ownValues = ownValues;\n lamb.pairs = pairs;\n lamb.pathExists = pathExists;\n lamb.pathExistsIn = pathExistsIn;\n lamb.pick = pick;\n lamb.pickIf = pickIf;\n lamb.pickKeys = pickKeys;\n lamb.rename = rename;\n lamb.renameKeys = renameKeys;\n lamb.renameWith = renameWith;\n lamb.skip = skip;\n lamb.skipIf = skipIf;\n lamb.skipKeys = skipKeys;\n lamb.tear = tear;\n lamb.tearOwn = tearOwn;\n lamb.validate = validate;\n lamb.validateWith = validateWith;\n lamb.values = values;\n\n /**\n * Pads a string to the desired length with the given char starting from the beginning of the string.\n * @example\n * _.padLeft(\"foo\", \"-\", 0) // => \"foo\"\n * _.padLeft(\"foo\", \"-\", -1) // => \"foo\"\n * _.padLeft(\"foo\", \"-\", 5) // => \"--foo\"\n * _.padLeft(\"foo\", \"-\", 3) // => \"foo\"\n * _.padLeft(\"foo\", \"ab\", 7) // => \"aaaafoo\"\n * _.padLeft(\"foo\", \"\", 5) // => \" foo\"\n * _.padLeft(\"\", \"-\", 5) // => \"-----\"\n *\n * @memberof module:lamb\n * @category String\n * @param {String} source\n * @param {String} [char=\" \"] - The padding char. If a string is passed only the first char is used.\n * @param {Number} len\n * @returns {String}\n */\n function padLeft (source, char, len) {\n return _getPadding(source, char, len) + source;\n }\n\n /**\n * Pads a string to the desired length with the given char starting from the end of the string.\n * @example\n * _.padRight(\"foo\", \"-\", 0) // => \"foo\"\n * _.padRight(\"foo\", \"-\", -1) // => \"foo\"\n * _.padRight(\"foo\", \"-\", 5) // => \"foo--\"\n * _.padRight(\"foo\", \"-\", 3) // => \"foo\"\n * _.padRight(\"foo\", \"ab\", 7) // => \"fooaaaa\"\n * _.padRight(\"foo\", \"\", 5) // => \"foo \"\n * _.padRight(\"\", \"-\", 5) // => \"-----\"\n *\n * @memberof module:lamb\n * @category String\n * @param {String} source\n * @param {String} [char=\" \"] - The padding char. If a string is passed only the first char is used.\n * @param {Number} len\n * @returns {String}\n */\n function padRight (source, char, len) {\n return source + _getPadding(source, char, len);\n }\n\n /**\n * Builds a new string by repeating the source string the desired amount of times.
\n * Note that unlike the current ES6 proposal for\n * [String.prototype.repeat]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat},\n * this function doesn't throw a RangeError if times is negative,\n * but returns an empty string instead.\n * @example\n * _.repeat(\"Hello\", -1) // => \"\"\n * _.repeat(\"Hello\", 1) // => \"Hello\"\n * _.repeat(\"Hello\", 3) // => \"HelloHelloHello\"\n *\n * @memberof module:lamb\n * @category String\n * @param {String} source\n * @param {Number} times\n * @returns {String}\n */\n function repeat (source, times) {\n var result = \"\";\n\n for (var i = 0; i < times; i++) {\n result += source;\n }\n\n return result;\n }\n\n /**\n * Builds a predicate expecting a string to test against the given regular expression pattern.\n * @example\n * var hasNumbersOnly = _.testWith(/^\\d+$/);\n *\n * hasNumbersOnly(\"123\") // => true\n * hasNumbersOnly(\"123 Kg\") // => false\n *\n * @memberof module:lamb\n * @category String\n * @param {RegExp} pattern\n * @returns {Function}\n */\n function testWith (pattern) {\n return _reProto.test.bind(pattern);\n }\n\n lamb.padLeft = padLeft;\n lamb.padRight = padRight;\n lamb.repeat = repeat;\n lamb.testWith = testWith;\n\n /* istanbul ignore next */\n if (typeof exports === \"object\") {\n module.exports = lamb;\n } else if (typeof define === \"function\" && define.amd) {\n define(function () {\n return lamb;\n });\n } else {\n host.lamb = lamb;\n }\n})(this);\n\n/**\n * @callback AccumulatorCallback\n * @global\n * @param {*} previousValue - The value returned it the last execution of the accumulator or, in the first\n * iteration, the {@link module:lamb.reduce|initialValue} if supplied.\n * @param {*} currentValue - The value being processed in the current iteration.\n * @param {Number} idx - The index of the element being processed.\n * @param {ArrayLike} arrayLike - The list being traversed.\n */\n\n/**\n * The built-in arguments object.\n * @typedef {arguments} arguments\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments|arguments} in Mozilla documentation.\n */\n\n/**\n * The built-in Array object.\n * @typedef {Array} Array\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array|Array} in Mozilla documentation.\n */\n\n/**\n * Any array-like object.\n * @typedef {Array|String|arguments|?} ArrayLike\n * @global\n */\n\n/**\n * The built-in Boolean object.\n * @typedef {Boolean} Boolean\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean|Boolean} in Mozilla documentation.\n */\n\n/**\n * The built-in Date object.\n * @typedef {Date} Date\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date|Date} in Mozilla documentation.\n */\n\n/**\n * The built-in Function object.\n * @typedef {Function} function\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function|Function} and\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions|Functions} in Mozilla documentation.\n */\n\n/**\n * @callback ListIteratorCallback\n * @global\n * @param {*} element - The element being evaluated.\n * @param {Number} idx - The index of the element within the list.\n * @param {ArrayLike} arrayLike - The list being traversed.\n */\n\n/**\n * The built-in Number object.\n * @typedef {Number} Number\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number|Number} in Mozilla documentation.\n */\n\n/**\n * The built-in Object object.\n * @typedef {Object} Object\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object|Object} in Mozilla documentation.\n */\n\n/**\n * @callback ObjectIteratorCallback\n * @global\n * @param {*} value - The value of the current property.\n * @param {String} key - The property name.\n * @param {Object} source - The object being traversed.\n */\n\n/**\n * The built-in RegExp object.\n * @typedef {RegExp} RegExp\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp|RegExp} in Mozilla documentation.\n */\n\n/**\n * Represent a sorting criteria used by {@link module:lamb.sortedInsert|sortedInsert},\n * {@link module:lamb.sort|sort} and {@link module:lamb.sortWith|sortWith}, and it's\n * usually built using {@link module:lamb.sorter|sorter} and {@link module:lamb.sorterDesc|sorterDesc}.\n * @typedef {Sorter} Sorter\n * @global\n * @property {Boolean} isDescending\n * @property {Function} compare\n */\n\n/**\n * The built-in String object.\n * @typedef {String} String\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String|String} in Mozilla documentation.\n */\n\n/**\n * The built-in primitive value undefined\n * @typedef {Undefined} Undefined\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined|undefined} in Mozilla documentation.\n */\n"]} \ No newline at end of file +{"version":3,"sources":["lamb.js"],"names":["host","always","value","compose","functions","arguments","args","len","length","apply","this","identity","partial","fn","_argsTail","boundArg","lastIdx","newArgs","argsLen","i","_","_argsToArrayFrom","idx","result","Array","_asPartial","argsHolder","argsHolderLen","canApply","_comparer","a","b","String","isSVZ","_compareWith","criteria","isDescSort","criterion","compare","isDescending","index","_currier","arity","isRightCurry","isAutoCurry","holderLen","newArgsLen","reverse","_curry","_flatten","array","isDeep","output","j","vLen","isArray","_getInsertionIndex","element","comparer","start","end","pivot","_getNaturalIndex","target","_isInteger","clamp","_getNumConsecutiveHits","arrayLike","predicate","predicateContext","bind","_getPadding","source","char","isNil","type","repeat","Object","Math","ceil","_getPathInfo","obj","parts","walkNonEnumerables","_makeTypeErrorFor","key","_getPathKey","isUndefined","isValid","includeNonEnumerables","_isEnumerable","keyAsNumber","Number","_groupWith","makeValue","iteratee","iterateeContext","_immutable","seen","indexOf","push","freeze","forEach","getOwnPropertyNames","isNull","_invoker","boundArgs","methodName","method","boundArgsLen","ofs","_isArrayIndex","n","_isOwnEnumerable","_safeEnumerables","floor","_keyToPairIn","_makeArrayChecker","defaultResult","_makeCriteria","sorters","map","_makeCriterion","_sorter","_makeReducer","step","accumulator","initialValue","nCalls","TypeError","desiredType","toLowerCase","_merge","getKeys","reduce","_partialWithIteratee","optionalArgument","f","binary","_setIn","prop","_setIndex","updater","slice","_setPathIn","v","targetKey","reader","_toPathParts","path","separator","split","contains","fromIndex","isIn","filter","find","findIndex","adapter","list","allOf","predicates","anyOf","condition","trueFn","falseFn","is","isGT","isGTE","isLT","isLTE","not","unless","call","when","add","min","max","divide","generate","limit","modulo","multiply","randomInt","random","range","remainder","subtract","isType","typeName","_objectProto","toString","getAt","getIndex","getIn","getKey","getPath","getPathIn","pathInfo","setAt","setIn","setKey","setPath","setPathIn","updateAt","updateIn","enumerables","updateKey","updatePath","updatePathIn","difference","rest","shallowFlatten","unary","isInRest","dropN","dropWhile","flatMap","el","arr","rLen","flatten","insert","splice","insertAt","intersection","uniques","item","everyIn","partition","pluck","take","takeN","takeWhile","transpose","elementLen","minLen","hasNaN","sort","data","sortedInsert","sortWith","concat","applyArgs","aritize","asPartial","collect","curry","curryable","curryableRight","curryRight","debounce","timespan","timeoutID","debounced","clearTimeout","setTimeout","flip","getArgAt","invoker","invokerOn","mapArgs","mapper","mapWith","tapArgs","tappers","tappersLen","throttle","lastCall","now","Date","checker","message","keyPaths","pathSeparator","getValues","fromPairs","pairsList","pair","has","hasKey","hasKeyValue","hasOwnKey","hasOwn","hasPathValue","immutable","make","names","values","valuesLen","pathExists","pathExistsIn","pick","whitelist","pickIf","rename","keysMap","oldKeys","renameWith","skip","blacklist","validate","checkers","errors","_checker","padLeft","padRight","times","testWith","pattern","_reProto","test","lamb","create","_version","_arrayProto","prototype","RegExp","generic","Function","propertyIsEnumerable","_pairsFrom","_safeKeys","keys","_tearFrom","_unsafeKeyListFrom","_valuesFrom","every","filterWith","findIndexWhere","findWhere","reduceRight","reduceRightWith","reduceWith","someIn","some","isNot","head","last","setIndex","updateIndex","drop","flatMapWith","init","partitionWith","pluckKey","tail","union","zip","zipWithIndex","count","countBy","group","groupBy","indexBy","sorter","sorterDesc","pipe","wrap","hasOwnProperty","merge","mergeOwn","ownPairs","ownValues","pairs","pickKeys","renameKeys","skipIf","skipKeys","tear","tearOwn","validateWith","exports","module","define","amd"],"mappings":";;;;;;;;CAQA,SAAWA,GACP,YA4CA,SAASC,GAAQC,GACb,MAAO,YACH,MAAOA,IA4Bf,QAASC,KACL,GAAIC,GAAYC,SAEhB,OAAO,YAIH,IAHA,GAAIC,GAAOD,UACPE,EAAMH,EAAUI,OAEbD,KACHD,GAAQF,EAAUG,GAAKE,MAAMC,KAAMJ,GAGvC,OAA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YA,GACjBnD,GAAKoD,MAAQA,GACbpD,GAAKtB,WAAaA,GAClBsB,GAAKrB,aAAeA,GACpBqB,GAAKpB,KAAOA,GACZoB,GAAKlB,OAASA,GACdkB,GAAKqD,SAAWA,GAChBrD,GAAKjB,OAASA,GACdiB,GAAKsD,WAAaA,GAClBtD,GAAKd,WAAaA,GAClBc,GAAKb,KAAOA,GACZa,GAAKuD,OAASA,GACdvD,GAAKwD,SAAWA,GAChBxD,GAAKyD,KAAOA,GACZzD,GAAK0D,QAAUA,GACf1D,GAAKX,SAAWA,GAChBW,GAAK2D,aAAeA,GACpB3D,GAAKxB,OAASA,GA0FdwB,GAAKP,QAAUA,GACfO,GAAKN,SAAWA,GAChBM,GAAK5O,OAASA,GACd4O,GAAKJ,SAAWA,GAGO,gBAAZgE,SACPC,OAAOD,QAAU5D,GACQ,kBAAX8D,SAAyBA,OAAOC,IAC9CD,OAAO,WACH,MAAO9D,MAGXxT,EAAKwT,KAAOA,IAEjB9S","file":"lamb.min.js","sourcesContent":["/**\n * @overview lamb - A lightweight, and docile, JavaScript library to help embracing functional programming.\n * @author Andrea Scartabelli \n * @version 0.43.0\n * @module lamb\n * @license MIT\n * @preserve\n */\n(function (host) {\n \"use strict\";\n\n var lamb = Object.create(null);\n\n /**\n * The current module version.\n * @memberof module:lamb\n * @private\n * @category Core\n * @type String\n */\n lamb._version = \"0.43.0\";\n\n // alias used as a placeholder argument for partial application\n var _ = lamb;\n\n // some prototype shortcuts for internal use\n var _arrayProto = Array.prototype;\n var _objectProto = Object.prototype;\n var _reProto = RegExp.prototype;\n\n /**\n * Builds a function that returns a constant value.\n * It's actually the simplest form of the K combinator or Kestrel.\n * @example\n * var truth = _.always(true);\n *\n * truth() // => true\n * truth(false) // => true\n * truth(1, 2) // => true\n *\n * // the value being returned is actually the\n * // very same value passed to the function\n * var foo = {bar: \"baz\"};\n * var alwaysFoo = _.always(foo);\n *\n * alwaysFoo() === foo // => true\n *\n * @memberof module:lamb\n * @category Core\n * @see [SKI combinator calculus]{@link https://en.wikipedia.org/wiki/SKI_combinator_calculus}\n * @param {*} value\n * @returns {Function}\n */\n function always (value) {\n return function () {\n return value;\n };\n }\n\n /**\n * Returns a function that is the composition of the functions given as parameters.\n * Each function consumes the result of the function that follows.\n * @example\n * var sayHi = function (name) { return \"Hi, \" + name; };\n * var capitalize = function (s) {\n * return s[0].toUpperCase() + s.substr(1).toLowerCase();\n * };\n * var fixNameAndSayHi = _.compose(sayHi, capitalize);\n *\n * sayHi(\"bOb\") // => \"Hi, bOb\"\n * fixNameAndSayHi(\"bOb\") // \"Hi, Bob\"\n *\n * var getName = _.getKey(\"name\");\n * var users = [{name: \"fred\"}, {name: \"bOb\"}];\n * var sayHiToUser = _.compose(fixNameAndSayHi, getName);\n *\n * users.map(sayHiToUser) // [\"Hi, Fred\", \"Hi, Bob\"]\n *\n * @memberof module:lamb\n * @category Function\n * @param {...Function} fn\n * @returns {Function}\n */\n function compose () {\n var functions = arguments;\n\n return function () {\n var args = arguments;\n var len = functions.length;\n\n while (len--) {\n args = [functions[len].apply(this, args)];\n }\n\n return args[0];\n };\n }\n\n /**\n * Creates generic functions out of methods.\n * @memberof module:lamb\n * @category Core\n * @author A very little change on a great idea by [Irakli Gozalishvili]{@link https://github.com/Gozala/}.\n * Thanks for this *beautiful* one-liner (never liked your \"unbind\" naming choice, though).\n * @function\n * @example\n * // Lamb's \"slice\" is actually implemented like this\n * var slice = _.generic(Array.prototype.slice);\n *\n * slice([\"foo\", \"bar\", \"baz\"], 0, -1) // => [\"foo\", \"bar\"]\n *\n * // the function will work with any array-like object\n * slice(\"fooBAR\", 0, 3) // => [\"f\", \"o\", \"o\"]\n *\n * @param {Function} method\n * @returns {Function}\n */\n var generic = Function.bind.bind(Function.call);\n\n /**\n * The I combinator. Any value passed to the function is simply returned as it is.\n * @example\n * var foo = {bar: \"baz\"};\n *\n * _.identity(foo) === foo // true\n *\n * @memberof module:lamb\n * @category Core\n * @see [SKI combinator calculus]{@link https://en.wikipedia.org/wiki/SKI_combinator_calculus}\n * @param {*} value\n * @returns {*} The value passed as parameter.\n */\n function identity (value) {\n return value;\n }\n\n /**\n * Builds a partially applied function. The lamb object itself can be used\n * as a placeholder argument and it's useful to alias it with a short symbol such as _.\n * @example\n * var weights = [\"2 Kg\", \"10 Kg\", \"1 Kg\", \"7 Kg\"];\n * var parseInt10 = _.partial(parseInt, _, 10);\n *\n * weights.map(parseInt10) // => [2, 10, 1, 7]\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.asPartial|asPartial}\n * @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}\n * @param {Function} fn\n * @param {...*} args\n * @returns {Function}\n */\n function partial (fn) {\n var args = _argsTail.apply(null, arguments);\n\n return function () {\n var lastIdx = 0;\n var newArgs = [];\n var argsLen = args.length;\n\n for (var i = 0, boundArg; i < argsLen; i++) {\n boundArg = args[i];\n newArgs[i] = boundArg === _ ? arguments[lastIdx++] : boundArg;\n }\n\n for (var len = arguments.length; lastIdx < len; lastIdx++) {\n newArgs[i++] = arguments[lastIdx];\n }\n\n return fn.apply(this, newArgs);\n };\n }\n\n lamb.always = always;\n lamb.compose = compose;\n lamb.generic = generic;\n lamb.identity = identity;\n lamb.partial = partial;\n\n /**\n * Builds an array with the received arguments excluding the first one.
\n * To be used with the arguments object, which needs to be passed to the apply\n * method of this function.\n * @private\n * @function\n * @param {...*} value\n * @returns {Array}\n */\n var _argsTail = _argsToArrayFrom(1);\n\n /**\n * Builds helper functions to extract portions of the arguments\n * object rather efficiently without having to write for loops\n * manually for each case.
\n * The arguments object needs to be passed to the apply method\n * of the generated function.\n * @private\n * @param {Number} idx\n * @returns {Function}\n */\n function _argsToArrayFrom (idx) {\n return function () {\n var argsLen = arguments.length || idx;\n var len = argsLen - idx;\n var result = Array(len);\n\n for (var i = 0; i < len; i++) {\n result[i] = arguments[i + idx];\n }\n\n return result;\n };\n }\n\n /**\n * Keeps building a partial application of the received function as long\n * as it's called with placeholders; applies the original function with\n * the collected parameters otherwise.\n * @private\n * @param {Function} fn\n * @param {Array} argsHolder\n * @returns {Function|*}\n */\n function _asPartial (fn, argsHolder) {\n return function () {\n var argsHolderLen = argsHolder.length;\n var argsLen = arguments.length;\n var lastIdx = 0;\n var newArgs = [];\n var canApply = true;\n\n for (var i = 0; i < argsLen; i++) {\n if (arguments[i] === _) {\n canApply = false;\n break;\n }\n }\n\n for (var idx = 0, boundArg; idx < argsHolderLen; idx++) {\n boundArg = argsHolder[idx];\n newArgs[idx] = lastIdx < argsLen && boundArg === _ ? arguments[lastIdx++] : boundArg;\n }\n\n while (lastIdx < argsLen) {\n newArgs[idx++] = arguments[lastIdx++];\n }\n\n return canApply ? fn.apply(this, newArgs) : _asPartial(fn, newArgs);\n };\n }\n\n /**\n * The default comparer for sorting functions.
\n * If the given values are of different types they\n * will be both converted to strings.
\n * Uses the SameValueZero comparison.\n * @private\n * @param {*} a\n * @param {*} b\n * @returns {Number} -1 | 0 | 1\n */\n function _comparer (a, b) {\n var result = 0;\n\n if (typeof a !== typeof b) {\n a = String(a);\n b = String(b);\n }\n\n /* eslint-disable no-self-compare */\n\n if (!isSVZ(a, b)) {\n if (a > b || a !== a) {\n result = 1;\n } else if (a < b || b !== b) {\n result = -1;\n }\n }\n\n /* eslint-enable no-self-compare */\n\n return result;\n }\n\n /**\n * Accepts a list of sorting criteria and builds a function that compares\n * two values with such criteria.\n * @private\n * @param {Sorter[]} criteria\n * @returns {Function}\n */\n function _compareWith (criteria) {\n var len = criteria.length;\n\n return function (a, b) {\n var result = 0;\n var isDescSort;\n var criterion;\n\n for (var i = 0; i < len; i++) {\n criterion = criteria[i];\n result = criterion.compare(a.value, b.value);\n\n if (result !== 0) {\n isDescSort = criteria[i].isDescending;\n break;\n }\n }\n\n if (result === 0) {\n isDescSort = criteria[len - 1].isDescending;\n result = a.index - b.index;\n }\n\n return isDescSort ? -result : result;\n };\n }\n\n /**\n * Used by curry functions to collect arguments until the arity is consumed,\n * then applies the original function.\n * @private\n * @param {Function} fn\n * @param {Number} arity\n * @param {Boolean} isRightCurry\n * @param {Boolean} isAutoCurry\n * @param {Array} argsHolder\n * @returns {Function}\n */\n function _currier (fn, arity, isRightCurry, isAutoCurry, argsHolder) {\n return function () {\n var holderLen = argsHolder.length;\n var argsLen = arguments.length;\n var newArgsLen = holderLen + (argsLen > 1 && isAutoCurry ? argsLen : 1);\n var newArgs = Array(newArgsLen);\n\n for (var i = 0; i < holderLen; i++) {\n newArgs[i] = argsHolder[i];\n }\n\n for (; i < newArgsLen; i++) {\n newArgs[i] = arguments[i - holderLen];\n }\n\n if (newArgsLen >= arity) {\n return fn.apply(this, isRightCurry ? newArgs.reverse() : newArgs);\n } else {\n return _currier(fn, arity, isRightCurry, isAutoCurry, newArgs);\n }\n };\n }\n\n /**\n * Prepares a function for currying by setting the proper arity for\n * the _currier function.\n * If the desumed arity isn't greater than one, it will return the received\n * function itself, instead.\n * @private\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @param {Boolean} isRightCurry\n * @param {Boolean} isAutoCurry\n * @returns {Function}\n */\n function _curry (fn, arity, isRightCurry, isAutoCurry) {\n if (arity >>> 0 !== arity) {\n arity = fn.length;\n }\n\n return arity > 1 ? _currier(fn, arity, isRightCurry, isAutoCurry, []) : fn;\n }\n\n /**\n * Flattens an array.\n * @private\n * @param {Array} array - The source array\n * @param {Boolean} isDeep - Whether to perform a deep flattening or not\n * @param {Array} output - An array to collect the result\n * @param {Number} idx - The next index to be filled in the output\n * @returns {Array} The output array filled with the results\n */\n function _flatten (array, isDeep, output, idx) {\n for (var i = 0, len = array.length, value, j, vLen; i < len; i++) {\n value = array[i];\n\n if (!Array.isArray(value)) {\n output[idx++] = value;\n } else if (isDeep) {\n _flatten(value, true, output, idx);\n idx = output.length;\n } else {\n vLen = value.length;\n output.length += vLen;\n\n for (j = 0; j < vLen; j++) {\n output[idx++] = value[j];\n }\n }\n }\n\n return output;\n }\n\n /**\n * Establishes at which index an element should be inserted in a sorted array to respect\n * the array order. Needs the comparer used to sort the array.\n * @private\n * @param {Array} array\n * @param {*} element\n * @param {Function} comparer\n * @param {Number} start\n * @param {Number} end\n * @returns {Number}\n */\n function _getInsertionIndex (array, element, comparer, start, end) {\n if (array.length === 0) {\n return 0;\n }\n\n var pivot = (start + end) >> 1;\n var result = comparer({\n value: element,\n index: pivot\n }, {\n value: array[pivot],\n index: pivot\n });\n\n if (end - start <= 1) {\n return result < 0 ? pivot : pivot + 1;\n } else if (result < 0) {\n return _getInsertionIndex(array, element, comparer, start, pivot);\n } else if (result === 0) {\n return pivot + 1;\n } else {\n return _getInsertionIndex(array, element, comparer, pivot, end);\n }\n }\n\n /**\n * Checks if the given index, even negative, exists in the target object, if\n * it's an array-like, and transforms it to a natural number.\n * Returns undefined otherwise.\n * @private\n * @param {ArrayLike} target\n * @param {Number} index\n * @returns {Number|Undefined}\n */\n function _getNaturalIndex (target, index) {\n var len = target.length;\n\n if (_isInteger(index) && _isInteger(len)) {\n return clamp(index, -len, len - 1) === index ? index < 0 ? index + len : index : void 0;\n } else {\n return void 0;\n }\n }\n\n /**\n * Gets the number of consecutive elements satisfying a predicate in an array-like object.\n * @private\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Number}\n */\n function _getNumConsecutiveHits (arrayLike, predicate, predicateContext) {\n var idx = 0;\n var len = arrayLike.length;\n\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n while (idx < len && predicate(arrayLike[idx], idx, arrayLike)) {\n idx++;\n }\n\n return idx;\n }\n\n /**\n * Builds the prefix or suffix to be used when padding a string.\n * @private\n * @param {String} source\n * @param {String} char\n * @param {Number} len\n * @returns {String}\n */\n function _getPadding (source, char, len) {\n if (!isNil(source) && type(source) !== \"String\") {\n source = String(source);\n }\n\n return repeat(Object(char)[0] || \" \", Math.ceil(len - source.length));\n }\n\n /**\n * Checks if a path is valid in the given object and retrieves the path target.\n * @private\n * @param {Object} obj\n * @param {String[]} parts\n * @param {Boolean} walkNonEnumerables\n * @returns {Object}\n */\n function _getPathInfo (obj, parts, walkNonEnumerables) {\n if (isNil(obj)) {\n throw _makeTypeErrorFor(obj, \"object\");\n }\n\n var target = obj;\n var i = -1;\n var len = parts.length;\n var key;\n\n while (++i < len) {\n key = _getPathKey(target, parts[i], walkNonEnumerables);\n\n if (isUndefined(key)) {\n break;\n }\n\n target = target[key];\n }\n\n return i === len ? {isValid: true, target: target} : {isValid: false, target: void 0};\n }\n\n /**\n * Helper to retrieve the correct key while evaluating a path.\n * @private\n * @param {Object} target\n * @param {String} key\n * @param {Boolean} includeNonEnumerables\n * @returns {String|Number|Undefined}\n */\n function _getPathKey (target, key, includeNonEnumerables) {\n if (includeNonEnumerables && key in Object(target) || _isEnumerable(target, key)) {\n return key;\n }\n\n var keyAsNumber = Number(key);\n\n if (keyAsNumber < 0) {\n return _getNaturalIndex(target, keyAsNumber);\n } else if (Array.isArray(target) && keyAsNumber < target.length) {\n return keyAsNumber;\n }\n\n return void 0;\n }\n\n /**\n * Builds a \"grouping function\" for an array-like object.\n * @private\n * @param {Function} makeValue\n * @returns {Function}\n */\n function _groupWith (makeValue) {\n return function (arrayLike, iteratee, iterateeContext) {\n if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n var result = {};\n var len = arrayLike.length;\n\n for (var i = 0, element, key; i < len; i++) {\n element = arrayLike[i];\n key = iteratee(element, i, arrayLike);\n result[key] = makeValue(result[key], element);\n }\n\n return result;\n };\n }\n\n /**\n * Makes an object immutable by recursively calling Object.freeze\n * on its members.\n * @private\n * @param {Object} obj\n * @param {Array} seen\n * @returns {Object} The obj parameter itself, not a copy.\n */\n function _immutable (obj, seen) {\n if (seen.indexOf(obj) === -1) {\n seen.push(Object.freeze(obj));\n\n forEach(Object.getOwnPropertyNames(obj), function (key) {\n var value = obj[key];\n\n if (typeof value === \"object\" && !isNull(value)) {\n _immutable(value, seen);\n }\n });\n }\n\n return obj;\n }\n\n /**\n * If a method with the given name exists on the target, applies it with the provided\n * arguments and returns the result. Returns undefined otherwise.
\n * The arguments for the method are built by concatenating the array of bound arguments,\n * optionally received by {@link module:lamb.invoker|invoker}, with the final set of, also\n * optional, args.\n * @private\n * @param {Array} boundArgs\n * @param {String} methodName\n * @param {Object} target\n * @param {...*} [args]\n * @returns {*}\n */\n function _invoker (boundArgs, methodName, target) {\n var method = target[methodName];\n\n if (typeof method !== \"function\") {\n return void 0;\n }\n\n var boundArgsLen = boundArgs.length;\n var ofs = 3 - boundArgsLen;\n var len = arguments.length - ofs;\n var args = Array(len);\n\n for (var i = 0; i < boundArgsLen; i++) {\n args[i] = boundArgs[i];\n }\n\n for (; i < len; i++) {\n args[i] = arguments[i + ofs];\n }\n\n return method.apply(target, args);\n }\n\n /**\n * Accepts a target object and a key name and verifies that the target is an array and that\n * the key is an existing index.\n * @private\n * @param {Object} target\n * @param {String|Number} key\n * @returns {Boolean}\n */\n function _isArrayIndex (target, key) {\n var n = Number(key);\n\n return Array.isArray(target) && _isInteger(n) && !(n < 0 && _isEnumerable(target, key));\n }\n\n /**\n * Checks whether the specified key is an enumerable property of the given object or not.\n * @private\n * @param {Object} obj\n * @param {String} key\n * @returns {Boolean}\n */\n function _isEnumerable (obj, key) {\n return key in Object(obj) && (_isOwnEnumerable(obj, key) || ~_safeEnumerables(obj).indexOf(key));\n }\n\n /**\n * Checks if the given value is an integer.\n * @private\n * @param {*} n\n * @returns {Boolean}\n */\n function _isInteger (n) {\n return Math.floor(n) === n;\n }\n\n /**\n * Checks whether the specified key is a own enumerable property of the given object or not.\n * @private\n * @function\n * @param {Object} obj\n * @param {String} key\n * @returns {Boolean}\n */\n var _isOwnEnumerable = generic(_objectProto.propertyIsEnumerable);\n\n /**\n * Accepts an object and build a function expecting a key to create a \"pair\" with the key\n * and its value.\n * @private\n * @param {Object} obj\n * @returns {Function}\n */\n function _keyToPairIn (obj) {\n return function (key) {\n return [key, obj[key]];\n };\n }\n\n /**\n * Helper to build the {@link module:lamb.everyIn|everyIn} or the\n * {@link module:lamb.someIn|someIn} function.\n * @private\n * @param {Boolean} defaultResult\n * @returns {Function}\n */\n function _makeArrayChecker (defaultResult) {\n return function (arrayLike, predicate, predicateContext) {\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n for (var i = 0, len = arrayLike.length; i < len; i++) {\n if (defaultResult ^ !!predicate(arrayLike[i], i, arrayLike)) {\n return !defaultResult;\n }\n }\n\n return defaultResult;\n };\n }\n\n /**\n * Builds a list of sorting criteria from a list of sorter functions. Returns a list containing\n * a single default sorting criterion if the sorter list is empty.\n * @private\n * @param {Function[]} sorters\n * @returns {Sorter[]}\n */\n function _makeCriteria (sorters) {\n return sorters.length ? map(sorters, _makeCriterion) : [_sorter()];\n }\n\n /**\n * Converts a sorting function to a sorting criterion if necessary.\n * @private\n * @param {Function} criterion\n * @returns {Sorter}\n */\n function _makeCriterion (criterion) {\n return typeof Object(criterion).compare === \"function\" ? criterion : _sorter(criterion);\n }\n\n /**\n * Builds a reduce function. The step parameter must be 1\n * to build {@link module:lamb.reduce|reduce} and -1 to build\n * {@link module:lamb.reduceRight|reduceRight}.\n * @private\n * @param {Number} step\n * @returns {Function}\n */\n function _makeReducer (step) {\n return function (arrayLike, accumulator, initialValue) {\n var len = arrayLike.length >>> 0;\n var idx = step === 1 ? 0 : len - 1;\n var nCalls;\n var result;\n\n if (arguments.length === 3) {\n nCalls = len;\n result = initialValue;\n } else {\n if (len === 0) {\n throw new TypeError(\"Reduce of empty array-like with no initial value\");\n }\n\n result = arrayLike[idx];\n idx += step;\n nCalls = len - 1;\n }\n\n for (; nCalls--; idx += step) {\n result = accumulator(result, arrayLike[idx], idx, arrayLike);\n }\n\n return result;\n };\n }\n\n /**\n * Builds a TypeError stating that it's not possible to convert the given value to the\n * desired type.\n * @private\n * @param {*} value\n * @param {String} desiredType\n * @returns {TypeError}\n */\n function _makeTypeErrorFor (value, desiredType) {\n return new TypeError(\"Cannot convert \" + type(value).toLowerCase() + \" to \" + desiredType);\n }\n\n /**\n * Merges the received objects using the provided functions to retrieve their keys.\n * @private\n * @param {Function} getKeys\n * @param {...Object} source\n * @returns {Object}\n */\n function _merge (getKeys) {\n return reduce(_argsTail.apply(null, arguments), function (result, source) {\n forEach(getKeys(source), function (key) {\n result[key] = source[key];\n });\n\n return result;\n }, {});\n }\n\n /**\n * Using the provided function to retrieve the keys of an object, builds\n * a function expecting an object to create a list of key / value pairs.\n * @private\n * @function\n * @param {Function} getKeys\n * @returns {Function}\n */\n var _pairsFrom = _curry(function (getKeys, obj) {\n return map(getKeys(obj), _keyToPairIn(obj));\n });\n\n /**\n * Builds a partial application of a function expecting an iteratee and an\n * optional argument other than its main data parameter.
\n * The optional argument is passed to the function only when is explicitly given\n * a value.
\n * The optional argument is usually the iteratee context, but reduce functions\n * pass their initial value instead.\n * @private\n * @param {Function} fn\n * @returns {Function}\n */\n function _partialWithIteratee (fn) {\n return function (iteratee, optionalArgument) {\n var f = arguments.length === 2 ? fn : binary(fn);\n\n return partial(f, _, iteratee, optionalArgument);\n };\n }\n\n /**\n * Builds a list of the enumerable properties of an object.\n * The function is null-safe, unlike the public one.\n * @private\n * @param {Object} obj\n * @returns {String[]}\n */\n function _safeEnumerables (obj) {\n var result = [];\n\n for (var key in obj) {\n result.push(key);\n }\n\n return result;\n }\n\n /**\n * A null-safe version of Object.keys.\n * @private\n * @param {Object} obj\n * @returns {String[]}\n */\n var _safeKeys = compose(Object.keys, Object);\n\n /**\n * Sets, or creates, a property in a copy of the provided object to the desired value.\n * @param {Object} source\n * @param {String} key\n * @param {*} value\n * @returns {Object}\n */\n function _setIn (source, key, value) {\n var result = {};\n\n for (var prop in source) {\n result[prop] = source[prop];\n }\n\n result[key] = value;\n\n return result;\n }\n\n /**\n * Sets an index in an array-like object.
\n * If provided with an updater function it will use it to update the current value,\n * otherwise sets the index to the specified value.\n * @private\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @param {*} [value]\n * @param {Function} [updater]\n * @returns {Array}\n */\n function _setIndex (arrayLike, index, value, updater) {\n var result = slice(arrayLike);\n var idx = _getNaturalIndex(result, index);\n\n if (!isUndefined(idx)) {\n result[idx] = arguments.length === 4 ? updater(arrayLike[idx]) : value;\n }\n\n return result;\n }\n\n /**\n * Sets the object's property targeted by the given path to the desired value.
\n * Works with arrays and is able to set their indexes, even negative ones.\n * @private\n * @param {Object|Array} obj\n * @param {String[]} parts\n * @param {*} value\n * @returns {Object|Array}\n */\n function _setPathIn (obj, parts, value) {\n var key = parts[0];\n var v;\n\n if (parts.length === 1) {\n v = value;\n } else {\n var targetKey = _getPathKey(obj, key, false);\n\n v = _setPathIn(\n isUndefined(targetKey) ? targetKey : obj[targetKey],\n slice(parts, 1),\n value\n );\n }\n\n return _isArrayIndex(obj, key) ? _setIndex(obj, +key, v) : _setIn(obj, key, v);\n }\n\n /**\n * Builds a sorting criterion. If the comparer function is missing, the default\n * comparer will be used instead.\n * @private\n * @param {Function} reader\n * @param {Boolean} isDescending\n * @param {Function} [comparer]\n * @returns {Sorter}\n */\n function _sorter (reader, isDescending, comparer) {\n return {\n isDescending: isDescending === true,\n compare: function (a, b) {\n if (typeof reader === \"function\" && reader !== identity) {\n a = reader(a);\n b = reader(b);\n }\n\n return (typeof comparer === \"function\" ? comparer : _comparer)(a, b);\n }\n };\n }\n\n /**\n * Using the provided function to retrieve the keys of an object, builds\n * a function expecting an object to create an array containing a list\n * of the keys in its first index and the corresponding list of values\n * in the second one.\n * @private\n * @function\n * @param {Function} getKeys\n * @returns {Function}\n */\n var _tearFrom = _curry(function (getKeys, obj) {\n return reduce(getKeys(obj), function (result, key) {\n result[0].push(key);\n result[1].push(obj[key]);\n\n return result;\n }, [[], []]);\n });\n\n /**\n * Splits a sting path using the provided separator and returns an array\n * of path parts.\n * @private\n * @param {String} path\n * @param {String} separator\n * @returns {String[]}\n */\n function _toPathParts (path, separator) {\n return String(path).split(separator || \".\");\n }\n\n /**\n * Creates a non-null-safe version of the provided \"getKeys\" function.\n * @private\n * @function\n * @param {Function} getKeys\n * @returns {Function}\n */\n var _unsafeKeyListFrom = _curry(function (getKeys, obj) {\n if (isNil(obj)) {\n throw _makeTypeErrorFor(obj, \"object\");\n }\n\n return getKeys(obj);\n });\n\n /**\n * Using the provided function to retrieve the keys of an object, builds\n * a function expecting an object to create the list of values for such keys.\n * @private\n * @function\n * @param {Function} getKeys\n * @returns {Function}\n */\n var _valuesFrom = _curry(function (getKeys, obj) {\n return map(getKeys(obj), partial(getIn, obj));\n });\n\n /**\n * Builds a predicate to check if an array-like object contains the given value.
\n * Please note that the equality test is made with {@link module:lamb.isSVZ|isSVZ}; so you can\n * check for NaN, but 0 and -0 are the same value.
\n * See also {@link module:lamb.isIn|isIn} for an uncurried version.\n * @example\n * var containsNaN = _.contains(NaN, 0);\n *\n * containsNaN([0, 1, 2, 3, NaN]) // => true\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.isIn|isIn}\n * @param {*} value\n * @param {Number} [fromIndex=0] The position at which to begin searching for the given value.\n * @returns {Function}\n */\n function contains (value, fromIndex) {\n return function (arrayLike) {\n return isIn(arrayLike, value, fromIndex);\n };\n }\n\n /**\n * Checks if all the elements in an array-like object satisfy the given predicate.
\n * The function will stop calling the predicate as soon as it returns a falsy value.
\n * Note that an empty array-like will always produce a true result regardless of the\n * predicate because of [vacuous truth]{@link https://en.wikipedia.org/wiki/Vacuous_truth}.
\n * Also note that unlike the native\n * [Array.prototype.every]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every},\n * this function won't skip deleted or unassigned indexes.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"age\": 12, active: true},\n * {\"name\": \"John\", \"age\": 40, active: true},\n * {\"name\": \"Mario\", \"age\": 17, active: true},\n * {\"name\": \"Paolo\", \"age\": 15, active: true}\n * ];\n * var isAdult = function (user) { return user.age >= 18; };\n * var isActive = _.hasKeyValue(\"active\", true);\n *\n * _.everyIn(persons, isAdult) // => false\n * _.everyIn(persons, isActive) // => true\n *\n * @example Showing the difference with Array.prototype.every:\n * var isDefined = _.not(_.isUndefined);\n * var arr = new Array(5);\n * arr[3] = 99;\n *\n * arr.every(isDefined) // => true\n * _.everyIn(arr, isDefined) // => false\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.every|every}\n * @see {@link module:lamb.some|some}, {@link module:lamb.someIn|someIn}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Boolean}\n */\n var everyIn = _makeArrayChecker(true);\n\n /**\n * A curried version of {@link module:lamb.everyIn|everyIn} expecting a predicate and its optional\n * context to build a function waiting for the array-like to act upon.\n * @example\n * var data = [2, 3, 5, 6, 8];\n * var isEven = function (n) { return n % 2 === 0; };\n * var isInteger = function (n) { return Math.floor(n) === n; };\n * var allEvens = _.every(isEven);\n * var allIntegers = _.every(isInteger);\n *\n * allEvens(data) // => false\n * allIntegers(data) // => true\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.everyIn|everyIn}\n * @see {@link module:lamb.some|some}, {@link module:lamb.someIn|someIn}\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Function}\n */\n var every = _partialWithIteratee(everyIn);\n\n /**\n * Builds an array comprised of all values of the array-like object passing the predicate\n * test.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.filter]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @example\n * var isLowerCase = function (s) { return s.toLowerCase() === s; };\n *\n * _.filter([\"Foo\", \"bar\", \"baZ\"], isLowerCase) // => [\"bar\"]\n *\n * // the function will work with any array-like object\n * _.filter(\"fooBAR\", isLowerCase) // => [\"f\", \"o\", \"o\"]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.filterWith|filterWith}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Array}\n */\n function filter (arrayLike, predicate, predicateContext) {\n var len = arrayLike.length;\n var result = [];\n\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n for (var i = 0; i < len; i++) {\n predicate(arrayLike[i], i, arrayLike) && result.push(arrayLike[i]);\n }\n\n return result;\n }\n\n /**\n * Returns a partial application of {@link module:lamb.filter|filter} that uses the given predicate and\n * the optional context to build a function expecting the array-like object to act upon.\n * @example\n * var isLowerCase = function (s) { return s.toLowerCase() === s; };\n * var getLowerCaseEntries = _.filterWith(isLowerCase);\n *\n * getLowerCaseEntries([\"Foo\", \"bar\", \"baZ\"]) // => [\"bar\"]\n *\n * // array-like objects can be used as well\n * getLowerCaseEntries(\"fooBAR\") // => [\"f\", \"o\", \"o\"]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.filter|filter}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var filterWith = _partialWithIteratee(filter);\n\n /**\n * Searches for an element satisfying the predicate in the given array-like object and returns it if\n * the search is successful. Returns undefined otherwise.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"age\": 12},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"age\": 18},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"age\": 40}\n * ];\n *\n * _.find(persons, _.hasKeyValue(\"age\", 40)) // => {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40}\n * _.find(persons, _.hasKeyValue(\"age\", 41)) // => undefined\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.findWhere|findWhere}\n * @see {@link module:lamb.findIndex|findIndex}, {@link module:lamb.findIndexWhere|findIndexWhere}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {*}\n */\n function find (arrayLike, predicate, predicateContext) {\n var idx = arguments.length === 3 ?\n findIndex(arrayLike, predicate, predicateContext) :\n findIndex(arrayLike, predicate);\n\n return idx === -1 ? void 0 : arrayLike[idx];\n }\n\n /**\n * Searches for an element satisfying the predicate in the given array-like object and returns its\n * index if the search is successful. Returns -1 otherwise.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"age\": 12},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"age\": 18},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"age\": 40}\n * ];\n *\n * _.findIndex(persons, _.hasKeyValue(\"age\", 40)) // => 1\n * _.findIndex(persons, _.hasKeyValue(\"age\", 41)) // => -1\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.findIndexWhere|findIndexWhere}\n * @see {@link module:lamb.find|find}, {@link module:lamb.findWhere|findWhere}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Number}\n */\n function findIndex (arrayLike, predicate, predicateContext) {\n var result = -1;\n\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n for (var i = 0, len = arrayLike.length; i < len; i++) {\n if (predicate(arrayLike[i], i, arrayLike)) {\n result = i;\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Builds a partial application of {@link module:lamb.findIndex|findIndex} expecting the array-like\n * object to search.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var findEvenIdx = _.findIndexWhere(isEven);\n *\n * findEvenIdx([1, 3, 4, 5, 7]) // => 2\n * findEvenIdx([1, 3, 5, 7]) // => -1\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.findIndex|findIndex}\n * @see {@link module:lamb.find|find}, {@link module:lamb.findWhere|findWhere}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var findIndexWhere = _partialWithIteratee(findIndex);\n\n /**\n * Builds a partial application of {@link module:lamb.find|find} expecting the array-like object\n * to search.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var findEven = _.findWhere(isEven);\n *\n * findEven([1, 3, 4, 5, 7]) // => 4\n * findEven([1, 3, 5, 7]) // => undefined\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.find|find}\n * @see {@link module:lamb.findIndex|findIndex}, {@link module:lamb.findIndexWhere|findIndexWhere}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var findWhere = _partialWithIteratee(find);\n\n /**\n * Executes the provided iteratee for each element of the given array-like object.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.forEach]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @example Adding a CSS class to all elements of a NodeList in a browser environment\n * var addClass = _.curry(function (className, element) {\n * element.classList.add(className);\n * });\n * var paragraphs = document.querySelectorAll(\"#some-container p\");\n *\n * _.forEach(paragraphs, addClass(\"main\"));\n * // each \"p\" element in the container will have the \"main\" class now\n *\n * @memberof module:lamb\n * @category Array\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Undefined}\n */\n function forEach (arrayLike, iteratee, iterateeContext) {\n if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n for (var i = 0, len = arrayLike.length >>> 0; i < len; i++) {\n iteratee(arrayLike[i], i, arrayLike);\n }\n }\n\n /**\n * Checks if an array-like object contains the given value.
\n * Please note that the equality test is made with {@link module:lamb.isSVZ|isSVZ}; so you can\n * check for NaN, but 0 and -0 are the same value.
\n * See also {@link module:lamb.contains|contains} for a curried version building a predicate.\n * @example\n * var numbers = [0, 1, 2, 3, NaN];\n *\n * _.isIn(numbers, 1) // => true\n * _.isIn(numbers, 0) // => true\n * _.isIn(numbers, -0) // => true\n * _.isIn(numbers, NaN) // => true\n * _.isIn(numbers, 2, 3) // => false\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.contains|contains}\n * @param {ArrayLike} arrayLike\n * @param {*} value\n * @param {Number} [fromIndex=0] The position at which to begin searching for the given value.\n * @returns {Boolean}\n */\n function isIn (arrayLike, value, fromIndex) {\n var result = false;\n\n for (var i = fromIndex >>> 0, len = arrayLike.length; i < len; i++) {\n if (isSVZ(value, arrayLike[i])) {\n result = true;\n break;\n }\n }\n\n return result;\n }\n\n /**\n * Builds a new array by applying the iteratee function to each element of the\n * received array-like object.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.map]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @example\n * _.map([\"Joe\", \"Mario\", \"Jane\"], _.invoker(\"toUpperCase\")) // => [\"JOE\", \"MARIO\", \"JANE\"]\n *\n * _.map([4, 9, 16], Math.sqrt); // => [2, 3, 4]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.mapWith|mapWith}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Array}\n */\n function map (arrayLike, iteratee, iterateeContext) {\n var len = arrayLike.length >>> 0;\n var result = Array(len);\n\n if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n for (var i = 0; i < len; i++) {\n result[i] = iteratee(arrayLike[i], i, arrayLike);\n }\n\n return result;\n }\n\n /**\n * Builds a partial application of {@link module:lamb.map|map} using the given iteratee and the\n * optional context. The resulting function expects the array-like object to act upon.\n * @example\n * var square = function (n) { return n * n; };\n * var getSquares = _.mapWith(square);\n *\n * getSquares([1, 2, 3, 4, 5]) // => [1, 4, 9, 16, 25]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.map|map}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {function}\n */\n var mapWith = _partialWithIteratee(map);\n\n /**\n * Reduces (or folds) the values of an array-like object, starting from the first, to a new\n * value using the provided accumulator function.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.reduce]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @example\n * _.reduce([1, 2, 3, 4], _.add) // => 10\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.reduceRight|reduceRight}\n * @see {@link module:lamb.reduceWith|reduceWith}, {@link module:lamb.reduceRightWith|reduceRightWith}\n * @param {ArrayLike} arrayLike\n * @param {AccumulatorCallback} accumulator\n * @param {*} [initialValue]\n * @returns {*}\n */\n var reduce = _makeReducer(1);\n\n /**\n * Same as {@link module:lamb.reduce|reduce}, but starts the fold operation from the last\n * element instead.
\n * Since version 0.34.0 this function is no longer a generic version of\n * [Array.prototype.reduceRight]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight}\n * for performance reasons.
\n * Note that unlike the native array method this function doesn't skip unassigned or deleted indexes.\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.reduce|reduce}\n * @see {@link module:lamb.reduceWith|reduceWith}, {@link module:lamb.reduceRightWith|reduceRightWith}\n * @param {ArrayLike} arrayLike\n * @param {AccumulatorCallback} accumulator\n * @param {*} [initialValue]\n * @returns {*}\n */\n var reduceRight = _makeReducer(-1);\n\n /**\n * A partial application of {@link module:lamb.reduce|reduceRight} that uses the\n * provided accumulator and the optional initialValue to\n * build a function expecting the array-like object to act upon.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.reduceRightWith(_.add)(arr) // => 15\n * _.reduceRightWith(_.subtract)(arr) // => -5\n * _.reduceRightWith(_.subtract, 0)(arr) // => -15\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.reduceWith|reduceWith}\n * @see {@link module:lamb.reduce|reduce}, {@link module:lamb.reduce|reduceRight}\n * @param {AccumulatorCallback} accumulator\n * @param {*} [initialValue]\n * @returns {Function}\n */\n var reduceRightWith = _partialWithIteratee(reduceRight);\n\n /**\n * A partial application of {@link module:lamb.reduce|reduce} that uses the\n * provided accumulator and the optional initialValue to\n * build a function expecting the array-like object to act upon.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.reduceWith(_.add)(arr) // => 15\n * _.reduceWith(_.subtract)(arr) // => -13\n * _.reduceWith(_.subtract, 0)(arr) // => -15\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.reduceRightWith|reduceRightWith}\n * @see {@link module:lamb.reduce|reduce}, {@link module:lamb.reduce|reduceRight}\n * @param {AccumulatorCallback} accumulator\n * @param {*} [initialValue]\n * @returns {Function}\n */\n var reduceWith = _partialWithIteratee(reduce);\n\n /**\n * Builds an array by extracting a portion of an array-like object.
\n * It's a generic version of [Array.prototype.slice]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice}.\n * @example\n * _.slice([\"foo\", \"bar\", \"baz\"], 0, 2) // => [\"foo\", \"bar\"]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {ArrayLike} arrayLike - Any array like object.\n * @param {Number} [start=0] - Zero-based index at which to begin extraction.\n * @param {Number} [end=arrayLike.length] - Zero-based index at which to end extraction.\n * Extracts up to but not including end.\n * @returns {Array}\n */\n var slice = generic(_arrayProto.slice);\n\n /**\n * Checks if at least one element in an array-like object satisfies the given predicate.
\n * The function will stop calling the predicate as soon as it returns a truthy value.
\n * Note that unlike the native\n * [Array.prototype.some]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some},\n * this function won't skip deleted or unassigned indexes.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"age\": 12, active: false},\n * {\"name\": \"John\", \"age\": 40, active: false},\n * {\"name\": \"Mario\", \"age\": 17, active: false},\n * {\"name\": \"Paolo\", \"age\": 15, active: false}\n * ];\n * var isAdult = function (user) { return user.age >= 18; };\n * var isActive = _.hasKeyValue(\"active\", true);\n *\n * _.someIn(persons, isAdult) // => true\n * _.someIn(persons, isActive) // => false\n *\n * @example Showing the difference with Array.prototype.some:\n * var arr = new Array(5);\n * arr[3] = 99;\n *\n * arr.some(_.isUndefined) // => false\n * _.someIn(arr, _.isUndefined) // => true\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.some|some}\n * @see {@link module:lamb.every|every}, {@link module:lamb.everyIn|everyIn}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Boolean}\n */\n var someIn = _makeArrayChecker(false);\n\n /**\n * A curried version of {@link module:lamb.someIn|someIn} expecting a predicate and its optional\n * context to build a function waiting for the array-like to act upon.\n * @example\n * var data = [1, 3, 5, 6, 7, 8];\n * var isEven = function (n) { return n % 2 === 0; };\n * var isInteger = function (n) { return Math.floor(n) === n; };\n * var containsEvens = _.some(isEven);\n * var containsStrings = _.some(_.isType(\"String\"));\n *\n * containsEvens(data) // => true\n * containsStrings(data) // => false\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.someIn|someIn}\n * @see {@link module:lamb.every|every}, {@link module:lamb.everyIn|everyIn}\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Function}\n */\n var some = _partialWithIteratee(someIn);\n\n lamb.contains = contains;\n lamb.every = every;\n lamb.everyIn = everyIn;\n lamb.filter = filter;\n lamb.filterWith = filterWith;\n lamb.find = find;\n lamb.findIndex = findIndex;\n lamb.findIndexWhere = findIndexWhere;\n lamb.findWhere = findWhere;\n lamb.forEach = forEach;\n lamb.isIn = isIn;\n lamb.map = map;\n lamb.mapWith = mapWith;\n lamb.reduce = reduce;\n lamb.reduceRight = reduceRight;\n lamb.reduceRightWith = reduceRightWith;\n lamb.reduceWith = reduceWith;\n lamb.slice = slice;\n lamb.some = some;\n lamb.someIn = someIn;\n\n /**\n * Accepts a series of functions and builds a function that applies the received\n * arguments to each one and returns the first non-undefined value.
\n * Meant to work in sinergy with {@link module:lamb.condition|condition} and\n * {@link module:lamb.invoker|invoker}, can be useful as a strategy pattern for functions,\n * to mimic conditional logic and also to build polymorphic functions.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var filterString = _.compose(_.invoker(\"join\", \"\"), _.filter);\n * var filterAdapter = _.adapter(\n * _.invoker(\"filter\"),\n * _.condition(_.isType(\"String\"), filterString)\n * );\n *\n * filterAdapter([1, 2, 3, 4, 5, 6], isEven) // => [2, 4, 6]\n * filterAdapter(\"123456\", isEven) // => \"246\"\n * filterAdapter({}, isEven) // => undefined\n *\n * // obviously it's composable\n * var filterWithDefault = _.adapter(filterAdapter, _.always(\"Not implemented\"));\n *\n * filterWithDefault([1, 2, 3, 4, 5, 6], isEven) // => [2, 4, 6]\n * filterWithDefault(\"123456\", isEven) // => \"246\"\n * filterWithDefault({}, isEven) // => \"Not implemented\"\n *\n * @memberof module:lamb\n * @category Logic\n * @param {...Function} fn\n * @returns {Function}\n */\n function adapter () {\n var functions = list.apply(null, arguments);\n\n return function () {\n var len = functions.length;\n var result;\n\n for (var i = 0; i < len; i++) {\n result = functions[i].apply(this, arguments);\n\n if (!isUndefined(result)) {\n break;\n }\n }\n\n return result;\n };\n }\n\n /**\n * Accepts a series of predicates and builds a new one that returns true if they are all satisfied\n * by the same arguments. The functions in the series will be applied one at a time until a\n * false value is produced, which is returned immediately.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var isPositive = function (n) { return n > 0; };\n * var isPositiveEven = _.allOf(isEven, isPositive);\n *\n * isPositiveEven(-2) // => false\n * isPositiveEven(11) // => false\n * isPositiveEven(6) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.anyOf|anyOf}\n * @param {...Function} predicate\n * @returns {Function}\n */\n function allOf () {\n var predicates = list.apply(null, arguments);\n\n return function () {\n for (var i = 0, len = predicates.length; i < len; i++) {\n if (!predicates[i].apply(this, arguments)) {\n return false;\n }\n }\n\n return true;\n };\n }\n\n /**\n * Accepts a series of predicates and builds a new one that returns true if at least one of them is\n * satisfied by the received arguments. The functions in the series will be applied one at a time\n * until a true value is produced, which is returned immediately.\n * @example\n * var users = [\n * {id: 1, name: \"John\", group: \"guest\"},\n * {id: 2, name: \"Jane\", group: \"root\"},\n * {id: 3, name: \"Mario\", group: \"admin\"}\n * ];\n * var isInGroup = _.partial(_.hasKeyValue, \"group\");\n * var isSuperUser = _.anyOf(isInGroup(\"admin\"), isInGroup(\"root\"));\n *\n * isSuperUser(users[0]) // => false\n * isSuperUser(users[1]) // => true\n * isSuperUser(users[2]) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.allOf|allOf}\n * @param {...Function} predicate\n * @returns {Function}\n */\n function anyOf () {\n var predicates = list.apply(null, arguments);\n\n return function () {\n for (var i = 0, len = predicates.length; i < len; i++) {\n if (predicates[i].apply(this, arguments)) {\n return true;\n }\n }\n\n return false;\n };\n }\n\n /**\n * Builds a function that will apply the received arguments to trueFn,\n * if the predicate is satisfied with the same arguments, or to falseFn otherwise.
\n * If falseFn isn't provided and the predicate isn't satisfied the function\n * will return undefined.
\n * Although you can use other conditions as trueFn or falseFn,\n * it's probably better to use {@link module:lamb.adapter|adapter} to build more complex behaviours.
\n * See also {@link module:lamb.unless|unless} and {@link module:lamb.when|when} as they are\n * shortcuts to common use cases.\n * @example\n * var isEven = function (n) { return n % 2 === 0};\n * var halve = function (n) { return n / 2; };\n * var double = function (n) { return n * 2; };\n * var halveEvenAndDoubleOdd = _.condition(isEven, halve, double);\n *\n * halveEvenAndDoubleOdd(5) // => 10\n * halveEvenAndDoubleOdd(6) // => 3\n *\n * var halveIfNumber = _.condition(_.isType(\"Number\"), halve);\n *\n * halveIfNumber(2) // => 1\n * halveIfNumber(\"2\") // => undefined\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.unless|unless}\n * @see {@link module:lamb.when|when}\n * @param {Function} predicate\n * @param {Function} trueFn\n * @param {Function} [falseFn]\n * @returns {Function}\n */\n function condition (predicate, trueFn, falseFn) {\n return function () {\n if (predicate.apply(this, arguments)) {\n return trueFn.apply(this, arguments);\n } else if (falseFn) {\n return falseFn.apply(this, arguments);\n } else {\n return void 0;\n }\n };\n }\n\n /**\n * Verifies that the two supplied values are the same value using the \"SameValue\" comparison.
\n * Note that this doesn't behave as the strict equality operator, but rather as a shim of ES6's\n * [Object.is]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is}.\n * Differences are that 0 and -0 aren't the same value and, finally,\n * NaN is equal to itself.
\n * See also {@link module:lamb.isSVZ|isSVZ} which performs the check using the \"SameValueZero\" comparison.\n * @example\n * var testObject = {};\n *\n * _.is({}, testObject) // => false\n * _.is(testObject, testObject) // => true\n * _.is(\"foo\", \"foo\") // => true\n * _.is(0, -0) // => false\n * _.is(0 / 0, NaN) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @see [SameValue comparison]{@link http://www.ecma-international.org/ecma-262/6.0/#sec-samevalue}\n * @see [SameValueZero comparison]{@link http://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero}\n * @param {*} a\n * @param {*} b\n * @returns {Boolean}\n */\n function is (a, b) {\n return a === 0 && b === 0 ? 1 / a === 1 / b : isSVZ(a, b);\n }\n\n /**\n * Verifies that the first given value is greater than the second.\n * @example\n * var pastDate = new Date(2010, 2, 12);\n * var today = new Date();\n *\n * _.isGT(today, pastDate) // => true\n * _.isGT(pastDate, today) // => false\n * _.isGT(3, 4) // => false\n * _.isGT(3, 3) // => false\n * _.isGT(3, 2) // => true\n * _.isGT(0, -0) // => false\n * _.isGT(-0, 0) // => false\n * _.isGT(\"a\", \"A\") // => true\n * _.isGT(\"b\", \"a\") // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Number|String|Date|Boolean} a\n * @param {Number|String|Date|Boolean} b\n * @returns {Boolean}\n */\n function isGT (a, b) {\n return a > b;\n }\n\n /**\n * Verifies that the first given value is greater than or equal to the second.\n * Regarding equality, beware that this is simply a wrapper for the native operator,\n * so -0 === 0.\n * @example\n * _.isGTE(3, 4) // => false\n * _.isGTE(3, 3) // => true\n * _.isGTE(3, 2) // => true\n * _.isGTE(0, -0) // => true\n * _.isGTE(-0, 0) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Number|String|Date|Boolean} a\n * @param {Number|String|Date|Boolean} b\n * @returns {Boolean}\n */\n function isGTE (a, b) {\n return a >= b;\n }\n\n /**\n * Verifies that the first given value is less than the second.\n * @example\n * var pastDate = new Date(2010, 2, 12);\n * var today = new Date();\n *\n * _.isLT(today, pastDate) // => false\n * _.isLT(pastDate, today) // => true\n * _.isLT(3, 4) // => true\n * _.isLT(3, 3) // => false\n * _.isLT(3, 2) // => false\n * _.isLT(0, -0) // => false\n * _.isLT(-0, 0) // => false\n * _.isLT(\"a\", \"A\") // => false\n * _.isLT(\"a\", \"b\") // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Number|String|Date|Boolean} a\n * @param {Number|String|Date|Boolean} b\n * @returns {Boolean}\n */\n function isLT (a, b) {\n return a < b;\n }\n\n /**\n * Verifies that the first given value is less than or equal to the second.\n * Regarding equality, beware that this is simply a wrapper for the native operator,\n * so -0 === 0.\n * @example\n * _.isLTE(3, 4) // => true\n * _.isLTE(3, 3) // => true\n * _.isLTE(3, 2) // => false\n * _.isLTE(0, -0) // => true\n * _.isLTE(-0, 0) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Number|String|Date|Boolean} a\n * @param {Number|String|Date|Boolean} b\n * @returns {Boolean}\n */\n function isLTE (a, b) {\n return a <= b;\n }\n\n /**\n * A simple negation of {@link module:lamb.is|is}, exposed for convenience.\n * @example\n * _.isNot(\"foo\", \"foo\") // => false\n * _.isNot(0, -0) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @function\n * @param {*} valueA\n * @param {*} valueB\n * @returns {Boolean}\n */\n var isNot = not(is);\n\n /**\n * Verifies that the two supplied values are the same value using the \"SameValueZero\" comparison.
\n * With this comparison NaN is equal to itself, but 0 and -0 are\n * considered the same value.
\n * See also {@link module:lamb.is|is} to perform a \"SameValue\" comparison.\n * @example\n * var testObject = {};\n *\n * _.isSVZ({}, testObject) // => false\n * _.isSVZ(testObject, testObject) // => true\n * _.isSVZ(\"foo\", \"foo\") // => true\n * _.isSVZ(0, -0) // => true\n * _.isSVZ(0 / 0, NaN) // => true\n *\n * @memberof module:lamb\n * @category Logic\n * @see [SameValue comparison]{@link http://www.ecma-international.org/ecma-262/6.0/#sec-samevalue}\n * @see [SameValueZero comparison]{@link http://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero}\n * @param {*} a\n * @param {*} b\n * @returns {Boolean}\n */\n function isSVZ (a, b) {\n // eslint-disable-next-line no-self-compare\n return a !== a ? b !== b : a === b;\n }\n\n /**\n * Returns a predicate that negates the given one.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var isOdd = _.not(isEven);\n *\n * isOdd(5) // => true\n * isOdd(4) // => false\n *\n * @memberof module:lamb\n * @category Logic\n * @param {Function} predicate\n * @returns {Function}\n */\n function not (predicate) {\n return function () {\n return !predicate.apply(this, arguments);\n };\n }\n\n /**\n * Builds a unary function that will check its argument against the given predicate.\n * If the predicate isn't satisfied, the provided fn function will be\n * applied to the same value. The received argument is returned as it is otherwise.
\n * See {@link module:lamb.when|when} for the opposite behaviour.
\n * It's a shortcut for a common use case of {@link module:lamb.condition|condition},\n * where its trueFn parameter is the [identity function]{@link module:lamb.identity}.\n * @example\n * var isEven = function (n) { return n % 2 === 0};\n * var halve = function (n) { return n / 2; };\n * var halveUnlessIsEven = _.unless(isEven, halve);\n *\n * halveUnlessIsEven(5) // => 2.5\n * halveUnlessIsEven(6) // => 6\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.condition|condition}\n * @see {@link module:lamb.when|when}\n * @param {Function} predicate\n * @param {Function} fn\n * @returns {Function}\n */\n function unless (predicate, fn) {\n return function (value) {\n return predicate.call(this, value) ? value : fn.call(this, value);\n };\n }\n\n /**\n * Builds a unary function that will check its argument against the given predicate.\n * If the predicate is satisfied, the provided fn function will be\n * applied to the same value. The received argument is returned as it is otherwise.
\n * See {@link module:lamb.unless|unless} for the opposite behaviour.
\n * It's a shortcut for a common use case of {@link module:lamb.condition|condition},\n * where its falseFn parameter is the [identity function]{@link module:lamb.identity}.\n * @example\n * var isEven = function (n) { return n % 2 === 0};\n * var halve = function (n) { return n / 2; };\n * var halveIfEven = _.when(isEven, halve);\n *\n * halveIfEven(5) // => 5\n * halveIfEven(6) // => 3\n *\n * @memberof module:lamb\n * @category Logic\n * @see {@link module:lamb.condition|condition}\n * @see {@link module:lamb.unless|unless}\n * @param {Function} predicate\n * @param {Function} fn\n * @returns {Function}\n */\n function when (predicate, fn) {\n return function (value) {\n return predicate.call(this, value) ? fn.call(this, value) : value;\n };\n }\n\n lamb.adapter = adapter;\n lamb.allOf = allOf;\n lamb.anyOf = anyOf;\n lamb.condition = condition;\n lamb.is = is;\n lamb.isGT = isGT;\n lamb.isGTE = isGTE;\n lamb.isLT = isLT;\n lamb.isLTE = isLTE;\n lamb.isNot = isNot;\n lamb.isSVZ = isSVZ;\n lamb.not = not;\n lamb.unless = unless;\n lamb.when = when;\n\n /**\n * Adds two numbers.\n * @example\n * _.add(4, 5) // => 9\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function add (a, b) {\n return a + b;\n }\n\n /**\n * \"Clamps\" a number within the given limits.\n * @example\n * _.clamp(-5, 0, 10) // => 0\n * _.clamp(5, 0, 10) // => 5\n * _.clamp(15, 0, 10) // => 10\n * _.clamp(0, 0, 10) // => 0\n * _.clamp(10, 0, 10) // => 10\n * _.is(_.clamp(-0, 0, 10), -0) // => true\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} n\n * @param {Number} min\n * @param {Number} max\n * @returns {Number}\n */\n function clamp (n, min, max) {\n return n < min ? min : n > max ? max : n;\n }\n\n /**\n * Divides two numbers.\n * @example\n * _.divide(5, 2) // => 2.5\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function divide (a, b) {\n return a / b;\n }\n\n /**\n * Generates a sequence of values of the desired length with the provided iteratee.\n * The values being iterated, and received by the iteratee, are the results generated so far.\n * @example\n * var fibonacci = function (n, idx, results) {\n * return n + (results[idx - 1] || 0);\n * };\n *\n * _.generate(1, 10, fibonacci) // => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n *\n * @memberof module:lamb\n * @category Math\n * @param {*} start - The starting value\n * @param {Number} len - The desired length for the sequence\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Array}\n */\n function generate (start, len, iteratee, iterateeContext) {\n var result = [start];\n\n if (arguments.length === 4) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n for (var i = 0, limit = len - 1; i < limit; i++) {\n result.push(iteratee(result[i], i, result));\n }\n\n return result;\n }\n\n /**\n * Performs the modulo operation and should not be confused with the\n * {@link module:lamb.remainder|remainder}.\n * The function performs a floored division to calculate the result and not\n * a truncated one, hence the sign of the dividend is not kept, unlike the\n * {@link module:lamb.remainder|remainder}.\n * @example\n * _.modulo(5, 3) // => 2\n * _.remainder(5, 3) // => 2\n *\n * _.modulo(-5, 3) // => 1\n * _.remainder(-5, 3) // => -2\n *\n * @memberof module:lamb\n * @category Math\n * @see {@link http://en.wikipedia.org/wiki/Modulo_operation}\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function modulo (a, b) {\n return a - (b * Math.floor(a / b));\n }\n\n /**\n * Multiplies two numbers.\n * @example\n * _.multiply(5, 3) // => 15\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function multiply (a, b) {\n return a * b;\n }\n\n /**\n * Generates a random integer between two given integers, both included.\n * Note that no safety measure is taken if the provided arguments aren't integers, so\n * you may end up with unexpected (not really) results.\n * For example randomInt(0.1, 1.2) could be 2.\n * @example\n *\n * _.randomInt(1, 10) // => an integer >=1 && <= 10\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} min\n * @param {Number} max\n * @returns {Number}\n */\n function randomInt (min, max) {\n return Math.floor(Math.random() * (max - min + 1) + min);\n }\n\n /**\n * Generates an arithmetic progression of numbers starting from start up to,\n * but not including, limit, using the given step.\n * @example\n * _.range(2, 10) // => [2, 3, 4, 5, 6, 7, 8, 9]\n * _.range(2, 10, 0) // => [2]\n * _.range(1, -10, -2) // => [1, -1, -3, -5, -7, -9]\n * _.range(1, -10, 2) // => [1]\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} start\n * @param {Number} limit\n * @param {Number} [step=1]\n * @returns {Number[]}\n */\n function range (start, limit, step) {\n if (step === 0 || arguments.length < 2) {\n return [start];\n }\n\n if (!step) {\n step = 1;\n }\n\n var len = Math.max(Math.ceil((limit - start) / step), 0);\n\n return generate(start, len, partial(add, step));\n }\n\n /**\n * Gets the remainder of the division of two numbers.\n * Not to be confused with the {@link module:lamb.modulo|modulo} as the remainder\n * keeps the sign of the dividend and may lead to some unexpected results.\n * @example\n * // example of wrong usage of the remainder\n * // (in this case the modulo operation should be used)\n * var isOdd = function (n) { return _.remainder(n, 2) === 1; };\n * isOdd(-3) // => false as -3 % 2 === -1\n *\n * @memberof module:lamb\n * @category Math\n * @see {@link http://en.wikipedia.org/wiki/Modulo_operation}\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function remainder (a, b) {\n return a % b;\n }\n\n /**\n * Subtracts two numbers.\n * @example\n * _.subtract(5, 3) // => 2\n *\n * @memberof module:lamb\n * @category Math\n * @param {Number} a\n * @param {Number} b\n * @returns {Number}\n */\n function subtract (a, b) {\n return a - b;\n }\n\n lamb.add = add;\n lamb.clamp = clamp;\n lamb.divide = divide;\n lamb.generate = generate;\n lamb.modulo = modulo;\n lamb.multiply = multiply;\n lamb.randomInt = randomInt;\n lamb.range = range;\n lamb.remainder = remainder;\n lamb.subtract = subtract;\n\n /**\n * Verifies if a value is null or undefined.\n * @example\n * _.isNil(NaN) // => false\n * _.isNil({}) // => false\n * _.isNil(null) // => true\n * _.isNil(void 0) // => true\n * _.isNil() // => true\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.isNull|isNull}\n * @see {@link module:lamb.isUndefined|isUndefined}\n * @param {*} value\n * @returns {Boolean}\n */\n function isNil (value) {\n return isNull(value) || isUndefined(value);\n }\n\n /**\n * Verifies if a value is null.\n * @example\n * _.isNull(null) // => true\n * _.isNull(void 0) // => false\n * _.isNull(false) // => false\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.isNil|isNil} if you want to check for undefined too.\n * @param {*} value\n * @returns {Boolean}\n */\n function isNull (value) {\n return value === null;\n }\n\n /**\n * Builds a predicate that expects a value to check against the specified type.\n * @example\n * var isString = _.isType(\"String\");\n *\n * isString(\"Hello\") // => true\n * isString(new String(\"Hi\")) // => true\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.type|type}\n * @param {String} typeName\n * @returns {Function}\n */\n function isType (typeName) {\n return function (value) {\n return type(value) === typeName;\n };\n }\n\n /**\n * Verifies if a value is undefined.\n * @example\n * _.isUndefined(null) // => false\n * _.isUndefined(void 0) // => true\n * _.isUndefined(false) // => false\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.isNil|isNil} if you want to check for null too.\n * @param {*} value\n * @returns {Boolean}\n */\n function isUndefined (value) {\n return value === void 0;\n }\n\n /**\n * Retrieves the \"type tag\" from the given value.\n * @example\n * var x = 5;\n * var y = new Number(5);\n *\n * typeof x // => \"number\"\n * typeof y // => \"object\"\n * _.type(x) // => \"Number\"\n * _.type(y) // => \"Number\"\n *\n * _.type(Object.prototype.toString) // => \"Function\"\n * _.type(/a/) // => \"RegExp\"\n *\n * @memberof module:lamb\n * @category Type\n * @see {@link module:lamb.isType|isType}\n * @param {*} value\n * @returns {String}\n */\n function type (value) {\n return _objectProto.toString.call(value).slice(8, -1);\n }\n\n lamb.isNil = isNil;\n lamb.isNull = isNull;\n lamb.isType = isType;\n lamb.isUndefined = isUndefined;\n lamb.type = type;\n\n /**\n * A curried version of {@link module:lamb.getIndex|getIndex} that uses the provided index\n * to build a function expecting the array-like object holding the element we want to retrieve.\n * @example\n * var getFifthElement = _.getAt(4);\n *\n * getFifthElement([1, 2, 3, 4, 5]) // => 5\n * getFifthElement(\"foo bar\") // => \"b\"\n * getFifthElement([]) // => undefined\n * getFifthElement(\"foo\") // => undefined\n *\n * @example Using negative indexes\n * _.getAt(-2)([1, 2, 3]) // => 2\n * _.getAt(-3)(\"foo\") // => \"f\"\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.getIndex|getIndex}\n * @see {@link module:lamb.head|head} and {@link module:lamb.last|last} for common use cases shortcuts.\n * @param {Number} index\n * @returns {Function}\n */\n function getAt (index) {\n return function (arrayLike) {\n return getIndex(arrayLike, index);\n };\n }\n\n /**\n * Returns the value of the object property with the given key.\n * @example\n * var user = {name: \"John\"};\n *\n * _.getIn(user, \"name\") // => \"John\";\n * _.getIn(user, \"surname\") // => undefined\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.getKey|getKey}\n * @see {@link module:lamb.getPath|getPath}, {@link module:lamb.getPathIn|getPathIn}\n * @param {Object} obj\n * @param {String} key\n * @returns {*}\n */\n function getIn (obj, key) {\n return obj[key];\n }\n\n /**\n * Retrieves the element at the given index in an array-like object.
\n * Like {@link module:lamb.slice|slice} the index can be negative.
\n * If the index isn't supplied, or if its value isn't an integer within the array-like bounds,\n * the function will return undefined.
\n * getIndex will throw an exception when receives null or\n * undefined in place of an array-like object, but returns undefined\n * for any other value.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.getIndex(arr, 1) // => 2\n * _.getIndex(arr, -1) // => 5\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.getAt|getAt}\n * @see {@link module:lamb.head|head} and {@link module:lamb.last|last} for common use cases shortcuts.\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @returns {*}\n */\n function getIndex (arrayLike, index) {\n var idx = _getNaturalIndex(arrayLike, index);\n\n return isUndefined(idx) ? idx : arrayLike[idx];\n }\n\n /**\n * A curried version of {@link module:lamb.getIn|getIn}.
\n * Receives a property name and builds a function expecting the object from which we want to retrieve\n * the property.\n * @example\n * var user1 = {name: \"john\"};\n * var user2 = {name: \"jane\"};\n * var getName = _.getKey(\"name\");\n *\n * getName(user1) // => \"john\"\n * getName(user2) // => \"jane\"\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.getIn|getIn}\n * @see {@link module:lamb.getPath|getPath}, {@link module:lamb.getPathIn|getPathIn}\n * @param {String} key\n * @returns {Function}\n */\n function getKey (key) {\n return function (obj) {\n return getIn(obj, key);\n };\n }\n\n /**\n * Builds a partial application of {@link module:lamb.getPathIn|getPathIn} with the given\n * path and separator, expecting the object to act upon.
\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * login: {\n * \"user.name\": \"jdoe\",\n * password: \"abc123\"\n * }\n * };\n *\n * var getPwd = _.getPath(\"login.password\");\n * var getUsername = _.getPath(\"login/user.name\", \"/\");\n *\n * getPwd(user) // => \"abc123\";\n * getUsername(user) // => \"jdoe\"\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.getPathIn|getPathIn}\n * @see {@link module:lamb.getIn|getIn}, {@link module:lamb.getKey|getKey}\n * @param {String} path\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function getPath (path, separator) {\n return partial(getPathIn, _, path, separator);\n }\n\n /**\n * Gets a nested property value from an object using the given path.
\n * The path is a string with property names separated by dots by default, but\n * it can be customised with the optional third parameter.
\n * You can use integers in the path, even negative ones, to refer to array-like\n * object indexes, but the priority will be given to existing object keys:\n * the last example explains this particular case.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * login: {\n * \"user.name\": \"jdoe\",\n * password: \"abc123\"\n * },\n * scores: [\n * {id: 1, value: 10},\n * {id: 2, value: 20},\n * {id: 3, value: 30}\n * ]\n * };\n *\n * _.getPathIn(user, \"name\") // => \"John\"\n * _.getPathIn(user, \"login.password\") // => \"abc123\";\n * _.getPathIn(user, \"login/user.name\", \"/\") // => \"jdoe\"\n * _.getPathIn(user, \"name.foo\") // => undefined\n * _.getPathIn(user, \"name.foo.bar\") // => undefined\n *\n * @example Accessing array-like objects indexes:\n * _.getPathIn(user, \"login.password.1\") // => \"b\"\n * _.getPathIn(user, \"scores.0\") // => {id: 1, value: 10}\n * _.getPathIn(user, \"scores.-1.value\") // => 30\n *\n * @example Priority will be given to existing object keys over indexes:\n * _.getPathIn(user, \"scores.-1\") // => {id: 3, value: 30}\n *\n * // let's do something funny\n * user.scores[\"-1\"] = \"foo bar\";\n *\n * _.getPathIn(user, \"scores.-1\") // => \"foo bar\";\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.getPath|getPath}\n * @see {@link module:lamb.getIn|getIn}, {@link module:lamb.getKey|getKey}\n * @param {Object|ArrayLike} obj\n * @param {String} path\n * @param {String} [separator=\".\"]\n * @returns {*}\n */\n function getPathIn (obj, path, separator) {\n var pathInfo = _getPathInfo(obj, _toPathParts(path, separator), true);\n\n return pathInfo.target;\n }\n\n /**\n * Retrieves the first element of an array-like object.
\n * Just a common use case of {@link module:lamb.getAt|getAt} exposed for convenience.\n * @example\n * _.head([1, 2, 3]) // => 1\n * _.head(\"hello\") // => \"h\"\n * _.head([]) // => undefined\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.last|last}\n * @see {@link module:lamb.getIndex|getIndex}, {@link module:lamb.getAt|getAt}\n * @param {ArrayLike} arrayLike\n * @returns {*}\n */\n var head = getAt(0);\n\n /**\n * Retrieves the last element of an array-like object.
\n * Just a common use case of {@link module:lamb.getAt|getAt} exposed for convenience.\n * @example\n * _.last([1, 2, 3]) // => 3\n * _.last(\"hello\") // => \"o\"\n * _.last([]) // => undefined\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.head|head}\n * @see {@link module:lamb.getIndex|getIndex}, {@link module:lamb.getAt|getAt}\n * @param {ArrayLike} arrayLike\n * @returns {*}\n */\n var last = getAt(-1);\n\n /**\n * Builds a function that creates a copy of an array-like object with the given\n * index changed to the desired value.
\n * If the index is not an integer or if it's out of bounds, the function\n * will return a copy of the original array.
\n * Negative indexes are allowed.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.setAt(2, 99)(arr) // => [1, 2, 99, 4, 5]\n * arr // => [1, 2, 3, 4, 5]\n *\n * _.setAt(10, 99)(arr) // => [1, 2, 3, 4, 5] (not a reference to `arr`)\n *\n * @example Using negative indexes\n * _.setAt(-1, 99)(arr) // => [1, 2, 3, 4, 99]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.setIndex|setIndex}\n * @param {Number} index\n * @param {*} value\n * @returns {Function}\n */\n function setAt (index, value) {\n return function (arrayLike) {\n return _setIndex(arrayLike, index, value);\n };\n }\n\n /**\n * Sets the specified key to the given value in a copy of the provided object.
\n * All the remaining enumerable keys of the source object will be simply copied in the\n * result object without breaking references.
\n * If the specified key is not part of the source object, it will be added to the\n * result.
\n * The main purpose of the function is to work on simple plain objects used as\n * data structures, such as JSON objects, and makes no effort to play nice with\n * objects created from an OOP perspective (it's not worth it).
\n * For example the prototype of the result will be Object's regardless\n * of the source's one.\n * @example\n * var user = {name: \"John\", surname: \"Doe\", age: 30};\n *\n * _.setIn(user, \"name\", \"Jane\") // => {name: \"Jane\", surname: \"Doe\", age: 30}\n * _.setIn(user, \"gender\", \"male\") // => {name: \"John\", surname: \"Doe\", age: 30, gender: \"male\"}\n *x\n * // `user` still is {name: \"John\", surname: \"Doe\", age: 30}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.setKey|setKey}\n * @see {@link module:lamb.setPath|setPath}, {@link module:lamb.setPathIn|setPathIn}\n * @param {Object} source\n * @param {String} key\n * @param {*} value\n * @returns {Object}\n */\n function setIn (source, key, value) {\n if (isNil(source)) {\n throw _makeTypeErrorFor(source, \"object\");\n }\n\n return _setIn(source, key, value);\n }\n\n /**\n * Creates a copy of an array-like object with the given index changed to\n * the desired value.
\n * If the index is not an integer or if it's out of bounds, the function\n * will return a copy of the original array.
\n * Negative indexes are allowed.\n * @example\n * var arr = [1, 2, 3];\n *\n * _.setIndex(arr, 1, 99) // => [1, 99, 3]\n * _.setIndex(arr, -1, 99) // => [1, 2, 99]\n * _.setIndex(arr, 10, 99) // => [1, 2, 3] (not a reference to `arr`)\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.setAt|setAt}\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @param {*} value\n * @returns {Array}\n */\n var setIndex = aritize(_setIndex, 3);\n\n /**\n * Builds a partial application of {@link module:lamb.setIn|setIn} with the provided\n * key and value.
\n * The resulting function expects the object to act upon.
\n * Please refer to {@link module:lamb.setIn|setIn}'s description for explanations about\n * how the copy of the source object is made.\n * @example\n * var user = {name: \"John\", surname: \"Doe\", age: 30};\n * var setAgeTo40 = _.setKey(\"age\", 40);\n *\n * setAgeTo40(user) // => {name: \"john\", surname: \"doe\", age: 40}\n *\n * // `user` still is {name: \"John\", surname: \"Doe\", age: 30}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.setIn|setIn}\n * @see {@link module:lamb.setPath|setPath}, {@link module:lamb.setPathIn|setPathIn}\n * @param {String} key\n * @param {*} value\n * @returns {Function}\n */\n function setKey (key, value) {\n return partial(setIn, _, key, value);\n }\n\n /**\n * Builds a partial application of {@link module:lamb.setPathIn|setPathIn} expecting the\n * object to act upon.
\n * See {@link module:lamb.setPathIn|setPathIn} for more details and examples.\n * @example\n * var user = {id: 1, status: {active: false}};\n * var activate = _.setPath(\"status.active\", true);\n *\n * activate(user) // => {id: 1, status: {active: true}}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.setPathIn|setPathIn}\n * @see {@link module:lamb.setIn|setIn}, {@link module:lamb.setKey|setKey}\n * @param {String} path\n * @param {*} value\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function setPath (path, value, separator) {\n return partial(setPathIn, _, path, value, separator);\n }\n\n /**\n * Allows to change a nested value in a copy of the provided object.
\n * The function will delegate the \"set action\" to {@link module:lamb.setIn|setIn} or\n * {@link module:lamb.setAt|setAt} depending on the value encountered in the path,\n * so please refer to the documentation of those functions for specifics about the\n * implementation.
\n * Note anyway that the distinction will be between Arrays, delegated\n * to {@link module:lamb.setAt|setAt}, and everything else (including array-like objects),\n * which will be delegated to {@link module:lamb.setIn|setIn}.
\n * As a result of that, array-like objects will be converted to objects having numbers as keys\n * and paths targeting non-object values will be converted to empty objects.
\n * You can anyway target array elements using integers in the path, even negative ones, but\n * the priority will be given to existing, and enumerable, object keys.
\n * Non-enumerable properties encountered in the path will be considered as non-existent properties.
\n * Like {@link module:lamb.getPathIn|getPathIn} or {@link module:lamb.getPath|getPath} you can\n * use custom path separators.\n * @example\n * var user = {id: 1, status: {active : false, scores: [2, 4, 6]}};\n *\n * _.setPathIn(user, \"status.active\", true) // => {id: 1, status: {active : true, scores: [2, 4, 6]}}\n *\n * @example Targeting arrays\n * _.setPathIn(user, \"status.scores.0\", 8) // => {id: 1, status: {active : false, scores: [8, 4, 6]}}\n *\n * // you can use negative indexes as well\n * _.setPathIn(user, \"status.scores.-1\", 8) // => {id: 1, status: {active : false, scores: [2, 4, 8]}}\n *\n * @example Arrays can also be part of the path and not necessarily its target\n * var user = {id: 1, scores: [\n * {value: 2, year: \"2000\"},\n * {value: 4, year: \"2001\"},\n * {value: 6, year: \"2002\"}\n * ]};\n *\n * var newUser = _.setPathIn(user, \"scores.0.value\", 8);\n * // \"newUser\" holds:\n * // {id: 1, scores: [\n * // {value: 8, year: \"2000\"},\n * // {value: 4, year: \"2001\"},\n * // {value: 6, year: \"2002\"}\n * // ]}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.setPath|setPath}\n * @see {@link module:lamb.setIn|setIn}, {@link module:lamb.setKey|setKey}\n * @param {Object|Array} source\n * @param {String} path\n * @param {*} value\n * @param {String} [separator=\".\"]\n * @returns {Object|Array}\n */\n function setPathIn (source, path, value, separator) {\n if (isNil(source)) {\n throw _makeTypeErrorFor(source, \"object\");\n }\n\n return _setPathIn(source, _toPathParts(path, separator), value);\n }\n\n /**\n * Builds a function that creates a copy of an array-like object with the given index\n * changed by applying the provided function to its value.
\n * If the index is not an integer or if it's out of bounds, the function will return\n * a copy of the original array.
\n * Negative indexes are allowed.\n * @example\n * var arr = [\"a\", \"b\", \"c\"];\n * var toUpperCase = _.invoker(\"toUpperCase\");\n *\n * _.updateAt(1, toUpperCase)(arr) // => [\"a\", \"B\", \"c\"]\n * _.updateAt(-1, toUpperCase)(arr) // => [\"a\", \"b\", \"C\"]\n * _.updateAt(10, toUpperCase)(arr) // => [\"a\", \"b\", \"c\"] (not a reference to `arr`)\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.updateIndex|updateIndex}\n * @param {Number} index\n * @param {Function} updater\n * @returns {Function}\n */\n function updateAt (index, updater) {\n return function (arrayLike) {\n return _setIndex(arrayLike, index, null, updater);\n };\n }\n\n /**\n * Creates a copy of the given object having the desired key value updated by applying\n * the provided function to it.
\n * This function is meant for updating existing enumerable properties, and for those it\n * will delegate the \"set action\" to {@link module:lamb.setIn|setIn}; a copy of the\n * source is returned otherwise.\n * @example\n * var user = {name: \"John\", visits: 2};\n * var toUpperCase = _.invoker(\"toUpperCase\");\n *\n * _.updateIn(user, \"name\", toUpperCase) // => {name: \"JOHN\", visits: 2}\n * _.updateIn(user, \"surname\", toUpperCase) // => {name: \"John\", visits: 2}\n *\n * @example Non-enumerable properties will be treated as non-existent:\n * var user = Object.create({name: \"John\"}, {visits: {value: 2}});\n * var increment = _.partial(_.add, 1);\n *\n * _.updateIn(user, \"visits\", increment) // => {name: \"John\", visits: 2}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.updateKey|updateKey}\n * @see {@link module:lamb.updatePath|updatePath}, {@link module:lamb.updatePathIn|updatePathIn}\n * @param {Object} source\n * @param {String} key\n * @param {Function} updater\n * @returns {Object}\n */\n function updateIn (source, key, updater) {\n return _isEnumerable(source, key) ?\n _setIn(source, key, updater(source[key])) :\n _merge(enumerables, source);\n }\n\n /**\n * Creates a copy of an array-like object with the given index changed by applying the\n * provided function to its value.
\n * If the index is not an integer or if it's out of bounds, the function will return\n * a copy of the original array.
\n * Negative indexes are allowed.\n * @example\n * var arr = [\"a\", \"b\", \"c\"];\n * var toUpperCase = _.invoker(\"toUpperCase\");\n *\n * _.updateIndex(arr, 1, toUpperCase) // => [\"a\", \"B\", \"c\"]\n * _.updateIndex(arr, -1, toUpperCase) // => [\"a\", \"b\", \"C\"]\n * _.updateIndex(arr, 10, toUpperCase) // => [\"a\", \"b\", \"c\"] (not a reference to `arr`)\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.updateAt|updateAt}\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @param {Function} updater\n * @returns {Array}\n */\n var updateIndex = partial(_setIndex, _, _, null, _);\n\n /**\n * Builds a partial application of {@link module:lamb.updateIn|updateIn} with the provided\n * key and updater, expecting the object to act upon.\n * @example\n * var user = {name: \"John\", visits: 2};\n * var increment = _.partial(_.add, 1);\n * var incrementVisits = _.updateKey(\"visits\", increment);\n *\n * incrementVisits(user) // => {name: \"John\", visits: 3}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.updateIn|updateIn}\n * @see {@link module:lamb.updatePath|updatePath}, {@link module:lamb.updatePathIn|updatePathIn}\n * @param {String} key\n * @param {Function} updater\n * @returns {Function}\n */\n function updateKey (key, updater) {\n return partial(updateIn, _, key, updater);\n }\n\n /**\n * Builds a partial application of {@link module:lamb.updateIn|updateIn} expecting the object to act upon.\n * @example\n * var user = {id: 1, status: {scores: [2, 4, 6], visits: 0}};\n * var increment = _.partial(_.add, 1);\n * var incrementScores = _.updatePath(\"status.scores\", _.mapWith(increment))\n *\n * incrementScores(user) // => {id: 1, status: {scores: [3, 5, 7], visits: 0}}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.updatePathIn|updatePathIn}\n * @see {@link module:lamb.updateIn|updateIn}, {@link module:lamb.updateKey|updateKey}\n * @param {String} path\n * @param {Function} updater\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function updatePath (path, updater, separator) {\n return partial(updatePathIn, _, path, updater, separator);\n }\n\n /**\n * Allows to change a nested value in a copy of the given object by applying the provided\n * function to it.
\n * This function is meant for updating existing enumerable properties, and for those it\n * will delegate the \"set action\" to {@link module:lamb.setPathIn|setPathIn}; a copy of the\n * source is returned otherwise.
\n * Like the other \"path\" functions, negative indexes can be used to access array elements, but\n * the priority will be given to existing, and enumerable, object keys.
\n * @example\n * var user = {id: 1, status: {scores: [2, 4, 6], visits: 0}};\n * var inc = _.partial(_.add, 1);\n *\n * _.updatePathIn(user, \"status.visits\", inc) // => {id: 1, status: {scores: [2, 4, 6]}, visits: 1}\n *\n * @example Targeting arrays\n * _.updatePathIn(user, \"status.scores.0\", inc) // => {id: 1, status: {scores: [3, 4, 6], visits: 0}}\n *\n * // you can use negative indexes as well\n * _.updatePathIn(user, \"status.scores.-1\", inc) // => {id: 1, status: {scores: [2, 4, 7], visits: 0}}\n *\n * @example Arrays can also be part of the path and not necessarily its target\n * var user = {id: 1, scores: [\n * {value: 2, year: \"2000\"},\n * {value: 4, year: \"2001\"},\n * {value: 6, year: \"2002\"}\n * ]};\n *\n * var newUser = _.updatePathIn(user, \"scores.0.value\", increment);\n * // \"newUser\" holds:\n * // {id: 1, scores: [\n * // {value: 3, year: \"2000\"},\n * // {value: 4, year: \"2001\"},\n * // {value: 6, year: \"2002\"}\n * // ]}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.updatePath|updatePath}\n * @see {@link module:lamb.updateIn|updateIn}, {@link module:lamb.updateKey|updateKey}\n * @param {Object|Array} source\n * @param {String} path\n * @param {Function} updater\n * @param {String} [separator=\".\"]\n * @returns {Object|Array}\n */\n function updatePathIn (source, path, updater, separator) {\n var parts = _toPathParts(path, separator);\n var pathInfo = _getPathInfo(source, parts, false);\n\n if (pathInfo.isValid) {\n return _setPathIn(source, parts, updater(pathInfo.target));\n } else {\n return Array.isArray(source) ? slice(source) : _merge(enumerables, source);\n }\n }\n\n lamb.getAt = getAt;\n lamb.getIn = getIn;\n lamb.getIndex = getIndex;\n lamb.getKey = getKey;\n lamb.getPath = getPath;\n lamb.getPathIn = getPathIn;\n lamb.head = head;\n lamb.last = last;\n lamb.setAt = setAt;\n lamb.setIn = setIn;\n lamb.setIndex = setIndex;\n lamb.setKey = setKey;\n lamb.setPath = setPath;\n lamb.setPathIn = setPathIn;\n lamb.updateAt = updateAt;\n lamb.updateIn = updateIn;\n lamb.updateIndex = updateIndex;\n lamb.updateKey = updateKey;\n lamb.updatePath = updatePath;\n lamb.updatePathIn = updatePathIn;\n\n /**\n * Returns an array of items present only in the first of the given arrays.
\n * Note that this function uses the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.\n * @example\n * var a1 = [1, 2, 3, 4];\n * var a2 = [2, 4, 5];\n * var a3 = [4, 5, 3, 1];\n *\n * _.difference(a1, a2) // => [1, 3]\n * _.difference(a1, a2, a3) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @param {Array} array\n * @param {...Array} other\n * @returns {Array}\n */\n function difference (array) {\n var rest = shallowFlatten(map(_argsTail.apply(null, arguments), unary(slice)));\n var isInRest = partial(isIn, rest, _, 0);\n\n return filter(array, not(isInRest));\n }\n\n /**\n * Builds an array without the first n elements of the given array or array-like object.\n * Note that, being this only a shortcut for a specific use case of {@link module:lamb.slice|slice},\n * n can be a negative number.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.drop(arr, 2) // => [3, 4, 5]\n * _.drop(arr, -1) // => [5]\n * _.drop(arr, -10) // => [1, 2, 3, 4, 5]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.dropN|dropN}\n * @see {@link module:lamb.take|take}, {@link module:lamb.takeN|takeN}\n * @see {@link module:lamb.takeWhile|takeWhile}, {@link module:lamb.dropWhile|dropWhile}\n * @param {ArrayLike} arrayLike\n * @param {Number} n\n * @returns {Array}\n */\n var drop = binary(slice);\n\n /**\n * A curried version of {@link module:lamb.drop|drop} that expects the number of elements\n * to drop to build a function waiting for the list to take the elements from.\n * See the note and examples for {@link module:lamb.drop|drop} about passing a negative n.\n * @example\n * var drop2 = _.dropN(2);\n *\n * drop2([1, 2, 3, 4, 5]) // => [3, 4, 5]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.drop|drop}\n * @see {@link module:lamb.take|take}, {@link module:lamb.takeN|takeN}\n * @see {@link module:lamb.takeWhile|takeWhile}, {@link module:lamb.dropWhile|dropWhile}\n * @param {Number} n\n * @returns {Function}\n */\n function dropN (n) {\n return function (arrayLike) {\n return slice(arrayLike, n);\n };\n }\n\n /**\n * Builds a function that drops the first n elements satisfying a predicate\n * from an array or array-like object.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var dropWhileIsEven = _.dropWhile(isEven);\n *\n * dropWhileIsEven([2, 4, 6, 8]) // => []\n * dropWhileIsEven([2, 4, 7, 8]) // => [7, 8]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.takeWhile|takeWhile}\n * @see {@link module:lamb.drop|drop}, {@link module:lamb.dropN|dropN}\n * @see {@link module:lamb.take|take}, {@link module:lamb.takeN|takeN}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n function dropWhile (predicate, predicateContext) {\n var fn = arguments.length === 2 ? _getNumConsecutiveHits : binary(_getNumConsecutiveHits);\n\n return function (arrayLike) {\n return slice(arrayLike, fn(arrayLike, predicate, predicateContext));\n };\n }\n\n /**\n * Similar to {@link module:lamb.map|map}, but if the mapping function returns an array this will\n * be concatenated, rather than pushed, to the final result.\n * @example showing the difference with map\n * var words = [\"foo\", \"bar\"];\n * var toCharArray = function (s) { return s.split(\"\"); };\n *\n * _.map(words, toCharArray) // => [[\"f\", \"o\", \"o\"], [\"b\", \"a\", \"r\"]]\n * _.flatMap(words, toCharArray) // => [\"f\", \"o\", \"o\", \"b\", \"a\", \"r\"]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.flatMapWith|flatMapWith}\n * @param {Array} array\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Array}\n */\n function flatMap (array, iteratee, iterateeContext) {\n if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n return reduce(array, function (result, el, idx, arr) {\n var v = iteratee(el, idx, arr);\n\n if (!Array.isArray(v)) {\n v = [v];\n }\n\n for (var i = 0, len = v.length, rLen = result.length; i < len; i++) {\n result[rLen + i] = v[i];\n }\n\n return result;\n }, []);\n }\n\n /**\n * Builds a partial application of {@link module:lamb.flatMap|flatMap} using the given iteratee\n * and the optional context. The resulting function expects the array to act upon.\n * @example\n * var toCharArray = function (s) { return s.split(\"\"); };\n * var wordsToCharArray = _.flatMapWith(toCharArray);\n *\n * wordsToCharArray([\"foo\", \"bar\"]) // => [\"f\", \"o\", \"o\", \"b\", \"a\", \"r\"]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.flatMap|flatMap}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Function}\n */\n var flatMapWith = _partialWithIteratee(flatMap);\n\n /**\n * Flattens an array.\n * @example showing the difference with shallowFlatten\n * var arr = [1, 2, [3, 4, [5, 6]], 7, 8];\n *\n * _.flatten(arr) // => [1, 2, 3, 4, 5, 6, 7, 8]\n * _.shallowFlatten(arr) // => [1, 2, 3, 4, [5, 6], 7, 8]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.shallowFlatten|shallowFlatten}\n * @param {Array} array\n * @returns {Array}\n */\n function flatten (array) {\n return Array.isArray(array) ? _flatten(array, true, [], 0) : slice(array);\n }\n\n /**\n * Returns a copy of the given array-like object without the last element.\n * @example\n * _.init([1, 2, 3, 4]) // => [1, 2, 3]\n * _.init([1]) // => []\n * _.init([]) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.tail|tail}\n * @see {@link module:lamb.head|head}, {@link module:lamb.last|last}\n * @param {ArrayLike} arrayLike\n * @returns {Array}\n */\n var init = partial(slice, _, 0, -1);\n\n /**\n * Inserts the provided element in a copy of an array-like object at the\n * specified index.
\n * If the index is greater than the length of the array-like, the element\n * will be appended at the end.
\n * Negative indexes are allowed; when a negative index is out of bounds\n * the element will be inserted at the start of the resulting array.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.insert(arr, 3, 99) // => [1, 2, 3, 99, 4, 5]\n * _.insert(arr, -2, 99) // => [1, 2, 3, 99, 4, 5]\n * _.insert(arr, 10, 99) // => [1, 2, 3, 4, 5, 99]\n * _.insert(arr, -10, 99) // => [99, 1, 2, 3, 4, 5]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.insertAt|insertAt}\n * @see {@link module:lamb.sortedInsert|sortedInsert}\n * @param {ArrayLike} arrayLike\n * @param {Number} index\n * @param {*} element\n * @returns {Array}\n */\n function insert (arrayLike, index, element) {\n var result = slice(arrayLike);\n\n result.splice(index, 0, element);\n\n return result;\n }\n\n /**\n * Builds a partial application of {@link module:lamb.insert|insert}\n * expecting the array-like object to act upon.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.insertAt(3, 99)(arr) // => [1, 2, 3, 99, 4, 5]\n * _.insertAt(-2, 99)(arr) // => [1, 2, 3, 99, 4, 5]\n * _.insertAt(10, 99)(arr) // => [1, 2, 3, 4, 5, 99]\n * _.insertAt(-10, 99)(arr) // => [99, 1, 2, 3, 4, 5]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.insert|insert}\n * @see {@link module:lamb.sortedInsert|sortedInsert}\n * @param {Number} index\n * @param {*} element\n * @returns {Function}\n */\n function insertAt (index, element) {\n return partial(insert, _, index, element);\n }\n\n /**\n * Returns an array of every item that is included in all given arrays.
\n * Note that this function uses the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.\n * @example\n * var a1 = [1, 2, 3, 4];\n * var a2 = [2, 5, 4, 6];\n * var a3 = [5, 6, 7];\n *\n * _.intersection(a1, a2) // => [2, 4]\n * _.intersection(a1, a3) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @param {...Array} array\n * @returns {Array}\n */\n function intersection () {\n var rest = _argsTail.apply(null, arguments);\n\n return filter(uniques(arguments[0]), function (item) {\n return everyIn(rest, contains(item));\n });\n }\n\n /**\n * Generates an array with the values passed as arguments.\n * @example\n * _.list(1, 2, 3) // => [1, 2, 3]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {...*} value\n * @returns {Array}\n */\n var list = _argsToArrayFrom(0);\n\n /**\n * Splits an array-like object in two lists: the first with the elements satisfying the given predicate,\n * the others with the remaining elements.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n *\n * _.partition(numbers, isEven) // => [[2, 4, 6, 8, 10], [1, 3, 5, 7, 9]]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.partitionWith|partitionWith}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Array, Array<*>>}\n */\n function partition (arrayLike, predicate, predicateContext) {\n var result = [[], []];\n var len = arrayLike.length;\n\n if (arguments.length === 3) {\n predicate = predicate.bind(predicateContext);\n }\n\n for (var i = 0, el; i < len; i++) {\n el = arrayLike[i];\n result[predicate(el, i, arrayLike) ? 0 : 1].push(el);\n }\n\n return result;\n }\n\n /**\n * Builds a partial application of {@link module:lamb.partition|partition} using the given\n * predicate and the optional context.\n * The resulting function expects the array-like object to act upon.\n * @example\n * var users = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"active\": false},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"active\": true},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"active\": true},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"active\": false}\n * ];\n * var isActive = _.hasKeyValue(\"active\", true);\n * var splitByActiveStatus = _.partitionWith(isActive);\n *\n * splitByActiveStatus(users) // =>\n * // [[\n * // {\"name\": \"John\", \"surname\": \"Doe\", \"active\": true},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\", \"active\": true}\n * // ], [\n * // {\"name\": \"Jane\", \"surname\": \"Doe\", \"active\": false},\n * // {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"active\": false}\n * // ]]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.partition|partition}\n * @param {ListIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var partitionWith = _partialWithIteratee(partition);\n\n /**\n * \"Plucks\" the values of the specified key from a list of objects.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"age\": 12},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"age\": 18},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"age\": 15}\n * ];\n *\n * _.pluck(persons, \"age\") // => [12, 40, 18, 15]\n *\n * var lists = [\n * [1, 2],\n * [3, 4, 5],\n * [6]\n * ];\n *\n * _.pluck(lists, \"length\") // => [2, 3, 1]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.pluckKey|pluckKey}\n * @param {ArrayLike} arrayLike\n * @param {String} key\n * @returns {Array}\n */\n function pluck (arrayLike, key) {\n return map(arrayLike, getKey(key));\n }\n\n /**\n * A curried version of {@link module:lamb.pluck|pluck} expecting the key to retrieve to\n * build a function waiting for the array-like object to act upon.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"surname\": \"Doe\", \"age\": 12},\n * {\"name\": \"John\", \"surname\": \"Doe\", \"age\": 40},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\", \"age\": 18},\n * {\"name\": \"Paolo\", \"surname\": \"Bianchi\", \"age\": 15}\n * ];\n * var getAges = _.pluckKey(\"age\");\n *\n * getAges(persons) // => [12, 40, 18, 15]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.pluck|pluck}\n * @function\n * @param {String} key\n * @returns {Function}\n */\n var pluckKey = compose(mapWith, getKey);\n\n /**\n * Reverses a copy of the given array-like object.\n * @example\n * var arr = [1, 2, 3];\n *\n * _.reverse(arr) // => [3, 2, 1];\n *\n * // `arr` still is [1, 2, 3]\n *\n * @memberof module:lamb\n * @category Array\n * @param {ArrayLike} arrayLike\n * @returns {Array}\n */\n function reverse (arrayLike) {\n return slice(arrayLike).reverse();\n }\n\n /**\n * Flattens the \"first level\" of an array.\n * @example showing the difference with flatten\n * var arr = [1, 2, [3, 4, [5, 6]], 7, 8];\n *\n * _.flatten(arr) // => [1, 2, 3, 4, 5, 6, 7, 8]\n * _.shallowFlatten(arr) // => [1, 2, 3, 4, [5, 6], 7, 8]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.flatten|flatten}\n * @param {Array} array\n * @returns {Array}\n */\n function shallowFlatten (array) {\n return Array.isArray(array) ? _flatten(array, false, [], 0) : slice(array);\n }\n\n /**\n * Returns a copy of the given array-like object without the first element.\n * @example\n * _.tail([1, 2, 3, 4]) // => [2, 3, 4]\n * _.tail([1]) // => []\n * _.tail([]) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.init|init}\n * @see {@link module:lamb.head|head}, {@link module:lamb.last|last}\n * @param {ArrayLike} arrayLike\n * @returns {Array}\n */\n var tail = partial(slice, _, 1, void 0);\n\n /**\n * Retrieves the first n elements from an array or array-like object.
\n * Note that, being this a shortcut for a common use case of {@link module:lamb.slice|slice},\n * n can be a negative number.\n * @example\n * var arr = [1, 2, 3, 4, 5];\n *\n * _.take(arr, 3) // => [1, 2, 3]\n * _.take(arr, -1) // => [1, 2, 3, 4]\n * _.take(arr, -10) // => []\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.takeN|takeN}\n * @see {@link module:lamb.drop|drop}, {@link module:lamb.dropN|dropN}\n * @see {@link module:lamb.takeWhile|takeWhile}, {@link module:lamb.dropWhile|dropWhile}\n * @param {ArrayLike} arrayLike\n * @param {Number} n\n * @returns {Array}\n */\n function take (arrayLike, n) {\n return slice(arrayLike, 0, +n);\n }\n\n /**\n * A curried version of {@link module:lamb.take|take} that expects the number of elements\n * to retrieve to build a function waiting for the list to take the elements from.\n * See the note and examples for {@link module:lamb.take|take} about passing a negative n.\n * @example\n * var take2 = _.takeN(2);\n *\n * take2([1, 2, 3, 4, 5]) // => [1, 2]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.take|take}\n * @see {@link module:lamb.drop|drop}, {@link module:lamb.dropN|dropN}\n * @see {@link module:lamb.takeWhile|takeWhile}, {@link module:lamb.dropWhile|dropWhile}\n * @param {Number} n\n * @returns {Function}\n */\n function takeN (n) {\n return function (arrayLike) {\n return slice(arrayLike, 0, +n);\n };\n }\n\n /**\n * Builds a function that takes the first n elements satisfying a predicate from\n * an array or array-like object.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var takeWhileIsEven = _.takeWhile(isEven);\n *\n * takeWhileIsEven([1, 2, 4, 6, 8]) // => []\n * takeWhileIsEven([2, 4, 7, 8]) // => [2, 4]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.dropWhile|dropWhile}\n * @see {@link module:lamb.take|take}, {@link module:lamb.takeN|takeN}\n * @see {@link module:lamb.drop|drop}, {@link module:lamb.dropN|dropN}\n * @param {ListIteratorCallback} predicate\n * @param {Object} predicateContext\n * @returns {Function}\n */\n function takeWhile (predicate, predicateContext) {\n var fn = arguments.length === 2 ? _getNumConsecutiveHits : binary(_getNumConsecutiveHits);\n\n return function (arrayLike) {\n return slice(arrayLike, 0, fn(arrayLike, predicate, predicateContext));\n };\n }\n\n /**\n * Transposes a matrix. Can also be used to reverse a {@link module:lamb.zip|zip} operation.
\n * Just like {@link module:lamb.zip|zip}, the received array-like objects will be truncated to the\n * shortest length.\n * @example transposing a matrix\n * _.transpose([\n * [1, 2, 3],\n * [4, 5, 6],\n * [7, 8, 9]\n * ]) // =>\n * // [\n * // [1, 4, 7],\n * // [2, 5, 8],\n * // [3, 6, 9]\n * // ]\n *\n * @example showing the relationship with zip\n * var zipped = _.zip([\"a\", \"b\", \"c\"], [1, 2, 3]); // => [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n *\n * _.transpose(zipped) // => [[\"a\", \"b\", \"c\"], [1, 2, 3]]\n *\n * @memberof module:lamb\n * @category Array\n * @param {ArrayLike>} arrayLike\n * @returns {Array>}\n */\n function transpose (arrayLike) {\n var result = [];\n var len = arrayLike.length >>> 0;\n\n if (len === 0) {\n return result;\n }\n\n var minLen = arrayLike[0].length >>> 0;\n\n for (var j = 1, elementLen; j < len && minLen > 0; j++) {\n elementLen = arrayLike[j].length >>> 0;\n\n if (elementLen < minLen) {\n minLen = elementLen;\n }\n }\n\n for (var i = 0, el; i < minLen; i++) {\n el = result[i] = Array(len);\n\n for (j = 0; j < len; j++) {\n el[j] = arrayLike[j][i];\n }\n }\n\n return result;\n }\n\n /**\n * Returns a list of every unique element present in the given array-like objects.\n * @example\n * _.union([1, 2, 3, 2], [3, 4], [1, 5]) // => [1, 2, 3, 4, 5]\n * _.union(\"abc\", \"bcd\", \"cde\") // => [\"a\", \"b\", \"c\", \"d\", \"e\"]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {...ArrayLike} arrayLike\n * @returns {Array}\n */\n var union = compose(uniques, flatMapWith(unary(slice)), list);\n\n /**\n * Returns an array comprised of the unique elements of the given array-like object.
\n * Can work with lists of complex objects if supplied with an iteratee.
\n * Note that this function uses the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.
\n * When two values are considered equal, the first occurence will be the one included\n * in the result array.\n * @example With simple values:\n * _.uniques([-0, 1, 2, 0, 2, 3, 4, 3, 5, 1]) // => [-0, 1, 2, 3, 4, 5]\n *\n * @example With complex values:\n * var data = [\n * {id: \"1\", name: \"John\"},\n * {id: \"4\", name: \"Jane\"},\n * {id: \"5\", name: \"Joe\"},\n * {id: \"1\", name: \"Mario\"},\n * {id: \"5\", name: \"Paolo\"},\n * ];\n *\n * _.uniques(data, _.getKey(\"id\")) // =>\n * // [\n * // {id: \"1\", name: \"John\"},\n * // {id: \"4\", name: \"Jane\"},\n * // {id: \"5\", name: \"Joe\"}\n * // ]\n *\n * @memberof module:lamb\n * @category Array\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} [iteratee={@link module:lamb.identity|identity}]\n * @param {Object} [iterateeContext]\n * @returns {Array}\n */\n function uniques (arrayLike, iteratee, iterateeContext) {\n if (typeof iteratee !== \"function\") {\n iteratee = identity;\n } else if (arguments.length === 3) {\n iteratee = iteratee.bind(iterateeContext);\n }\n\n var result = [];\n var len = arrayLike.length;\n\n for (var i = 0, seen = [], hasNaN = false, value; i < len; i++) {\n value = iteratee(arrayLike[i], i, arrayLike);\n\n // eslint-disable-next-line no-self-compare\n if (value === value) {\n if (seen.indexOf(value) === -1) {\n seen[seen.length] = value;\n result[result.length] = arrayLike[i];\n }\n } else if (!hasNaN) {\n hasNaN = true;\n result[result.length] = arrayLike[i];\n }\n }\n\n return result;\n }\n\n /**\n * Builds a list of arrays out of the given array-like objects by pairing items with the same index.
\n * The received array-like objects will be truncated to the shortest length.
\n * See also {@link module:lamb.zipWithIndex|zipWithIndex} and {@link module:lamb.transpose|transpose}\n * for the reverse operation.\n * @example\n * _.zip(\n * [\"a\", \"b\", \"c\"],\n * [1, 2, 3],\n * [true, false, true]\n * ) // => [[\"a\", 1, true], [\"b\", 2, false], [\"c\", 3, true]]\n *\n * _.zip([1, 2, 3, 4], [5, 6, 7]) // => [[1, 5], [2, 6], [3, 7]]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {...ArrayLike} arrayLike\n * @returns {Array>}\n */\n var zip = compose(transpose, list);\n\n /**\n * \"{@link module:lamb.zip|Zips}\" an array-like object by pairing its values with their index.\n * @example\n * _.zipWithIndex([\"a\", \"b\", \"c\"]) // => [[\"a\", 0], [\"b\", 1], [\"c\", 2]]\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @param {ArrayLike} arrayLike\n * @returns {Array>}\n */\n var zipWithIndex = mapWith(binary(list));\n\n lamb.difference = difference;\n lamb.drop = drop;\n lamb.dropN = dropN;\n lamb.dropWhile = dropWhile;\n lamb.flatMap = flatMap;\n lamb.flatMapWith = flatMapWith;\n lamb.flatten = flatten;\n lamb.init = init;\n lamb.insert = insert;\n lamb.insertAt = insertAt;\n lamb.intersection = intersection;\n lamb.list = list;\n lamb.partition = partition;\n lamb.partitionWith = partitionWith;\n lamb.pluck = pluck;\n lamb.pluckKey = pluckKey;\n lamb.reverse = reverse;\n lamb.shallowFlatten = shallowFlatten;\n lamb.tail = tail;\n lamb.take = take;\n lamb.takeN = takeN;\n lamb.takeWhile = takeWhile;\n lamb.transpose = transpose;\n lamb.union = union;\n lamb.uniques = uniques;\n lamb.zip = zip;\n lamb.zipWithIndex = zipWithIndex;\n\n /**\n * Transforms an array-like object in a lookup table with the keys generated by the provided\n * iteratee, having as values the count of matches for the key.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"age\": 12},\n * {\"name\": \"John\", \"age\": 40},\n * {\"name\": \"Mario\", \"age\": 17},\n * {\"name\": \"Paolo\", \"age\": 15}\n * ];\n * var getAgeStatus = function (person) { return person.age >= 18 ? \"adult\" : \"minor\"; };\n *\n * _.count(persons, getAgeStatus) // => {\"adult\": 1, \"minor\": 3}\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.group|group}, {@link module:lamb.groupBy|groupBy}\n * @see {@link module:lamb.index|index}, {@link module:lamb.indexBy|indexBy}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Object}\n */\n var count = _groupWith(function (a) {\n return a ? ++a : 1;\n });\n\n /**\n * Using the provided iteratee, and its optional context, builds a partial application of\n * {@link module:lamb.count|count} expecting the array-like object to act upon.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"city\": \"New York\"},\n * {\"name\": \"John\", \"city\": \"New York\"},\n * {\"name\": \"Mario\", \"city\": \"Rome\"},\n * {\"name\": \"Paolo\"}\n * ];\n * var getCityOrUnknown = _.adapter(_.getKey(\"city\"), _.always(\"Unknown\"));\n * var countByCity = _.countBy(getCityOrUnknown);\n *\n * countByCity(persons) // => {\"New York\": 2, \"Rome\": 1, \"Unknown\": 1}\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.count|count}\n * @see {@link module:lamb.group|group}, {@link module:lamb.groupBy|groupBy}\n * @see {@link module:lamb.index|index}, {@link module:lamb.indexBy|indexBy}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Function}\n */\n var countBy = _partialWithIteratee(count);\n\n /**\n * Transforms an array-like object into a lookup table using the provided iteratee as a grouping\n * criterion to generate keys and values.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"city\": \"New York\"},\n * {\"name\": \"John\", \"city\": \"New York\"},\n * {\"name\": \"Mario\", \"city\": \"Rome\"},\n * {\"name\": \"Paolo\"}\n * ];\n * var getCity = _.getKey(\"city\");\n * var personsByCity = _.group(persons, getCity);\n *\n * // \"personsByCity\" holds:\n * // {\n * // \"New York\": [\n * // {\"name\": \"Jane\", \"city\": \"New York\"},\n * // {\"name\": \"John\", \"city\": \"New York\"}\n * // ],\n * // \"Rome\": [\n * // {\"name\": \"Mario\", \"city\": \"Rome\"}\n * // ],\n * // \"undefined\": [\n * // {\"name\": \"Paolo\"}\n * // ]\n * // }\n *\n * @example Adding a custom value for missing keys\n *\n * var getCityOrUnknown = _.adapter(getCity, _.always(\"Unknown\"));\n *\n * var personsByCity = _.group(persons, getCityOrUnknown);\n *\n * // \"personsByCity\" holds:\n * // {\n * // \"New York\": [\n * // {\"name\": \"Jane\", \"city\": \"New York\"},\n * // {\"name\": \"John\", \"city\": \"New York\"}\n * // ],\n * // \"Rome\": [\n * // {\"name\": \"Mario\", \"city\": \"Rome\"}\n * // ],\n * // \"Unknown\": [\n * // {\"name\": \"Paolo\"}\n * // ]\n * // }\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.groupBy|groupBy}\n * @see {@link module:lamb.count|count}, {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.index|index}, {@link module:lamb.indexBy|indexBy}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Object}\n */\n var group = _groupWith(function (a, b) {\n if (!a) {\n return [b];\n }\n\n a[a.length] = b;\n\n return a;\n });\n\n /**\n * Using the provided iteratee, and its optional context, builds a partial application\n * of {@link module:lamb.group|group} expecting the array-like object to act upon.\n * @example\n * var persons = [\n * {\"name\": \"Jane\", \"age\": 12},\n * {\"name\": \"John\", \"age\": 40},\n * {\"name\": \"Mario\", \"age\": 18},\n * {\"name\": \"Paolo\", \"age\": 15}\n * ];\n *\n * var getAgeStatus = function (person) { return person.age > 20 ? \"over 20\" : \"under 20\"; };\n * var groupByAgeStatus = _.groupBy(getAgeStatus);\n *\n * var personsByAgeStatus = groupByAgeStatus(persons);\n *\n * // \"personsByAgeStatus\" holds:\n * // {\n * // \"under 20\": [\n * // {\"name\": \"Jane\", \"age\": 12},\n * // {\"name\": \"Mario\", \"age\": 18},\n * // {\"name\": \"Paolo\", \"age\": 15}\n * // ],\n * // \"over 20\": [\n * // {\"name\": \"John\", \"age\": 40}\n * // ]\n * // }\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.group|group}\n * @see {@link module:lamb.count|count}, {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.index|index}, {@link module:lamb.indexBy|indexBy}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Function}\n */\n var groupBy = _partialWithIteratee(group);\n\n /**\n * Similar to {@link module:lamb.group|group}, but the generated lookup table will have\n * only one element of the original array-like object for each value.
\n * Should be used only when you're sure that your iteratee won't produce\n * duplicate keys, otherwise only the last evaluated element will be in the result.\n * @example\n * var users = [\n * {id: 1, name: \"John\"},\n * {id: 2, name: \"Jane\"},\n * {id: 3, name: \"Mario\"},\n * {id: 4, name: \"John\"}\n * ];\n *\n * var indexedUsers = _.index(users, _.getKey(\"id\"));\n *\n * // \"indexedUsers\" holds:\n * // {\n * // \"1\": {id: 1, name: \"John\"},\n * // \"2\": {id: 2, name: \"Jane\"},\n * // \"3\": {id: 3, name: \"Mario\"},\n * // \"4\": {id: 4, name: \"John\"}\n * // }\n *\n * @example Result of an iteratee producing a duplicate key:\n * var users = [\n * {id: 1, name: \"John\"},\n * {id: 2, name: \"Jane\"},\n * {id: 3, name: \"Mario\"},\n * {id: 4, name: \"John\"}\n * ];\n *\n * var indexedUsers = _.index(users, _.getKey(\"name\"));\n *\n * // \"indexedUsers\" holds:\n * // {\n * // \"John\": {\"id\": 4, \"name\": \"John\"},\n * // \"Jane\": {\"id\": 2, \"name\": \"Jane\"},\n * // \"Mario\": {\"id\": 3, \"name\": \"Mario\"}\n * // }\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.indexBy|indexBy}\n * @see {@link module:lamb.count|count}, {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.group|group}, {@link module:lamb.groupBy|groupBy}\n * @param {ArrayLike} arrayLike\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Object}\n */\n var index = _groupWith(function (a, b) {\n return b;\n });\n\n /**\n * Using the provided iteratee, and its optional context, builds a partial application\n * of {@link module:lamb.index|index} expecting the array-like object to act upon.\n * @example\n * var users = [\n * {id: 1, name: \"John\"},\n * {id: 2, name: \"Jane\"},\n * {id: 3, name: \"Mario\"}\n * ];\n * var indexByID = _.indexBy(_.getKey(\"id\"));\n *\n * var indexedUsers = indexByID(users);\n *\n * // \"indexedUsers\" holds:\n * // {\n * // \"1\": {id: 1, name: \"John\"},\n * // \"2\": {id: 2, name: \"Jane\"},\n * // \"3\": {id: 3, name: \"Mario\"}\n * // }\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.index|index}\n * @see {@link module:lamb.count|count}, {@link module:lamb.countBy|countBy}\n * @see {@link module:lamb.group|group}, {@link module:lamb.groupBy|groupBy}\n * @param {ListIteratorCallback} iteratee\n * @param {Object} [iterateeContext]\n * @returns {Function}\n */\n var indexBy = _partialWithIteratee(index);\n\n lamb.count = count;\n lamb.countBy = countBy;\n lamb.group = group;\n lamb.groupBy = groupBy;\n lamb.index = index;\n lamb.indexBy = indexBy;\n\n /**\n * Returns a [stably]{@link https://en.wikipedia.org/wiki/Sorting_algorithm#Stability} sorted\n * copy of an array-like object using the given criteria.
\n * Sorting criteria are built using Lamb's {@link module:lamb.sorter|sorter} function, but you\n * can also pass simple \"reader\" functions and default ascending sorters will be built for you.
\n * A \"reader\" is a function that evaluates the array element and supplies the value to be used\n * in the comparison.
\n * Please note that if the arguments received by the default comparer aren't of the same type,\n * they will be compared as strings.\n *\n * @example Stable sort:\n * var persons = [\n * {\"name\": \"John\", \"surname\" :\"Doe\"},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\"},\n * {\"name\": \"John\", \"surname\" :\"Moe\"},\n * {\"name\": \"Jane\", \"surname\": \"Foe\"}\n * ];\n *\n * var personsByName = _.sort(persons, _.getKey(\"name\"));\n *\n * // personsByName holds:\n * // [\n * // {\"name\": \"Jane\", \"surname\": \"Foe\"},\n * // {\"name\": \"John\", \"surname\" :\"Doe\"},\n * // {\"name\": \"John\", \"surname\" :\"Moe\"},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * // ]\n *\n * @example Stable multi-sort:\n * var personsByNameAscSurnameDesc = _.sort(\n * persons,\n * _.getKey(\"name\"),\n * _.sorterDesc(_.getKey(\"surname\"))\n * );\n *\n * // personsByNameAscSurnameDesc holds:\n * // [\n * // {\"name\": \"Jane\", \"surname\": \"Foe\"},\n * // {\"name\": \"John\", \"surname\" :\"Moe\"},\n * // {\"name\": \"John\", \"surname\" :\"Doe\"},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * // ]\n *\n * @example Using custom comparers:\n * var localeSorter = new Intl.Collator(\"it\");\n * var chars = [\"a\", \"è\", \"à\", \"é\", \"c\", \"b\", \"e\"];\n *\n * _.sort(chars, localeSorter) // => [\"a\", \"à\", \"b\", \"c\", \"e\", \"é\", \"è\"]\n *\n * var localeSorterDesc = _.sorterDesc(_.identity, localeSorter.compare);\n *\n * _.sort(chars, localeSorterDesc) // => [\"è\", \"é\", \"e\", \"c\", \"b\", \"à\", \"a\"]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.sortWith|sortWith}\n * @see {@link module:lamb.sorter|sorter}, {@link module:lamb.sorterDesc|sorterDesc}\n * @param {ArrayLike} arrayLike\n * @param {...(Sorter|Function)} [sorter={@link module:lamb.sorter|sorter()}]\n * @returns {Array}\n */\n function sort (arrayLike) {\n var criteria = _makeCriteria(_argsTail.apply(null, arguments));\n var data = [];\n var result = [];\n var len = arrayLike.length;\n\n for (var i = 0; i < len; i++) {\n data.push({\n value: arrayLike[i],\n index: i\n });\n }\n\n data.sort(_compareWith(criteria));\n\n for (i = 0; i < len; i++) {\n result.push(data[i].value);\n }\n\n return result;\n }\n\n /**\n * Inserts an element in a copy of a sorted array respecting the sort order.\n * @example with simple values\n * _.sortedInsert([], 1) // => [1]\n * _.sortedInsert([2, 4, 6], 5) // => [2, 4, 5, 6]\n * _.sortedInsert([4, 2, 1], 3, _.sorterDesc()) // => [4, 3, 2, 1]\n *\n * @example with complex values\n * var persons = [\n * {\"name\": \"jane\", \"surname\": \"doe\"},\n * {\"name\": \"John\", \"surname\": \"Doe\"},\n * {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * ];\n *\n * var getLowerCaseName = _.compose(\n * _.invoker(\"toLowerCase\"),\n * _.getKey(\"name\")\n * );\n *\n * var result = _.sortedInsert(\n * persons,\n * {\"name\": \"marco\", \"surname\": \"Rossi\"},\n * getLowerCaseName\n * );\n *\n * // `result` holds:\n * // [\n * // {\"name\": \"jane\", \"surname\": \"doe\"},\n * // {\"name\": \"John\", \"surname\": \"Doe\"},\n * // {\"name\": \"marco\", \"surname\": \"Rossi\"},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * // ]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.sort|sort}, {@link module:lamb.sortWith|sortWith}\n * @see {@link module:lamb.sorter|sorter}, {@link module:lamb.sorterDesc|sorterDesc}\n * @see {@link module:lamb.insert|insert}, {@link module:lamb.insertAt|insertAt} to insert the element\n * at a specific index\n * @param {ArrayLike} arrayLike\n * @param {*} element\n * @param {...(Sorter|Function)} [sorter={@link module:lamb.sorter|sorter()}] - The sorting criteria\n * used to sort the array.\n * @returns {Array}\n */\n function sortedInsert (arrayLike, element) {\n var result = slice(arrayLike);\n\n if (arguments.length === 1) {\n return result;\n }\n\n var len = arguments.length - 2;\n var sorters = Array(len);\n\n for (var i = 0; i < len; i++) {\n sorters[i] = arguments[i + 2];\n }\n\n var criteria = _makeCriteria(sorters);\n var idx = _getInsertionIndex(result, element, _compareWith(criteria), 0, result.length);\n\n result.splice(idx, 0, element);\n\n return result;\n }\n\n /**\n * Creates an ascending sort criterion with the provided reader and\n * comparer.
\n * See {@link module:lamb.sort|sort} for various examples.\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.sortedInsert|sortedInsert}\n * @see {@link module:lamb.sort|sort}, {@link module:lamb.sortWith|sortWith}\n * @see {@link module:lamb.sorterDesc|sorterDesc}\n * @param {Function} [reader={@link module:lamb.identity|identity}] A function meant to generate a\n * simple value from a complex one. The function should evaluate the array element and supply the\n * value to be passed to the comparer.\n * @param {Function} [comparer] An optional custom comparer function.\n * @returns {Sorter}\n */\n var sorter = partial(_sorter, _, false, _);\n\n /**\n * Creates a descending sort criterion with the provided reader and\n * comparer.
\n * See {@link module:lamb.sort|sort} for various examples.\n *\n * @memberof module:lamb\n * @category Array\n * @function\n * @see {@link module:lamb.sortedInsert|sortedInsert}\n * @see {@link module:lamb.sort|sort}, {@link module:lamb.sortWith|sortWith}\n * @see {@link module:lamb.sorter|sorter}\n * @param {Function} [reader={@link module:lamb.identity|identity}] A function meant to generate a\n * simple value from a complex one. The function should evaluate the array element and supply the\n * value to be passed to the comparer.\n * @param {Function} [comparer] An optional custom comparer function.\n * @returns {Sorter}\n */\n var sorterDesc = partial(_sorter, _, true, _);\n\n /**\n * Builds a partial application of {@link module:lamb.sort|sort} using the provided criteria.\n * The returned function expects the array-like object to sort.\n * As usual, sorting criteria are built using Lamb's {@link module:lamb.sorter|sorter} function,\n * but you can also pass simple \"reader\" functions and default ascending sorters will be built.
\n * A \"reader\" is a function that evaluates the array element and supplies the value to be used in\n * the comparison.
\n * See {@link module:lamb.sort|sort} for more examples.\n *\n * @example\n * var sortAsNumbers = _.sortWith(parseFloat);\n * var weights = [\"2 Kg\", \"10 Kg\", \"1 Kg\", \"7 Kg\"];\n *\n * sortAsNumbers(weights) // => [\"1 Kg\", \"2 Kg\", \"7 Kg\", \"10 Kg\"]\n *\n * @memberof module:lamb\n * @category Array\n * @see {@link module:lamb.sort|sort}\n * @see {@link module:lamb.sorter|sorter}, {@link module:lamb.sorterDesc|sorterDesc}\n * @param {...(Sorter|Function)} [sorter={@link module:lamb.sorter|sorter()}]\n * @returns {Function}\n */\n function sortWith () {\n var sorters = list.apply(null, arguments);\n\n return function (arrayLike) {\n return sort.apply(null, [arrayLike].concat(sorters));\n };\n }\n\n lamb.sort = sort;\n lamb.sortedInsert = sortedInsert;\n lamb.sorter = sorter;\n lamb.sorterDesc = sorterDesc;\n lamb.sortWith = sortWith;\n\n /**\n * Applies the passed function to the given argument list.\n * @example\n * _.apply(_.add, [3, 4]) // => 7\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {ArrayLike} args\n * @returns {*}\n */\n function apply (fn, args) {\n return fn.apply(this, Object(args));\n }\n\n /**\n * A curried version of {@link module:lamb.apply|apply}. Expects an array-like object to use as arguments\n * and builds a function waiting for the target of the application.\n * @example\n * var data = [3, 4];\n * var applyDataTo = _.applyArgs(data);\n *\n * applyDataTo(_.add) // => 7\n * applyDataTo(_.multiply) // => 12\n *\n * @memberof module:lamb\n * @category Function\n * @param {ArrayLike} args\n * @returns {Function}\n */\n function applyArgs (args) {\n return function (fn) {\n return fn.apply(this, Object(args));\n };\n }\n\n /**\n * Builds a function that passes only the specified amount of arguments to the given function.
\n * As {@link module:lamb.slice|slice} is used to extract the arguments, you can also\n * pass a negative arity.
\n * See also {@link module:lamb.binary|binary} and {@link module:lamb.unary|unary} for common use\n * cases shortcuts.\n * @example\n * function maxArgument () {\n * return Math.max.apply(null, arguments);\n * }\n *\n * maxArgument(10, 11, 45, 99) // => 99\n * _.aritize(maxArgument, 2)(10, 11, 45, 99) // => 11\n *\n * @example Using a negative arity:\n * _.aritize(maxArgument, -1)(10, 11, 45, 99) // => 45\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {Number} arity\n * @returns {Function}\n */\n function aritize (fn, arity) {\n return function () {\n var args = slice(list.apply(null, arguments), 0, arity);\n var argsLen = args.length;\n var n = Math.floor(arity);\n\n if (n > 0) {\n while (argsLen < n) {\n args[argsLen++] = void 0;\n }\n }\n\n return fn.apply(this, args);\n };\n }\n\n /**\n * Decorates the received function so that it can be called with\n * placeholders to build a partial application of it.
\n * The difference with {@link module:lamb.partial|partial} is that, as long as\n * you call the generated function with placeholders, another partial application\n * of the original function will be built.
\n * The final application will happen when one of the generated functions is\n * invoked without placeholders, using the parameters collected so far.
\n * This function comes in handy when you need to build different specialized\n * functions starting from a basic one, but it's also useful when dealing with\n * optional parameters as you can decide to apply the function even if its arity\n * hasn't been entirely consumed.\n * @example Explaining the function's behaviour:\n * var f = _.asPartial(function (a, b, c) {\n * return a + b + c;\n * });\n *\n * f(4, 3, 2) // => 9\n * f(4, _, 2)(3) // => 9\n * f(_, 3, _)(4, _)(2) // => 9\n *\n * @example Exploiting optional parameters: \n * var f = _.asPartial(function (a, b, c) {\n * return a + b + (c || 0);\n * });\n *\n * var addFive = f(5, _);\n * addFive(2) // => 7\n *\n * var addNine = addFive(4, _);\n * addNine(11) // => 20\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.partial|partial}\n * @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}\n * @param {Function} fn\n * @returns {Function}\n */\n function asPartial (fn) {\n return _asPartial(fn, []);\n }\n\n /**\n * Builds a function that passes only two arguments to the given function.
\n * It's simply a shortcut for a common use case of {@link module:lamb.aritize|aritize},\n * exposed for convenience.
\n * See also {@link module:lamb.unary|unary}.\n * @example\n * _.list(1, 2, 3, 4, 5) // => [1, 2, 3, 4, 5]\n * _.binary(_.list)(1, 2, 3, 4, 5) // => [1, 2]\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @returns {Function}\n */\n function binary (fn) {\n return function (a, b) {\n return fn.call(this, a, b);\n };\n }\n\n /**\n * Accepts a series of functions and builds a new function. The functions in the series\n * will then be applied, in order, with the values received by the function built with\n * collect.
\n * The collected results will be returned in an array.\n * @example\n * var user = {\n * id: \"jdoe\",\n * name: \"John\",\n * surname: \"Doe\",\n * scores: [2, 4, 7]\n * };\n * var getIDAndLastScore = _.collect(_.getKey(\"id\"), _.getPath(\"scores.-1\"));\n *\n * getIDAndLastScore(user) // => [\"jdoe\", 7]\n *\n * @example\n * var minAndMax = _.collect(Math.min, Math.max);\n *\n * minAndMax(3, 1, -2, 5, 4, -1) // => [-2, 5]\n *\n * @memberof module:lamb\n * @category Function\n * @param {...Function} fn\n * @returns {Function}\n */\n function collect () {\n var functions = list.apply(null, arguments);\n\n return function () {\n return map(functions, applyArgs(arguments));\n };\n }\n\n /**\n * Transforms the evaluation of the given function in the evaluation of a sequence of functions\n * expecting only one argument. Each function of the sequence is a partial application of the\n * original one, which will be applied when the specified (or derived) arity is consumed.
\n * Currying will start from the leftmost argument: use {@link module:lamb.curryRight|curryRight}\n * for right currying.\n * @example\n * var multiplyBy = _.curry(_.multiply);\n * var multiplyBy10 = multiplyBy(10);\n *\n * multiplyBy10(5) // => 50\n * multiplyBy10(2) // => 20\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}\n * @see {@link module:lamb.partial|partial}, {@link module:lamb.asPartial|asPartial}\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @returns {Function}\n */\n function curry (fn, arity) {\n return _curry(fn, arity, false);\n }\n\n /**\n * Builds an auto-curried function. The resulting function can be called multiple times with\n * any number of arguments, and the original function will be applied only when the specified\n * (or derived) arity is consumed.
\n * Currying will start from the leftmost argument: use {@link module:lamb.curryableRight|curryableRight}\n * for right currying.\n * @example\n * var collectFourElements = _.curryable(_.list, 4);\n *\n * collectFourElements(2)(3)(4)(5) // => [2, 3, 4, 5]\n * collectFourElements(2)(3, 4)(5) // => [2, 3, 4, 5]\n * collectFourElements(2, 3, 4, 5) // => [2, 3, 4, 5]\n * collectFourElements(2, 3)(4, 5) // => [2, 3, 4, 5]\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.curryableRight|curryableRight}\n * @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.partial|partial}, {@link module:lamb.asPartial|asPartial}\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @returns {Function}\n */\n function curryable (fn, arity) {\n return _curry(fn, arity, false, true);\n }\n\n /**\n * Same as {@link module:lamb.curryable|curryable}, but currying starts from the rightmost argument.\n * @example\n * var collectFourElements = _.curryableRight(_.list, 4);\n *\n * collectFourElements(2)(3)(4)(5) // => [5, 4, 3, 2]\n * collectFourElements(2)(3, 4)(5) // => [5, 4, 3, 2]\n * collectFourElements(2, 3, 4, 5) // => [5, 4, 3, 2]\n * collectFourElements(2, 3)(4, 5) // => [5, 4, 3, 2]\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.curryable|curryable}\n * @see {@link module:lamb.curry|curry}, {@link module:lamb.curryRight|curryRight}\n * @see {@link module:lamb.partial|partial}, {@link module:lamb.asPartial|asPartial}\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @returns {Function}\n */\n function curryableRight (fn, arity) {\n return _curry(fn, arity, true, true);\n }\n\n /**\n * Same as {@link module:lamb.curry|curry}, but currying starts from the rightmost argument.\n * @example\n * var divideBy = _.curryRight(_.divide);\n * var halve = divideBy(2);\n * halve(3) // => 1.5\n * halve(3, 7) // => 1.5\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.curry|curry}\n * @see {@link module:lamb.curryable|curryable}, {@link module:lamb.curryableRight|curryableRight}\n * @see {@link module:lamb.partial|partial}, {@link module:lamb.asPartial|asPartial}\n * @param {Function} fn\n * @param {Number} [arity=fn.length]\n * @returns {Function}\n */\n function curryRight (fn, arity) {\n return _curry(fn, arity, true);\n }\n\n /**\n * Returns a function that will execute the given function only if it stops being called for the\n * specified timespan.
\n * See also {@link module:lamb.throttle|throttle} for a different behaviour where the first call\n * happens immediately.\n * @example A common use case of debounce in a browser environment\n * var updateLayout = function () {\n * // some heavy DOM operations here\n * };\n *\n * window.addEventListener(\"resize\", _.debounce(updateLayout, 200), false);\n *\n * // The resize event is fired repeteadly until the user stops resizing the\n * // window, while the `updateLayout` function is called only once: 200 ms\n * // after he stopped.\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {Number} timespan - Expressed in milliseconds\n * @returns {Function}\n */\n function debounce (fn, timespan) {\n var timeoutID;\n\n return function () {\n var args = arguments;\n var debounced = function () {\n timeoutID = null;\n fn.apply(this, args);\n }.bind(this);\n\n clearTimeout(timeoutID);\n timeoutID = setTimeout(debounced, timespan);\n };\n }\n\n /**\n * Returns a function that applies its arguments to the original function in reverse order.\n * @example\n * _.list(1, 2, 3) // => [1, 2, 3]\n * _.flip(_.list)(1, 2, 3) // => [3, 2, 1]\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @returns {Function}\n */\n function flip (fn) {\n return function () {\n var args = list.apply(null, arguments).reverse();\n\n return fn.apply(this, args);\n };\n }\n\n /**\n * Builds a function that returns the argument received at the given index.
\n * As with {@link module:lamb.getAt|getAt} negative indexes are allowed.
\n * The resulting function will return undefined if no arguments are\n * passed or if the index is out of bounds.\n * @example\n * var getFirstArg = getArgAt(0);\n * var getLastArg = getArgAt(-1);\n *\n * getFirstArg(1, 2, 3) // => 1\n * getLastArg(1, 2, 3) // => 3\n *\n * getArgAt()(1, 2, 3) // => undefined\n * getArgAt(6)(1, 2, 3) // => undefined\n * getArgAt(1)() // => undefined\n *\n * @memberof module:lamb\n * @category Function\n * @param {Number} idx\n * @returns {Function}\n */\n function getArgAt (idx) {\n return function () {\n return arguments[_getNaturalIndex({length: arguments.length}, idx)];\n };\n }\n\n /**\n * Builds a function that will invoke the given method name on any received object and return\n * the result. If no method with such name is found the function will return undefined.\n * Along with the method name it's possible to supply some arguments that will be bound to the\n * method call.
\n * Further arguments can also be passed when the function is actually called, and they will be\n * concatenated to the bound ones.
\n * If different objects share a method name it's possible to build polymorphic functions as you\n * can see in the example below.
\n * {@link module:lamb.condition|Condition} can be used to wrap invoker to avoid this\n * behaviour by adding a predicate, while {@link module:lamb.adapter|adapter} can build more complex\n * polymorphic functions without the need of homonymy.
\n * Returning undefined or checking for such value is meant to favor composition and\n * interoperability between the aforementioned functions: for a more standard behaviour see also\n * {@link module:lamb.generic|generic}.\n * See also {@link module:lamb.invokerOn|invokerOn}.\n * @example Basic polymorphism with invoker\n * var polySlice = _.invoker(\"slice\");\n *\n * polySlice([1, 2, 3, 4, 5], 1, 3) // => [2, 3]\n * polySlice(\"Hello world\", 1, 3) // => \"el\"\n *\n * @example With bound arguments\n * var substrFrom2 = _.invoker(\"substr\", 2);\n * substrFrom2(\"Hello world\") // => \"llo world\"\n * substrFrom2(\"Hello world\", 5) // => \"llo w\"\n *\n * @memberof module:lamb\n * @category Function\n * @param {String} methodName\n * @param {...*} [boundArg]\n * @returns {Function}\n */\n function invoker (methodName) {\n return partial(_invoker, _argsTail.apply(null, arguments), methodName);\n }\n\n /**\n * Accepts an object and builds a function expecting a method name, and optionally arguments,\n * to call on such object.\n * Like {@link module:lamb.invoker|invoker}, if no method with the given name is found the\n * function will return undefined.\n * @example\n * var isEven = function (n) { return n % 2 === 0; };\n * var arr = [1, 2, 3, 4, 5];\n * var invokerOnArr = _.invokerOn(arr);\n *\n * invokerOnArr(\"filter\", isEven) // => [2, 4]\n * invokerOnArr(\"slice\", 1, 3) // => [2, 3]\n *\n * @memberof module:lamb\n * @category Function\n * @see {@link module:lamb.invoker|invoker}\n * @param {Object} target\n * @returns {Function}\n */\n function invokerOn (target) {\n return partial(_invoker, [], _, target);\n }\n\n /**\n * Builds a function that allows to map over the received arguments before applying them\n * to the original one.\n * @example\n * var sumArray = _.reduceWith(_.add);\n * var sum = _.compose(sumArray, _.list);\n *\n * sum(1, 2, 3, 4, 5) // => 15\n *\n * var square = _.partial(Math.pow, _, 2);\n * var sumSquares = _.mapArgs(sum, square);\n *\n * sumSquares(1, 2, 3, 4, 5) // => 55\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {ListIteratorCallback} mapper\n * @returns {Function}\n */\n function mapArgs (fn, mapper) {\n return compose(partial(apply, fn), mapWith(mapper), list);\n }\n\n /**\n * Creates a pipeline of functions, where each function consumes the result of the previous one.
\n * See also {@link module:lamb.compose|compose}.\n * @example\n * var square = _.partial(Math.pow, _, 2);\n * var getMaxAndSquare = _.pipe(Math.max, square);\n *\n * getMaxAndSquare(3, 5) // => 25\n *\n * @memberof module:lamb\n * @category Function\n * @function\n * @param {...Function} fn\n * @returns {Function}\n */\n var pipe = flip(compose);\n\n /**\n * Builds a function that allows to \"tap\" into the arguments of the original one.\n * This allows to extract simple values from complex ones, transform arguments or simply intercept them.\n * If a \"tapper\" isn't found the argument is passed as it is.\n * @example\n * var someObject = {count: 5};\n * var someArrayData = [2, 3, 123, 5, 6, 7, 54, 65, 76, 0];\n * var getDataAmount = _.tapArgs(_.add, _.getKey(\"count\"), _.getKey(\"length\"));\n *\n * getDataAmount(someObject, someArrayData); // => 15\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {...?Function} [tapper]\n * @returns {Function}\n */\n function tapArgs (fn) {\n var tappers = _argsTail.apply(null, arguments);\n\n return function () {\n var len = arguments.length;\n var tappersLen = tappers.length;\n var args = [];\n\n for (var i = 0; i < len; i++) {\n args.push(i < tappersLen ? tappers[i](arguments[i]) : arguments[i]);\n }\n\n return fn.apply(this, args);\n };\n }\n\n /**\n * Returns a function that will invoke the passed function at most once in the given timespan.
\n * The first call in this case happens as soon as the function is invoked; see also\n * {@link module:lamb.debounce|debounce} for a different behaviour where the first call is delayed.\n * @example\n * var log = _.throttle(console.log.bind(console), 5000);\n *\n * log(\"Hi\"); // console logs \"Hi\"\n * log(\"Hi again\"); // nothing happens\n * // after five seconds\n * log(\"Hello world\"); // console logs \"Hello world\"\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @param {Number} timespan - Expressed in milliseconds.\n * @returns {Function}\n */\n function throttle (fn, timespan) {\n var result;\n var lastCall = 0;\n\n return function () {\n var now = Date.now();\n\n if (now - lastCall >= timespan) {\n lastCall = now;\n result = fn.apply(this, arguments);\n }\n\n return result;\n };\n }\n\n /**\n * Builds a function that passes only one argument to the given function.
\n * It's simply a shortcut for a common use case of {@link module:lamb.aritize|aritize},\n * exposed for convenience.
\n * See also {@link module:lamb.binary|binary}.\n * @example\n * var weights = [\"2 Kg\", \"10 Kg\", \"1 Kg\", \"7 Kg\"];\n *\n * weights.map(_.unary(parseInt)) // => [2, 10, 1, 7]\n *\n * @memberof module:lamb\n * @category Function\n * @param {Function} fn\n * @returns {Function}\n */\n function unary (fn) {\n return function (a) {\n return fn.call(this, a);\n };\n }\n\n /**\n * Wraps the function fn inside a wrapper function.
\n * This allows to conditionally execute fn, to tamper with its arguments\n * or return value and to run code before and after its execution.
\n * Being this nothing more than a \"{@link module:lamb.flip|flipped}\"\n * [partial application]{@link module:lamb.partial}, you can also easily build new\n * functions from existent ones.\n * @example\n * var arrayMax = _.wrap(Math.max, _.apply);\n *\n * arrayMax([4, 5, 2, 6, 1]) // => 6\n *\n * @memberof module:lamb\n * @category Function\n * @function\n * @param {Function} fn\n * @param {Function} wrapper\n * @returns {Function}\n */\n var wrap = binary(flip(partial));\n\n lamb.apply = apply;\n lamb.applyArgs = applyArgs;\n lamb.aritize = aritize;\n lamb.asPartial = asPartial;\n lamb.binary = binary;\n lamb.collect = collect;\n lamb.curry = curry;\n lamb.curryRight = curryRight;\n lamb.curryable = curryable;\n lamb.curryableRight = curryableRight;\n lamb.debounce = debounce;\n lamb.flip = flip;\n lamb.getArgAt = getArgAt;\n lamb.invoker = invoker;\n lamb.invokerOn = invokerOn;\n lamb.mapArgs = mapArgs;\n lamb.pipe = pipe;\n lamb.tapArgs = tapArgs;\n lamb.throttle = throttle;\n lamb.unary = unary;\n lamb.wrap = wrap;\n\n /**\n * Builds a checker function meant to be used with\n * {@link module:lamb.validate|validate}.
\n * Note that the function accepts multiple keyPaths as a means to\n * compare their values. In other words all the received keyPaths will be\n * passed as arguments to the predicate to run the test.
\n * If you want to run the same single property check with multiple properties, you should build\n * multiple checkers and combine them with {@link module:lamb.validate|validate}.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * login: {\n * username: \"jdoe\",\n * password: \"abc123\",\n * passwordConfirm: \"abc123\"\n * }\n * };\n * var pwdMatch = _.checker(\n * _.is,\n * \"Passwords don't match\",\n * [\"login.password\", \"login.passwordConfirm\"]\n * );\n *\n * pwdMatch(user) // => []\n *\n * var newUser = _.setPathIn(user, \"login.passwordConfirm\", \"avc123\");\n *\n * pwdMatch(newUser) // => [\"Passwords don't match\", [\"login.password\", \"login.passwordConfirm\"]]\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.validate|validate}, {@link module:lamb.validateWith|validateWith}\n * @param {Function} predicate - The predicate to test the object properties\n * @param {String} message - The error message\n * @param {String[]} keyPaths - The array of keys, or {@link module:lamb.getPathIn|paths}, to test.\n * @param {String} [pathSeparator=\".\"]\n * @returns {Function} A checker function which returns an error in the form\n * [\"message\", [\"propertyA\", \"propertyB\"]] or an empty array.\n */\n function checker (predicate, message, keyPaths, pathSeparator) {\n return function (obj) {\n var getValues = partial(getPathIn, obj, _, pathSeparator);\n\n return predicate.apply(obj, map(keyPaths, getValues)) ? [] : [message, keyPaths];\n };\n }\n\n /**\n * Creates an array with all the enumerable properties of the given object.\n * @example Showing the difference with {@link module:lamb.keys|keys}\n * var baseFoo = Object.create({a: 1}, {b: {value: 2}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3},\n * d: {value: 4, enumerable: true}\n * });\n *\n * _.keys(foo) // => [\"d\"]\n * _.enumerables(foo) // => [\"d\", \"a\"]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.keys|keys}\n * @param {Object} obj\n * @returns {String[]}\n */\n var enumerables = _unsafeKeyListFrom(_safeEnumerables);\n\n /**\n * Builds an object from a list of key / value pairs like the one\n * returned by [pairs]{@link module:lamb.pairs} or {@link module:lamb.ownPairs|ownPairs}.
\n * In case of duplicate keys the last key / value pair is used.\n * @example\n * _.fromPairs([[\"a\", 1], [\"b\", 2], [\"c\", 3]]) // => {\"a\": 1, \"b\": 2, \"c\": 3}\n * _.fromPairs([[\"a\", 1], [\"b\", 2], [\"a\", 3]]) // => {\"a\": 3, \"b\": 2}\n * _.fromPairs([[1], [void 0, 2], [null, 3]]) // => {\"1\": undefined, \"undefined\": 2, \"null\": 3}\n *\n * @memberof module:lamb\n * @category Object\n * @param {Array>} pairsList\n * @returns {Object}\n */\n function fromPairs (pairsList) {\n var result = {};\n\n forEach(pairsList, function (pair) {\n result[pair[0]] = pair[1];\n });\n\n return result;\n }\n\n /**\n * Verifies the existence of a property in an object.\n * @example\n * var user1 = {name: \"john\"};\n *\n * _.has(user1, \"name\") // => true\n * _.has(user1, \"surname\") // => false\n * _.has(user1, \"toString\") // => true\n *\n * var user2 = Object.create(null);\n *\n * // not inherited through the prototype chain\n * _.has(user2, \"toString\") // => false\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.hasKey|hasKey}\n * @see {@link module:lamb.hasOwn|hasOwn}, {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}, {@link module:lamb.pathExists|pathExists}\n * @param {Object} obj\n * @param {String} key\n * @returns {Boolean}\n */\n function has (obj, key) {\n if (typeof obj !== \"object\" && !isUndefined(obj)) {\n obj = Object(obj);\n }\n\n return key in obj;\n }\n\n /**\n * Curried version of {@link module:lamb.has|has}.
\n * Returns a function expecting the object to check against the given key.\n * @example\n * var user1 = {name: \"john\"};\n * var user2 = {};\n * var hasName = _.hasKey(\"name\");\n *\n * hasName(user1) // => true\n * hasName(user2) // => false\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.has|has}\n * @see {@link module:lamb.hasOwn|hasOwn}, {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}, {@link module:lamb.pathExists|pathExists}\n * @param {String} key\n * @returns {Function}\n */\n function hasKey (key) {\n return function (obj) {\n return has(obj, key);\n };\n }\n\n /**\n * Builds a predicate expecting an object to check against the given key / value pair.
\n * The value check is made with the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.\n * @example\n * var hasTheCorrectAnswer = _.hasKeyValue(\"answer\", 42);\n *\n * hasTheCorrectAnswer({answer: 2}) // false\n * hasTheCorrectAnswer({answer: 42}) // true\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.hasPathValue|hasPathValue}\n * @param {String} key\n * @param {*} value\n * @returns {Function}\n */\n function hasKeyValue (key, value) {\n return function (obj) {\n return isSVZ(value, obj[key]);\n };\n }\n\n /**\n * Verifies if an object has the specified property and that the property isn't inherited through\n * the prototype chain.
\n * @example Comparison with has.\n * var user = {name: \"john\"};\n *\n * _.has(user, \"name\") // => true\n * _.has(user, \"surname\") // => false\n * _.has(user, \"toString\") // => true\n *\n * _.hasOwn(user, \"name\") // => true\n * _.hasOwn(user, \"surname\") // => false\n * _.hasOwn(user, \"toString\") // => false\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.has|has}, {@link module:lamb.hasKey|hasKey}\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}, {@link module:lamb.pathExists|pathExists}\n * @param {Object} obj\n * @param {String} key\n * @returns {Boolean}\n */\n var hasOwn = generic(_objectProto.hasOwnProperty);\n\n /**\n * Curried version of {@link module:lamb.hasOwn|hasOwn}.
\n * Returns a function expecting the object to check against the given key.\n * @example\n * var user = {name: \"john\"};\n * var hasOwnName = _.hasOwnKey(\"name\");\n * var hasOwnToString = _.hasOwnToString(\"toString\");\n *\n * hasOwnName(user) // => true\n * hasOwnToString(user) // => false\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.hasOwn|hasOwn}\n * @see {@link module:lamb.has|has}, {@link module:lamb.hasKey|hasKey}\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}, {@link module:lamb.pathExists|pathExists}\n * @param {String} key\n * @returns {Function}\n */\n function hasOwnKey (key) {\n return function (obj) {\n return hasOwn(obj, key);\n };\n }\n\n /**\n * Builds a predicate to check if the given path exists in an object and holds the desired value.
\n * The value check is made with the [\"SameValueZero\" comparison]{@link module:lamb.isSVZ|isSVZ}.
\n * Note that the function will check even non-enumerable properties.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * personal: {\n * age: 25,\n * gender: \"M\"\n * },\n * scores: [\n * {id: 1, value: 10, passed: false},\n * {id: 2, value: 20, passed: false},\n * {id: 3, value: 30, passed: true}\n * ]\n * };\n *\n * var isMale = _.hasPathValue(\"personal.gender\", \"M\");\n * var hasPassedFirstTest = _.hasPathValue(\"scores.0.passed\", true);\n * var hasPassedLastTest = _.hasPathValue(\"scores.-1.passed\", true);\n *\n * isMale(user) // => true\n * hasPassedFirstTest(user) // => false\n * hasPassedLastTest(user) // => true\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.hasKeyValue|hasKeyValue}\n * @param {String} path\n * @param {*} value\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function hasPathValue (path, value, separator) {\n return function (obj) {\n var pathInfo = _getPathInfo(obj, _toPathParts(path, separator), true);\n\n return pathInfo.isValid && isSVZ(pathInfo.target, value);\n };\n }\n\n /**\n * Makes an object immutable by recursively calling [Object.freeze]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze}\n * on its members.
\n * Any attempt to extend or modify the object can throw a TypeError or fail silently,\n * depending on the environment and the [strict mode]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode} directive.\n * @example\n * var user = _.immutable({\n * name: \"John\",\n * surname: \"Doe\",\n * login: {\n * username: \"jdoe\",\n * password: \"abc123\"\n * },\n * luckyNumbers: [13, 17]\n * });\n *\n * // All of these statements will fail and possibly\n * // throw a TypeError (see the function description)\n * user.name = \"Joe\";\n * delete user.name;\n * user.newProperty = [];\n * user.login.password = \"foo\";\n * user.luckyNumbers.push(-13);\n *\n * @memberof module:lamb\n * @category Object\n * @param {Object} obj\n * @returns {Object}\n */\n function immutable (obj) {\n return _immutable(obj, []);\n }\n\n /**\n * Retrieves the list of the own enumerable properties of an object.
\n * Although [Object.keys]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys}\n * is already present in ECMAScript 5, its behaviour changed in the subsequent specifications\n * of the standard.
\n * This function shims the ECMAScript 6 version, by forcing a conversion to\n * object for any value but null and undefined.\n * @example Showing the difference with {@link module:lamb.enumerables|enumerables}\n * var baseFoo = Object.create({a: 1}, {b: {value: 2}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3},\n * d: {value: 4, enumerable: true}\n * });\n *\n * _.enumerables(foo) // => [\"d\", \"a\"]\n * _.keys(foo) // => [\"d\"]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.enumerables|enumerables}\n * @param {Object} obj\n * @returns {String[]}\n */\n var keys = _unsafeKeyListFrom(_safeKeys);\n\n /**\n * Builds an object from the two given lists, using the first one as keys and the last\n * one as values.
\n * If the list of keys is longer than the values one, the keys will be created with\n * undefined values.
\n * If more values than keys are supplied, the extra values will be ignored.
\n * See also {@link module:lamb.tear|tear} and {@link module:lamb.tearOwn|tearOwn} for\n * the reverse operation.\n * @example\n * _.make([\"a\", \"b\", \"c\"], [1, 2, 3]) // => {a: 1, b: 2, c: 3}\n * _.make([\"a\", \"b\", \"c\"], [1, 2]) // => {a: 1, b: 2, c: undefined}\n * _.make([\"a\", \"b\"], [1, 2, 3]) // => {a: 1, b: 2}\n * _.make([null, void 0, 2], [1, 2, 3]) // => {\"null\": 1, \"undefined\": 2, \"2\": 3}\n *\n * @memberof module:lamb\n * @category Object\n * @param {String[]} names\n * @param {ArrayLike} values\n * @returns {Object}\n */\n function make (names, values) {\n var result = {};\n var valuesLen = values.length;\n\n for (var i = 0, len = names.length; i < len; i++) {\n result[names[i]] = i < valuesLen ? values[i] : void 0;\n }\n\n return result;\n }\n\n /**\n * Merges the enumerable properties of the provided sources into a new object.
\n * In case of key homonymy each source has precedence over the previous one.
\n * See also {@link module:lamb.mergeOwn|mergeOwn} for merging only own properties of\n * the given sources.\n * @example\n * _.merge({a: 1}, {b: 3, c: 4}, {b: 5}) // => {a: 1, b: 5, c: 4}\n *\n * @example Array-like objects will be transformed to objects with numbers as keys:\n * _.merge([1, 2], {a: 2}) // => {\"0\": 1, \"1\": 2, a: 2}\n * _.merge(\"foo\", {a: 2}) // => {\"0\": \"f\", \"1\": \"o\", \"2\": \"o\", a: 2}\n *\n * @example Every other value will be treated as an empty object:\n * _.merge({a: 2}, null, NaN) // => {a: 2}\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {...Object} source\n * @returns {Object}\n */\n var merge = partial(_merge, _safeEnumerables);\n\n /**\n * Same as {@link module:lamb.merge|merge}, but only the own properties of the\n * sources are taken into account.\n * @example showing the difference with merge:\n * var baseFoo = Object.create({a: 1}, {b: {value: 2, enumerable: true}, z: {value: 5}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3, enumerable: true}\n * });\n *\n * var bar = {d: 4};\n *\n * _.merge(foo, bar) // => {a: 1, b: 2, c: 3, d: 4}\n * _.mergeOwn(foo, bar) // => {c: 3, d: 4}\n *\n * @example Array-like objects will be transformed to objects with numbers as keys:\n * _.mergeOwn([1, 2], {a: 2}) // => {\"0\": 1, \"1\": 2, a: 2}\n * _.mergeOwn(\"foo\", {a: 2}) // => {\"0\": \"f\", \"1\": \"o\", \"2\": \"o\", a: 2}\n *\n * @example Every other value will be treated as an empty object:\n * _.mergeOwn({a: 2}, null, NaN) // => {a: 2}\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {...Object} source\n * @returns {Object}\n */\n var mergeOwn = partial(_merge, _safeKeys);\n\n /**\n * Same as {@link module:lamb.pairs|pairs}, but only the own enumerable properties of the object are\n * taken into account.
\n * See also {@link module:lamb.fromPairs|fromPairs} for the reverse operation.\n * @example showing the difference with pairs\n * var baseFoo = Object.create({a: 1}, {b: {value: 2, enumerable: true}, z: {value: 5}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3, enumerable: true}\n * });\n *\n * _.pairs(foo) // => [[\"c\", 3], [\"b\", 2], [\"a\", 1]]\n * _.ownPairs(foo) // => [[\"c\", 3]]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array>}\n */\n var ownPairs = _pairsFrom(keys);\n\n /**\n * Same as {@link module:lamb.values|values}, but only the own enumerable properties of the object are\n * taken into account.
\n * @example showing the difference with values\n * var baseFoo = Object.create({a: 1}, {b: {value: 2, enumerable: true}, z: {value: 5}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3, enumerable: true}\n * });\n *\n * _.values(foo) // => [3, 2, 1]\n * _.ownValues(foo) // => [3]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array}\n */\n var ownValues = _valuesFrom(keys);\n\n /**\n * Converts an object into an array of key / value pairs of its enumerable properties.
\n * See also {@link module:lamb.ownPairs|ownPairs} for picking only the own enumerable\n * properties and {@link module:lamb.fromPairs|fromPairs} for the reverse operation.\n * @example\n * _.pairs({a: 1, b: 2, c: 3}) // => [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array>}\n */\n var pairs = _pairsFrom(enumerables);\n\n /**\n * Builds a partial application of {@link module:lamb.pathExistsIn|pathExistsIn} using the given\n * path and the optional separator. The resulting function expects the object to check.
\n * Note that the function will check even non-enumerable properties.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * address: {\n * city: \"New York\"\n * },\n * scores: [10, 20, 15]\n * };\n *\n * var hasCity = _.pathExists(\"address.city\");\n * var hasCountry = _.pathExists(\"address.country\");\n * var hasAtLeastThreeScores = _.pathExists(\"scores.2\");\n *\n * hasCity(user) // => true\n * hasCountry(user) // => false\n * hasAtLeastThreeScores(user) // => true\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.pathExistsIn|pathExistsIn}\n * @see {@link module:lamb.hasOwn|hasOwn}, {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.has|has}, {@link module:lamb.hasKey|hasKey}\n * @param {String} path\n * @param {String} [separator=\".\"]\n * @returns {Function}\n */\n function pathExists (path, separator) {\n return function (obj) {\n return pathExistsIn(obj, path, separator);\n };\n }\n\n /**\n * Checks if the provided path exists in the given object.
\n * Note that the function will check even non-enumerable properties.\n * @example\n * var user = {\n * name: \"John\",\n * surname: \"Doe\",\n * address: {\n * city: \"New York\"\n * },\n * scores: [10, 20, 15]\n * };\n *\n * _.pathExistsIn(user, \"address.city\") // => true\n * _.pathExistsIn(user, \"address.country\") // => false\n * _.pathExistsIn(user, \"scores.1\") // => true\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.pathExists|pathExists}\n * @see {@link module:lamb.hasOwn|hasOwn}, {@link module:lamb.hasOwnKey|hasOwnKey}\n * @see {@link module:lamb.has|has}, {@link module:lamb.hasKey|hasKey}\n * @param {Object} obj\n * @param {String} path\n * @param {String} [separator=\".\"]\n * @returns {Boolean}\n */\n function pathExistsIn (obj, path, separator) {\n var pathInfo = _getPathInfo(obj, _toPathParts(path, separator), true);\n\n return pathInfo.isValid;\n }\n\n /**\n * Returns an object containing only the specified properties of the given object.
\n * Non existent properties will be ignored.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n *\n * _.pick(user, [\"name\", \"age\"]) // => {\"name\": \"john\", \"age\": 30};\n * _.pick(user, [\"name\", \"email\"]) // => {\"name\": \"john\"}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.pickIf|pickIf}, {@link module:lamb.pickKeys|pickKeys}\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipIf|skipIf}\n * @param {Object} source\n * @param {String[]} whitelist\n * @returns {Object}\n */\n function pick (source, whitelist) {\n var result = {};\n\n forEach(whitelist, function (key) {\n if (has(source, key)) {\n result[key] = source[key];\n }\n });\n\n return result;\n }\n\n /**\n * Builds a function expecting an object whose enumerable properties will be checked\n * against the given predicate.
\n * The properties satisfying the predicate will be included in the resulting object.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n * var pickIfIsString = _.pickIf(_.isType(\"String\"));\n *\n * pickIfIsString(user) // => {name: \"john\", surname: \"doe\"}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickKeys|pickKeys}\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipKeys|skipKeys},\n * {@link module:lamb.skipIf|skipIf}\n * @param {ObjectIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n function pickIf (predicate, predicateContext) {\n if (arguments.length === 2) {\n predicate = predicate.bind(predicateContext);\n }\n\n return function (source) {\n var result = {};\n\n forEach(enumerables(source), function (key) {\n if (predicate(source[key], key, source)) {\n result[key] = source[key];\n }\n });\n\n return result;\n };\n }\n\n /**\n * A curried version of {@link module:lamb.pick|pick}, expecting a whitelist of keys to build\n * a function waiting for the object to act upon.\n * @example\n * var user = {id: 1, name: \"Jane\", surname: \"Doe\", active: false};\n * var getUserInfo = _.pickKeys([\"id\", \"active\"]);\n *\n * getUserInfo(user) // => {id: 1, active: false}\n *\n * @example A useful composition with mapWith:\n * var users = [\n * {id: 1, name: \"Jane\", surname: \"Doe\", active: false},\n * {id: 2, name: \"John\", surname: \"Doe\", active: true},\n * {id: 3, name: \"Mario\", surname: \"Rossi\", active: true},\n * {id: 4, name: \"Paolo\", surname: \"Bianchi\", active: false}\n * ];\n * var select = _.compose(_.mapWith, _.pickKeys);\n * var selectUserInfo = select([\"id\", \"active\"]);\n *\n * selectUserInfo(users) // =>\n * // [\n * // {id: 1, active: false},\n * // {id: 2, active: true},\n * // {id: 3, active: true},\n * // {id: 4, active: false}\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickIf|pickIf}\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipKeys|skipKeys},\n * {@link module:lamb.skipIf|skipIf}\n * @param {String[]} whitelist\n * @returns {Function}\n */\n var pickKeys = _curry(pick, 2, true);\n\n /**\n * Creates a copy of the given object with its enumerable keys renamed as\n * indicated in the provided lookup table.\n * @example\n * var person = {\"firstName\": \"John\", \"lastName\": \"Doe\"};\n * var keysMap = {\"firstName\": \"name\", \"lastName\": \"surname\"};\n *\n * _.rename(person, keysMap) // => {\"name\": \"John\", \"surname\": \"Doe\"}\n *\n * @example It's safe using it to swap keys:\n * var keysMap = {\"firstName\": \"lastName\", \"lastName\": \"firstName\"};\n *\n * _.rename(person, keysMap) // => {\"lastName\": \"John\", \"firstName\": \"Doe\"}\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.renameKeys|renameKeys}, {@link module:lamb.renameWith|renameWith}\n * @param {Object} source\n * @param {Object} keysMap\n * @returns {Object}\n */\n function rename (source, keysMap) {\n keysMap = Object(keysMap);\n var result = {};\n var oldKeys = enumerables(source);\n\n for (var prop in keysMap) {\n if (~oldKeys.indexOf(prop)) {\n result[keysMap[prop]] = source[prop];\n }\n }\n\n for (var i = 0, len = oldKeys.length, key; i < len; i++) {\n key = oldKeys[i];\n\n if (!(key in keysMap || key in result)) {\n result[key] = source[key];\n }\n }\n\n return result;\n }\n\n /**\n * A curried version of {@link module:lamb.rename|rename} expecting a\n * keysMap to build a function waiting for the object to act upon.\n * @example\n * var persons = [\n * {\"firstName\": \"John\", \"lastName\": \"Doe\"},\n * {\"first_name\": \"Mario\", \"last_name\": \"Rossi\"},\n * ];\n * var normalizeKeys = _.renameKeys({\n * \"firstName\": \"name\",\n * \"first_name\": \"name\",\n * \"lastName\": \"surname\",\n * \"last_name\": \"surname\"\n * });\n *\n * persons.map(normalizeKeys) // =>\n * // [\n * // {\"name\": \"John\", \"surname\": \"Doe\"},\n * // {\"name\": \"Mario\", \"surname\": \"Rossi\"}\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.rename|rename}, {@link module:lamb.renameWith|renameWith}\n * @param {Object} keysMap\n * @returns {Function}\n */\n var renameKeys = _curry(rename, 2, true);\n\n /**\n * Uses the provided function as a keysMap generator and returns\n * a function expecting the object whose keys we want to {@link module:lamb.rename|rename}.\n * @example\n * var person = {\"NAME\": \"John\", \"SURNAME\": \"Doe\"};\n * var makeLowerKeysMap = function (source) {\n * var sourceKeys = _.keys(source);\n * return _.make(sourceKeys, sourceKeys.map(_.invoker(\"toLowerCase\")));\n * };\n * var lowerKeysFor = _.renameWith(makeLowerKeysMap);\n *\n * lowerKeysFor(person) // => {\"name\": \"John\", \"surname\": \"doe\"};\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.rename|rename}, {@link module:lamb.renameKeys|renameKeys}\n * @param {Function} fn\n * @returns {Function}\n */\n function renameWith (fn) {\n return function (source) {\n return rename(source, fn(source));\n };\n }\n\n /**\n * Returns a copy of the source object without the specified properties.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n *\n * _.skip(user, [\"name\", \"age\"]) // => {surname: \"doe\"};\n * _.skip(user, [\"name\", \"email\"]) // => {surname: \"doe\", age: 30};\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.skipKeys|skipKeys}, {@link module:lamb.skipIf|skipIf}\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickKeys|pickKeys},\n * {@link module:lamb.pickIf|pickIf}\n * @param {Object} source\n * @param {String[]} blacklist\n * @returns {Object}\n */\n function skip (source, blacklist) {\n var result = {};\n\n forEach(enumerables(source), function (key) {\n if (!isIn(blacklist, key)) {\n result[key] = source[key];\n }\n });\n\n return result;\n }\n\n /**\n * Builds a function expecting an object whose enumerable properties will be checked\n * against the given predicate.
\n * The properties satisfying the predicate will be omitted in the resulting object.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n * var skipIfIstring = _.skipIf(_.isType(\"String\"));\n *\n * skipIfIstring(user) // => {age: 30}\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipKeys|skipKeys}\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickKeys|pickKeys},\n * {@link module:lamb.pickIf|pickIf}\n * @param {ObjectIteratorCallback} predicate\n * @param {Object} [predicateContext]\n * @returns {Function}\n */\n var skipIf = tapArgs(pickIf, not);\n\n /**\n * A curried version of {@link module:lamb.skip|skip}, expecting a blacklist of keys to build\n * a function waiting for the object to act upon.\n * @example\n * var user = {id: 1, name: \"Jane\", surname: \"Doe\", active: false};\n * var getUserInfo = _.skipKeys([\"name\", \"surname\"]);\n *\n * getUserInfo(user) // => {id: 1, active: false}\n *\n * @example A useful composition with mapWith:\n * var users = [\n * {id: 1, name: \"Jane\", surname: \"Doe\", active: false},\n * {id: 2, name: \"John\", surname: \"Doe\", active: true},\n * {id: 3, name: \"Mario\", surname: \"Rossi\", active: true},\n * {id: 4, name: \"Paolo\", surname: \"Bianchi\", active: false}\n * ];\n * var discard = _.compose(_.mapWith, _.skipKeys);\n * var discardNames = discard([\"name\", \"surname\"]);\n *\n * discardNames(users) // =>\n * // [\n * // {id: 1, active: false},\n * // {id: 2, active: true},\n * // {id: 3, active: true},\n * // {id: 4, active: false}\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @see {@link module:lamb.skip|skip}, {@link module:lamb.skipIf|skipIf}\n * @see {@link module:lamb.pick|pick}, {@link module:lamb.pickKeys|pickKeys},\n * {@link module:lamb.pickIf|pickIf}\n * @param {String[]} blacklist\n * @returns {Function}\n */\n var skipKeys = _curry(skip, 2, true);\n\n /**\n * Tears an object apart by transforming it in an array of two lists: one containing\n * its enumerable keys, the other containing the corresponding values.
\n * Although this \"tearing apart\" may sound as a rather violent process, the source\n * object will be unharmed.
\n * See also {@link module:lamb.tearOwn|tearOwn} for picking only the own enumerable properties and\n * {@link module:lamb.make|make} for the reverse operation.\n * @example\n * _.tear({a: 1, b: 2, c: 3}) // => [[\"a\", \"b\", \"c\"], [1, 2, 3]]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array, Array<*>>}\n */\n var tear = _tearFrom(enumerables);\n\n /**\n * Same as {@link module:lamb.tear|tear}, but only the own properties of the object are\n * taken into account.
\n * See also {@link module:lamb.make|make} for the reverse operation.\n * @example showing the difference with tear\n * var baseFoo = Object.create({a: 1}, {b: {value: 2, enumerable: true}, z: {value: 5}});\n * var foo = Object.create(baseFoo, {\n * c: {value: 3, enumerable: true}\n * });\n *\n * _.tear(foo) // => [[\"c\", \"b\", \"a\"], [3, 2, 1]]\n * _.tearOwn(foo) // => [[\"c\"], [3]]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array, Array<*>>}\n */\n var tearOwn = _tearFrom(keys);\n\n /**\n * Validates an object with the given list of {@link module:lamb.checker|checker} functions.\n * @example\n * var hasContent = function (s) { return s.trim().length > 0; };\n * var isAdult = function (age) { return age >= 18; };\n * var userCheckers = [\n * _.checker(hasContent, \"Name is required\", [\"name\"]),\n * _.checker(hasContent, \"Surname is required\", [\"surname\"]),\n * _.checker(isAdult, \"Must be at least 18 years old\", [\"age\"])\n * ];\n *\n * var user1 = {name: \"john\", surname: \"doe\", age: 30};\n * var user2 = {name: \"jane\", surname: \"\", age: 15};\n *\n * _.validate(user1, userCheckers) // => []\n * _.validate(user2, userCheckers) // =>\n * // [\n * // [\"Surname is required\", [\"surname\"]],\n * // [\"Must be at least 18 years old\", [\"age\"]]\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.validateWith|validateWith}\n * @see {@link module:lamb.checker|checker}\n * @param {Object} obj\n * @param {Function[]} checkers\n * @returns {Array>} An array of errors in the form returned by\n * {@link module:lamb.checker|checker}, or an empty array.\n */\n function validate (obj, checkers) {\n return reduce(checkers, function (errors, _checker) {\n var result = _checker(obj);\n\n result.length && errors.push(result);\n\n return errors;\n }, []);\n }\n\n /**\n * A curried version of {@link module:lamb.validate|validate} accepting a list of\n * {@link module:lamb.checker|checkers} and returning a function expecting the object to validate.\n * @example\n * var hasContent = function (s) { return s.trim().length > 0; };\n * var isAdult = function (age) { return age >= 18; };\n * var userCheckers = [\n * _.checker(hasContent, \"Name is required\", [\"name\"]),\n * _.checker(hasContent, \"Surname is required\", [\"surname\"]),\n * _.checker(isAdult, \"Must be at least 18 years old\", [\"age\"])\n * ];\n * var validateUser = _.validateWith(userCheckers);\n *\n * var user1 = {name: \"john\", surname: \"doe\", age: 30};\n * var user2 = {name: \"jane\", surname: \"\", age: 15};\n *\n * validateUser(user1) // => []\n * validateUser(user2) // =>\n * // [\n * // [\"Surname is required\", [\"surname\"]],\n * // [\"Must be at least 18 years old\", [\"age\"]]\n * // ]\n *\n * @memberof module:lamb\n * @category Object\n * @see {@link module:lamb.validate|validate}\n * @see {@link module:lamb.checker|checker}\n * @function\n * @param {Function[]} checkers\n * @returns {Function}\n */\n var validateWith = _curry(validate, 2, true);\n\n /**\n * Generates an array with the values of the enumerable properties of the given object.
\n * See also {@link module:lamb.ownValues|ownValues} for picking only the own properties of the object.\n * @example\n * var user = {name: \"john\", surname: \"doe\", age: 30};\n *\n * _.values(user) // => [\"john\", \"doe\", 30]\n *\n * @memberof module:lamb\n * @category Object\n * @function\n * @param {Object} obj\n * @returns {Array}\n */\n var values = _valuesFrom(enumerables);\n\n lamb.checker = checker;\n lamb.enumerables = enumerables;\n lamb.fromPairs = fromPairs;\n lamb.has = has;\n lamb.hasKey = hasKey;\n lamb.hasKeyValue = hasKeyValue;\n lamb.hasOwn = hasOwn;\n lamb.hasOwnKey = hasOwnKey;\n lamb.hasPathValue = hasPathValue;\n lamb.immutable = immutable;\n lamb.keys = keys;\n lamb.make = make;\n lamb.merge = merge;\n lamb.mergeOwn = mergeOwn;\n lamb.ownPairs = ownPairs;\n lamb.ownValues = ownValues;\n lamb.pairs = pairs;\n lamb.pathExists = pathExists;\n lamb.pathExistsIn = pathExistsIn;\n lamb.pick = pick;\n lamb.pickIf = pickIf;\n lamb.pickKeys = pickKeys;\n lamb.rename = rename;\n lamb.renameKeys = renameKeys;\n lamb.renameWith = renameWith;\n lamb.skip = skip;\n lamb.skipIf = skipIf;\n lamb.skipKeys = skipKeys;\n lamb.tear = tear;\n lamb.tearOwn = tearOwn;\n lamb.validate = validate;\n lamb.validateWith = validateWith;\n lamb.values = values;\n\n /**\n * Pads a string to the desired length with the given char starting from the beginning of the string.\n * @example\n * _.padLeft(\"foo\", \"-\", 0) // => \"foo\"\n * _.padLeft(\"foo\", \"-\", -1) // => \"foo\"\n * _.padLeft(\"foo\", \"-\", 5) // => \"--foo\"\n * _.padLeft(\"foo\", \"-\", 3) // => \"foo\"\n * _.padLeft(\"foo\", \"ab\", 7) // => \"aaaafoo\"\n * _.padLeft(\"foo\", \"\", 5) // => \" foo\"\n * _.padLeft(\"\", \"-\", 5) // => \"-----\"\n *\n * @memberof module:lamb\n * @category String\n * @param {String} source\n * @param {String} [char=\" \"] - The padding char. If a string is passed only the first char is used.\n * @param {Number} len\n * @returns {String}\n */\n function padLeft (source, char, len) {\n return _getPadding(source, char, len) + source;\n }\n\n /**\n * Pads a string to the desired length with the given char starting from the end of the string.\n * @example\n * _.padRight(\"foo\", \"-\", 0) // => \"foo\"\n * _.padRight(\"foo\", \"-\", -1) // => \"foo\"\n * _.padRight(\"foo\", \"-\", 5) // => \"foo--\"\n * _.padRight(\"foo\", \"-\", 3) // => \"foo\"\n * _.padRight(\"foo\", \"ab\", 7) // => \"fooaaaa\"\n * _.padRight(\"foo\", \"\", 5) // => \"foo \"\n * _.padRight(\"\", \"-\", 5) // => \"-----\"\n *\n * @memberof module:lamb\n * @category String\n * @param {String} source\n * @param {String} [char=\" \"] - The padding char. If a string is passed only the first char is used.\n * @param {Number} len\n * @returns {String}\n */\n function padRight (source, char, len) {\n return source + _getPadding(source, char, len);\n }\n\n /**\n * Builds a new string by repeating the source string the desired amount of times.
\n * Note that unlike the current ES6 proposal for\n * [String.prototype.repeat]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat},\n * this function doesn't throw a RangeError if times is negative,\n * but returns an empty string instead.\n * @example\n * _.repeat(\"Hello\", -1) // => \"\"\n * _.repeat(\"Hello\", 1) // => \"Hello\"\n * _.repeat(\"Hello\", 3) // => \"HelloHelloHello\"\n *\n * @memberof module:lamb\n * @category String\n * @param {String} source\n * @param {Number} times\n * @returns {String}\n */\n function repeat (source, times) {\n var result = \"\";\n\n for (var i = 0; i < times; i++) {\n result += source;\n }\n\n return result;\n }\n\n /**\n * Builds a predicate expecting a string to test against the given regular expression pattern.\n * @example\n * var hasNumbersOnly = _.testWith(/^\\d+$/);\n *\n * hasNumbersOnly(\"123\") // => true\n * hasNumbersOnly(\"123 Kg\") // => false\n *\n * @memberof module:lamb\n * @category String\n * @param {RegExp} pattern\n * @returns {Function}\n */\n function testWith (pattern) {\n return _reProto.test.bind(pattern);\n }\n\n lamb.padLeft = padLeft;\n lamb.padRight = padRight;\n lamb.repeat = repeat;\n lamb.testWith = testWith;\n\n /* istanbul ignore next */\n if (typeof exports === \"object\") {\n module.exports = lamb;\n } else if (typeof define === \"function\" && define.amd) {\n define(function () {\n return lamb;\n });\n } else {\n host.lamb = lamb;\n }\n})(this);\n\n/**\n * @callback AccumulatorCallback\n * @global\n * @param {*} previousValue - The value returned it the last execution of the accumulator or, in the first\n * iteration, the {@link module:lamb.reduce|initialValue} if supplied.\n * @param {*} currentValue - The value being processed in the current iteration.\n * @param {Number} idx - The index of the element being processed.\n * @param {ArrayLike} arrayLike - The list being traversed.\n */\n\n/**\n * The built-in arguments object.\n * @typedef {arguments} arguments\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments|arguments} in Mozilla documentation.\n */\n\n/**\n * The built-in Array object.\n * @typedef {Array} Array\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array|Array} in Mozilla documentation.\n */\n\n/**\n * Any array-like object.\n * @typedef {Array|String|arguments|?} ArrayLike\n * @global\n */\n\n/**\n * The built-in Boolean object.\n * @typedef {Boolean} Boolean\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean|Boolean} in Mozilla documentation.\n */\n\n/**\n * The built-in Date object.\n * @typedef {Date} Date\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date|Date} in Mozilla documentation.\n */\n\n/**\n * The built-in Function object.\n * @typedef {Function} function\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function|Function} and\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions|Functions} in Mozilla documentation.\n */\n\n/**\n * @callback ListIteratorCallback\n * @global\n * @param {*} element - The element being evaluated.\n * @param {Number} idx - The index of the element within the list.\n * @param {ArrayLike} arrayLike - The list being traversed.\n */\n\n/**\n * The built-in Number object.\n * @typedef {Number} Number\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number|Number} in Mozilla documentation.\n */\n\n/**\n * The built-in Object object.\n * @typedef {Object} Object\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object|Object} in Mozilla documentation.\n */\n\n/**\n * @callback ObjectIteratorCallback\n * @global\n * @param {*} value - The value of the current property.\n * @param {String} key - The property name.\n * @param {Object} source - The object being traversed.\n */\n\n/**\n * The built-in RegExp object.\n * @typedef {RegExp} RegExp\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp|RegExp} in Mozilla documentation.\n */\n\n/**\n * Represent a sorting criteria used by {@link module:lamb.sortedInsert|sortedInsert},\n * {@link module:lamb.sort|sort} and {@link module:lamb.sortWith|sortWith}, and it's\n * usually built using {@link module:lamb.sorter|sorter} and {@link module:lamb.sorterDesc|sorterDesc}.\n * @typedef {Sorter} Sorter\n * @global\n * @property {Boolean} isDescending\n * @property {Function} compare\n */\n\n/**\n * The built-in String object.\n * @typedef {String} String\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String|String} in Mozilla documentation.\n */\n\n/**\n * The built-in primitive value undefined\n * @typedef {Undefined} Undefined\n * @global\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined|undefined} in Mozilla documentation.\n */\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 2ac989d..4a8eba2 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "coveralls": "gulp coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" }, "tonicExample": "var _ = require('lamb');", - "version": "0.43.0-alpha.8", + "version": "0.43.0", "devDependencies": { "coveralls": "^2.11.14", "gulp": "^3.9.1",