UNPKG

714 kBJavaScriptView Raw
1/**
2 * k2 - Functional javascript utils
3 * @version v0.6.1
4 */
5(function webpackUniversalModuleDefinition(root, factory) {
6 if(typeof exports === 'object' && typeof module === 'object')
7 module.exports = factory();
8 else if(typeof define === 'function' && define.amd)
9 define(factory);
10 else if(typeof exports === 'object')
11 exports["k2"] = factory();
12 else
13 root["k2"] = factory();
14})(this, function() {
15return /******/ (function(modules) { // webpackBootstrap
16/******/ // The module cache
17/******/ var installedModules = {};
18
19/******/ // The require function
20/******/ function __webpack_require__(moduleId) {
21
22/******/ // Check if module is in cache
23/******/ if(installedModules[moduleId])
24/******/ return installedModules[moduleId].exports;
25
26/******/ // Create a new module (and put it into the cache)
27/******/ var module = installedModules[moduleId] = {
28/******/ exports: {},
29/******/ id: moduleId,
30/******/ loaded: false
31/******/ };
32
33/******/ // Execute the module function
34/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
35
36/******/ // Flag the module as loaded
37/******/ module.loaded = true;
38
39/******/ // Return the exports of the module
40/******/ return module.exports;
41/******/ }
42
43
44/******/ // expose the modules object (__webpack_modules__)
45/******/ __webpack_require__.m = modules;
46
47/******/ // expose the module cache
48/******/ __webpack_require__.c = installedModules;
49
50/******/ // __webpack_public_path__
51/******/ __webpack_require__.p = "";
52
53/******/ // Load entry module and return exports
54/******/ return __webpack_require__(0);
55/******/ })
56/************************************************************************/
57/******/ ([
58/* 0 */
59/***/ function(module, exports, __webpack_require__) {
60
61 "use strict";
62
63 var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
64
65 var findPartialMatches = _interopRequire(__webpack_require__(1));
66
67 var rankPartialMatches = _interopRequire(__webpack_require__(2));
68
69 var cleanText = _interopRequire(__webpack_require__(3));
70
71 var objectLens = _interopRequire(__webpack_require__(4));
72
73 var guessDateFormat = _interopRequire(__webpack_require__(5));
74
75 var onlyTrue = _interopRequire(__webpack_require__(6));
76
77 module.exports = {
78 findPartialMatches: findPartialMatches,
79 rankPartialMatches: rankPartialMatches,
80 cleanEnteredText: cleanText,
81 objectLens: objectLens,
82 guessDateFormat: guessDateFormat,
83 onlyTrue: onlyTrue
84 };
85
86/***/ },
87/* 1 */
88/***/ function(module, exports, __webpack_require__) {
89
90 "use strict";
91
92 __webpack_require__(7);
93 var check = __webpack_require__(9);
94 var _ = __webpack_require__(8);
95
96 function findPartialMatchesSingleProperty(property, items, queryText) {
97 la(check.unemptyString(property), "need property name", property);
98 la(check.array(items), "expected list of items", items);
99 la(check.string(queryText), "expected query string", queryText);
100 if (!queryText) {
101 return [];
102 }
103
104 var text = queryText.toLowerCase();
105 function hasQueryText(item) {
106 return item[property].toLowerCase().indexOf(text) !== -1;
107 }
108
109 return items.filter(hasQueryText);
110 }
111
112 function findPartialMatchesMultipleProperties(properties, items, queryText) {
113 if (check.string(properties)) {
114 return findPartialMatchesSingleProperty(properties, items, queryText);
115 }
116 la(check.arrayOfStrings(properties), "need properties", properties);
117 la(check.array(items), "expected list of items", items);
118 la(check.string(queryText), "expected query string", queryText);
119 if (!queryText) {
120 return [];
121 }
122
123 var text = queryText.toLowerCase();
124 function hasQueryText(item) {
125 return properties.some(function (property) {
126 var value = item[property];
127 if (!value) {
128 return false;
129 }
130 return value.toLowerCase().indexOf(text) !== -1;
131 });
132 }
133
134 return items.filter(hasQueryText);
135 }
136
137 module.exports = findPartialMatchesMultipleProperties;
138
139/***/ },
140/* 2 */
141/***/ function(module, exports, __webpack_require__) {
142
143 "use strict";
144
145 __webpack_require__(7);
146 var check = __webpack_require__(9);
147 var _ = __webpack_require__(8);
148
149 // given objects that match query text, rank them, with better matches first
150 function rankPartialMatchesSingleProperty(property, matches, queryText) {
151 la(check.unemptyString(property), "need property name", property);
152 la(check.array(matches), "expected list of matches", matches);
153 la(check.string(queryText), "expected query string", queryText);
154 if (!matches.length || !queryText) {
155 return [];
156 }
157 var text = queryText.toLowerCase();
158
159 // ranks items, whereby a lower number is a better rank, assumes item
160 // matches the query string.
161 function rankMatch(item) {
162 var NOT_FOUND_RANK = 1000000;
163 var matchText = item[property].toLowerCase();
164 if (matchText === text) {
165 return -1;
166 }
167 var matchStartsAt = matchText.indexOf(text);
168 if (matchStartsAt === -1) {
169 return NOT_FOUND_RANK;
170 }
171 return matchStartsAt;
172 }
173
174 return _.sortBy(matches, rankMatch);
175 }
176
177 function rankPartialMatchesMultipleProperties(properties, matches, queryText) {
178 if (check.string(properties)) {
179 return rankPartialMatchesSingleProperty(properties, matches, queryText);
180 }
181 la(check.arrayOfStrings(properties), "need properties", properties);
182 la(check.array(matches), "expected list of matches", matches);
183 la(check.string(queryText), "expected query string", queryText);
184 if (!matches.length || !queryText) {
185 return [];
186 }
187 var text = queryText.toLowerCase();
188
189 // ranks items, whereby a lower number is a better rank, assumes item
190 // matches the query string.
191 function rankMatch(property, item) {
192 var NOT_FOUND_RANK = 1000000;
193 var matchText = item[property];
194 if (!matchText) {
195 return NOT_FOUND_RANK;
196 }
197 matchText = matchText.toLowerCase();
198 if (matchText === text) {
199 return -1;
200 }
201 var matchStartsAt = matchText.indexOf(text);
202 if (matchStartsAt === -1) {
203 return NOT_FOUND_RANK;
204 }
205 return matchStartsAt;
206 }
207
208 // best match over multiple properties is the smallest match
209 function rankMatches(item) {
210 var ranks = properties.map(function (property) {
211 return rankMatch(property, item);
212 });
213
214 return _.min(ranks);
215 }
216
217 return _.sortBy(matches, rankMatches);
218 }
219
220 module.exports = rankPartialMatchesMultipleProperties;
221
222/***/ },
223/* 3 */
224/***/ function(module, exports, __webpack_require__) {
225
226
227
228 /**
229 Removes HTML entities added by TextArea. Used in ticker search
230 @method cleanEnteredSearchText */
231 "use strict";
232
233 module.exports = cleanEnteredSearchText;
234 __webpack_require__(7);
235 var check = __webpack_require__(9);
236 var _ = __webpack_require__(8);
237 function cleanEnteredSearchText(str) {
238 la(check.string(str), "expected string to clean", str);
239 str = str.toLowerCase();
240 str = str.replace(" ", " ");
241 str = str.trim();
242 str = _.unescape(str);
243 return str;
244 }
245
246/***/ },
247/* 4 */
248/***/ function(module, exports, __webpack_require__) {
249
250 "use strict";
251
252 var R = __webpack_require__(10);
253
254 /**
255 Makes a lens for immutable object updates on the given key.
256 @method objectLens */
257 function objectLens(key) {
258 return R.lens(R.prop(key), function (val, obj) {
259 var child = Object.create(obj);
260 child.toJSON = function () {
261 var base;
262 if (obj.toJSON) {
263 base = obj.toJSON();
264 } else {
265 base = R.pick(Object.keys(obj), obj);
266 }
267 base[key] = val;
268 return base;
269 };
270 child[key] = val;
271 return child;
272 });
273 }
274
275 module.exports = objectLens;
276
277/***/ },
278/* 5 */
279/***/ function(module, exports, __webpack_require__) {
280
281 "use strict";
282
283 var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
284
285 __webpack_require__(7);
286 var check = __webpack_require__(9);
287
288 var xor = _interopRequire(__webpack_require__(6));
289
290 var isYear = function (x) {
291 return check.number(x) && x > 0;
292 };
293
294 var isMonth = function (x) {
295 return check.number(x) && x > 0 && x < 13;
296 };
297
298 var isDay = function (x) {
299 return check.number(x) && x > 0 && x < 32;
300 };
301
302 var validYearMonthDay = function (y, m, d) {
303 la(check.number(y) && check.number(m) && check.number(d), "invalid year or month or day", y, m, d);
304 return isYear(y) && isMonth(m) && isDay(d);
305 };
306
307 var isFormat = function (regex, str) {
308 la(check.instance(regex, RegExp), "expected regular expression", regex);
309 la(check.string(str), "expected string", str);
310 return regex.test(str);
311 };
312
313 var validIndices = check.schema.bind(null, {
314 year: check.number,
315 month: check.number,
316 day: check.number
317 });
318
319 var parseString = function (regex, indices, str) {
320 la(check.instance(regex, RegExp));
321 la(check.object(indices) && validIndices(indices), "missing indices", indices);
322 la(check.string(str), "missing date string", str);
323 var initial = check.unemptyString(str) && isFormat(regex, str);
324 if (!initial) {
325 return;
326 }
327 var matches = regex.exec(str);
328 return {
329 year: parseInt(matches[indices.year]),
330 month: parseInt(matches[indices.month]),
331 day: parseInt(matches[indices.day])
332 };
333 };
334
335 var parseIfPossible = function (regex, indices, str) {
336 var date = parseString(regex, indices, str);
337 if (date) {
338 la(validIndices(date), "missing date fields", date);
339 return validYearMonthDay(date.year, date.month, date.day);
340 }
341 };
342
343 var isYYYYMMDD = parseIfPossible.bind(null, /^(\d\d\d\d)[\-|\/](\d\d)\-(\d\d)$/, {
344 year: 1,
345 month: 2,
346 day: 3
347 });
348
349 var isYYYYDDMM = parseIfPossible.bind(null, /^(\d\d\d\d)\-(\d\d)\-(\d\d)$/, {
350 year: 1,
351 month: 3,
352 day: 2
353 });
354
355 var isDDMMYYYY = parseIfPossible.bind(null, /^(\d\d)[-|\/](\d\d?)[-|\/](\d\d\d\d)$/, {
356 year: 3,
357 month: 2,
358 day: 1
359 });
360
361 var isMMDDYYYY = parseIfPossible.bind(null, /^(\d\d)[-|\/](\d\d?)[-|\/](\d\d\d\d)$/, {
362 day: 2,
363 month: 1,
364 year: 3 });
365
366 function lift(fn) {
367 return function lifted(arr) {
368 return Array.isArray(arr) ? arr.every(fn) : fn(arr);
369 };
370 }
371
372 var formats = {
373 "YYYY-MM-DD": lift(isYYYYMMDD),
374 "YYYY-DD-MM": lift(isYYYYDDMM),
375 "DD-MM-YYYY": lift(isDDMMYYYY),
376 "MM-DD-YYYY": lift(isMMDDYYYY)
377 };
378
379 function findMatchedFormats(strings) {
380 var matchedFormats = [];
381 Object.keys(formats).forEach(function (format) {
382 var formatCheck = formats[format];
383 la(check.fn(formatCheck), "expected check function", format, formatCheck);
384 if (formatCheck(strings)) {
385 matchedFormats.push(format);
386 }
387 });
388 return matchedFormats;
389 }
390
391 function guessDateFormat(strings) {
392 if (!arguments.length) {
393 return;
394 }
395
396 var matchedFormats = findMatchedFormats(strings);
397 la(check.array(matchedFormats), "expected array result", matchedFormats, strings);
398
399 if (matchedFormats.length !== 1) {
400 // no matches or ambiguous dates
401 return;
402 }
403
404 return matchedFormats[0];
405 }
406
407 module.exports = guessDateFormat;
408
409/***/ },
410/* 6 */
411/***/ function(module, exports, __webpack_require__) {
412
413 /*
414 Returns true only if for the given list of predicates,
415 only single one is true, and the rest are false.
416
417 onlyTrue(true, false, false); // true
418 onlyTrue(false, false, false); // false
419 onlyTrue(false, true, true); // false
420 onlyTrue(false, false, true); // true
421 */
422 "use strict";
423
424 function onlyTrue() {
425 var predicates = Array.prototype.slice.call(arguments, 0);
426 if (!predicates.length) {
427 return false;
428 }
429 var count = 0,
430 k;
431 for (k = 0; k < predicates.length; k += 1) {
432 if (predicates[k]) {
433 count += 1;
434 if (count > 1) {
435 return false;
436 }
437 }
438 }
439
440 return count === 1;
441 }
442
443 module.exports = onlyTrue;
444
445/***/ },
446/* 7 */
447/***/ function(module, exports, __webpack_require__) {
448
449 /* WEBPACK VAR INJECTION */(function(global) {(function initLazyAss() {
450
451 function isArrayLike(a) {
452 return a && typeof a.length === 'number';
453 }
454
455 function formMessage(args) {
456 var msg = args.reduce(function (total, arg, k) {
457 if (k) {
458 total += ' ';
459 }
460 if (typeof arg === 'string') {
461 return total + arg;
462 }
463 if (typeof arg === 'function') {
464 var fnResult;
465 try {
466 fnResult = arg();
467 } catch (err) {
468 // ignore the error
469 fnResult = '[function ' + arg.name + ' threw error!]';
470 }
471 return total + fnResult;
472 }
473 if (Array.isArray(arg)) {
474 return total + JSON.stringify(arg);
475 }
476 if (isArrayLike(arg)) {
477 return total + JSON.stringify(Array.prototype.slice.call(arg));
478 }
479 if (arg instanceof Error) {
480 return total + arg.name + ' ' + arg.message;
481 }
482 var argString;
483 try {
484 argString = JSON.stringify(arg, null, 2);
485 } catch (err) {
486 argString = '[cannot stringify arg ' + k + ']';
487 }
488 return total + argString;
489 }, '');
490 return msg;
491 }
492
493 function lazyAssLogic(condition) {
494 var fn = typeof condition === 'function' ? condition : null;
495
496 if (fn) {
497 condition = fn();
498 }
499 if (!condition) {
500 var args = [].slice.call(arguments, 1);
501 if (fn) {
502 args.unshift(fn.toString());
503 }
504 return new Error(formMessage(args));
505 }
506 }
507
508 var lazyAss = function lazyAss() {
509 var err = lazyAssLogic.apply(null, arguments);
510 if (err) {
511 throw err;
512 }
513 };
514
515 var lazyAssync = function lazyAssync() {
516 var err = lazyAssLogic.apply(null, arguments);
517 if (err) {
518 setTimeout(function () {
519 throw err;
520 }, 0);
521 }
522 };
523
524 function register(value, name) {
525 if (typeof window === 'object') {
526 /* global window */
527 window[name] = value;
528 } else if (typeof global === 'object') {
529 global[name] = value;
530 } else {
531 throw new Error('Do not know how to register ' + name);
532 }
533 }
534
535 register(lazyAss, 'lazyAss');
536 register(lazyAss, 'la');
537 register(lazyAssync, 'lazyAssync');
538 register(lazyAssync, 'lac');
539
540 }());
541
542 /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
543
544/***/ },
545/* 8 */
546/***/ function(module, exports, __webpack_require__) {
547
548 var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module, global) {/**
549 * @license
550 * lodash 3.6.0 (Custom Build) <https://lodash.com/>
551 * Build: `lodash modern -d -o ./index.js`
552 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
553 * Based on Underscore.js 1.8.2 <http://underscorejs.org/LICENSE>
554 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
555 * Available under MIT license <https://lodash.com/license>
556 */
557 ;(function() {
558
559 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
560 var undefined;
561
562 /** Used as the semantic version number. */
563 var VERSION = '3.6.0';
564
565 /** Used to compose bitmasks for wrapper metadata. */
566 var BIND_FLAG = 1,
567 BIND_KEY_FLAG = 2,
568 CURRY_BOUND_FLAG = 4,
569 CURRY_FLAG = 8,
570 CURRY_RIGHT_FLAG = 16,
571 PARTIAL_FLAG = 32,
572 PARTIAL_RIGHT_FLAG = 64,
573 ARY_FLAG = 128,
574 REARG_FLAG = 256;
575
576 /** Used as default options for `_.trunc`. */
577 var DEFAULT_TRUNC_LENGTH = 30,
578 DEFAULT_TRUNC_OMISSION = '...';
579
580 /** Used to detect when a function becomes hot. */
581 var HOT_COUNT = 150,
582 HOT_SPAN = 16;
583
584 /** Used to indicate the type of lazy iteratees. */
585 var LAZY_DROP_WHILE_FLAG = 0,
586 LAZY_FILTER_FLAG = 1,
587 LAZY_MAP_FLAG = 2;
588
589 /** Used as the `TypeError` message for "Functions" methods. */
590 var FUNC_ERROR_TEXT = 'Expected a function';
591
592 /** Used as the internal argument placeholder. */
593 var PLACEHOLDER = '__lodash_placeholder__';
594
595 /** `Object#toString` result references. */
596 var argsTag = '[object Arguments]',
597 arrayTag = '[object Array]',
598 boolTag = '[object Boolean]',
599 dateTag = '[object Date]',
600 errorTag = '[object Error]',
601 funcTag = '[object Function]',
602 mapTag = '[object Map]',
603 numberTag = '[object Number]',
604 objectTag = '[object Object]',
605 regexpTag = '[object RegExp]',
606 setTag = '[object Set]',
607 stringTag = '[object String]',
608 weakMapTag = '[object WeakMap]';
609
610 var arrayBufferTag = '[object ArrayBuffer]',
611 float32Tag = '[object Float32Array]',
612 float64Tag = '[object Float64Array]',
613 int8Tag = '[object Int8Array]',
614 int16Tag = '[object Int16Array]',
615 int32Tag = '[object Int32Array]',
616 uint8Tag = '[object Uint8Array]',
617 uint8ClampedTag = '[object Uint8ClampedArray]',
618 uint16Tag = '[object Uint16Array]',
619 uint32Tag = '[object Uint32Array]';
620
621 /** Used to match empty string literals in compiled template source. */
622 var reEmptyStringLeading = /\b__p \+= '';/g,
623 reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
624 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
625
626 /** Used to match HTML entities and HTML characters. */
627 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
628 reUnescapedHtml = /[&<>"'`]/g,
629 reHasEscapedHtml = RegExp(reEscapedHtml.source),
630 reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
631
632 /** Used to match template delimiters. */
633 var reEscape = /<%-([\s\S]+?)%>/g,
634 reEvaluate = /<%([\s\S]+?)%>/g,
635 reInterpolate = /<%=([\s\S]+?)%>/g;
636
637 /**
638 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
639 */
640 var reComboMarks = /[\u0300-\u036f\ufe20-\ufe23]/g;
641
642 /**
643 * Used to match [ES template delimiters](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components).
644 */
645 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
646
647 /** Used to match `RegExp` flags from their coerced string values. */
648 var reFlags = /\w*$/;
649
650 /** Used to detect hexadecimal string values. */
651 var reHexPrefix = /^0[xX]/;
652
653 /** Used to detect host constructors (Safari > 5). */
654 var reHostCtor = /^\[object .+?Constructor\]$/;
655
656 /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
657 var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
658
659 /** Used to ensure capturing order of template delimiters. */
660 var reNoMatch = /($^)/;
661
662 /**
663 * Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).
664 * In addition to special characters the forward slash is escaped to allow for
665 * easier `eval` use and `Function` compilation.
666 */
667 var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
668 reHasRegExpChars = RegExp(reRegExpChars.source);
669
670 /** Used to match unescaped characters in compiled string literals. */
671 var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
672
673 /** Used to match words to create compound words. */
674 var reWords = (function() {
675 var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
676 lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
677
678 return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
679 }());
680
681 /** Used to detect and test for whitespace. */
682 var whitespace = (
683 // Basic whitespace characters.
684 ' \t\x0b\f\xa0\ufeff' +
685
686 // Line terminators.
687 '\n\r\u2028\u2029' +
688
689 // Unicode category "Zs" space separators.
690 '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
691 );
692
693 /** Used to assign default `context` object properties. */
694 var contextProps = [
695 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
696 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
697 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'document',
698 'isFinite', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
699 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
700 'window'
701 ];
702
703 /** Used to make template sourceURLs easier to identify. */
704 var templateCounter = -1;
705
706 /** Used to identify `toStringTag` values of typed arrays. */
707 var typedArrayTags = {};
708 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
709 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
710 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
711 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
712 typedArrayTags[uint32Tag] = true;
713 typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
714 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
715 typedArrayTags[dateTag] = typedArrayTags[errorTag] =
716 typedArrayTags[funcTag] = typedArrayTags[mapTag] =
717 typedArrayTags[numberTag] = typedArrayTags[objectTag] =
718 typedArrayTags[regexpTag] = typedArrayTags[setTag] =
719 typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
720
721 /** Used to identify `toStringTag` values supported by `_.clone`. */
722 var cloneableTags = {};
723 cloneableTags[argsTag] = cloneableTags[arrayTag] =
724 cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
725 cloneableTags[dateTag] = cloneableTags[float32Tag] =
726 cloneableTags[float64Tag] = cloneableTags[int8Tag] =
727 cloneableTags[int16Tag] = cloneableTags[int32Tag] =
728 cloneableTags[numberTag] = cloneableTags[objectTag] =
729 cloneableTags[regexpTag] = cloneableTags[stringTag] =
730 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
731 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
732 cloneableTags[errorTag] = cloneableTags[funcTag] =
733 cloneableTags[mapTag] = cloneableTags[setTag] =
734 cloneableTags[weakMapTag] = false;
735
736 /** Used as an internal `_.debounce` options object by `_.throttle`. */
737 var debounceOptions = {
738 'leading': false,
739 'maxWait': 0,
740 'trailing': false
741 };
742
743 /** Used to map latin-1 supplementary letters to basic latin letters. */
744 var deburredLetters = {
745 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
746 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
747 '\xc7': 'C', '\xe7': 'c',
748 '\xd0': 'D', '\xf0': 'd',
749 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
750 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
751 '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
752 '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
753 '\xd1': 'N', '\xf1': 'n',
754 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
755 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
756 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
757 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
758 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
759 '\xc6': 'Ae', '\xe6': 'ae',
760 '\xde': 'Th', '\xfe': 'th',
761 '\xdf': 'ss'
762 };
763
764 /** Used to map characters to HTML entities. */
765 var htmlEscapes = {
766 '&': '&amp;',
767 '<': '&lt;',
768 '>': '&gt;',
769 '"': '&quot;',
770 "'": '&#39;',
771 '`': '&#96;'
772 };
773
774 /** Used to map HTML entities to characters. */
775 var htmlUnescapes = {
776 '&amp;': '&',
777 '&lt;': '<',
778 '&gt;': '>',
779 '&quot;': '"',
780 '&#39;': "'",
781 '&#96;': '`'
782 };
783
784 /** Used to determine if values are of the language type `Object`. */
785 var objectTypes = {
786 'function': true,
787 'object': true
788 };
789
790 /** Used to escape characters for inclusion in compiled string literals. */
791 var stringEscapes = {
792 '\\': '\\',
793 "'": "'",
794 '\n': 'n',
795 '\r': 'r',
796 '\u2028': 'u2028',
797 '\u2029': 'u2029'
798 };
799
800 /** Detect free variable `exports`. */
801 var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
802
803 /** Detect free variable `module`. */
804 var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
805
806 /** Detect free variable `global` from Node.js. */
807 var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
808
809 /** Detect free variable `self`. */
810 var freeSelf = objectTypes[typeof self] && self && self.Object && self;
811
812 /** Detect free variable `window`. */
813 var freeWindow = objectTypes[typeof window] && window && window.Object && window;
814
815 /** Detect the popular CommonJS extension `module.exports`. */
816 var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
817
818 /**
819 * Used as a reference to the global object.
820 *
821 * The `this` value is used if it is the global object to avoid Greasemonkey's
822 * restricted `window` object, otherwise the `window` object is used.
823 */
824 var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
825
826 /*--------------------------------------------------------------------------*/
827
828 /**
829 * The base implementation of `compareAscending` which compares values and
830 * sorts them in ascending order without guaranteeing a stable sort.
831 *
832 * @private
833 * @param {*} value The value to compare to `other`.
834 * @param {*} other The value to compare to `value`.
835 * @returns {number} Returns the sort order indicator for `value`.
836 */
837 function baseCompareAscending(value, other) {
838 if (value !== other) {
839 var valIsReflexive = value === value,
840 othIsReflexive = other === other;
841
842 if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
843 return 1;
844 }
845 if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
846 return -1;
847 }
848 }
849 return 0;
850 }
851
852 /**
853 * The base implementation of `_.findIndex` and `_.findLastIndex` without
854 * support for callback shorthands and `this` binding.
855 *
856 * @private
857 * @param {Array} array The array to search.
858 * @param {Function} predicate The function invoked per iteration.
859 * @param {boolean} [fromRight] Specify iterating from right to left.
860 * @returns {number} Returns the index of the matched value, else `-1`.
861 */
862 function baseFindIndex(array, predicate, fromRight) {
863 var length = array.length,
864 index = fromRight ? length : -1;
865
866 while ((fromRight ? index-- : ++index < length)) {
867 if (predicate(array[index], index, array)) {
868 return index;
869 }
870 }
871 return -1;
872 }
873
874 /**
875 * The base implementation of `_.indexOf` without support for binary searches.
876 *
877 * @private
878 * @param {Array} array The array to search.
879 * @param {*} value The value to search for.
880 * @param {number} fromIndex The index to search from.
881 * @returns {number} Returns the index of the matched value, else `-1`.
882 */
883 function baseIndexOf(array, value, fromIndex) {
884 if (value !== value) {
885 return indexOfNaN(array, fromIndex);
886 }
887 var index = fromIndex - 1,
888 length = array.length;
889
890 while (++index < length) {
891 if (array[index] === value) {
892 return index;
893 }
894 }
895 return -1;
896 }
897
898 /**
899 * The base implementation of `_.isFunction` without support for environments
900 * with incorrect `typeof` results.
901 *
902 * @private
903 * @param {*} value The value to check.
904 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
905 */
906 function baseIsFunction(value) {
907 // Avoid a Chakra JIT bug in compatibility modes of IE 11.
908 // See https://github.com/jashkenas/underscore/issues/1621 for more details.
909 return typeof value == 'function' || false;
910 }
911
912 /**
913 * Converts `value` to a string if it is not one. An empty string is returned
914 * for `null` or `undefined` values.
915 *
916 * @private
917 * @param {*} value The value to process.
918 * @returns {string} Returns the string.
919 */
920 function baseToString(value) {
921 if (typeof value == 'string') {
922 return value;
923 }
924 return value == null ? '' : (value + '');
925 }
926
927 /**
928 * Used by `_.max` and `_.min` as the default callback for string values.
929 *
930 * @private
931 * @param {string} string The string to inspect.
932 * @returns {number} Returns the code unit of the first character of the string.
933 */
934 function charAtCallback(string) {
935 return string.charCodeAt(0);
936 }
937
938 /**
939 * Used by `_.trim` and `_.trimLeft` to get the index of the first character
940 * of `string` that is not found in `chars`.
941 *
942 * @private
943 * @param {string} string The string to inspect.
944 * @param {string} chars The characters to find.
945 * @returns {number} Returns the index of the first character not found in `chars`.
946 */
947 function charsLeftIndex(string, chars) {
948 var index = -1,
949 length = string.length;
950
951 while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
952 return index;
953 }
954
955 /**
956 * Used by `_.trim` and `_.trimRight` to get the index of the last character
957 * of `string` that is not found in `chars`.
958 *
959 * @private
960 * @param {string} string The string to inspect.
961 * @param {string} chars The characters to find.
962 * @returns {number} Returns the index of the last character not found in `chars`.
963 */
964 function charsRightIndex(string, chars) {
965 var index = string.length;
966
967 while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
968 return index;
969 }
970
971 /**
972 * Used by `_.sortBy` to compare transformed elements of a collection and stable
973 * sort them in ascending order.
974 *
975 * @private
976 * @param {Object} object The object to compare to `other`.
977 * @param {Object} other The object to compare to `object`.
978 * @returns {number} Returns the sort order indicator for `object`.
979 */
980 function compareAscending(object, other) {
981 return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
982 }
983
984 /**
985 * Used by `_.sortByOrder` to compare multiple properties of each element
986 * in a collection and stable sort them in the following order:
987 *
988 * If orders is unspecified, sort in ascending order for all properties.
989 * Otherwise, for each property, sort in ascending order if its corresponding value in
990 * orders is true, and descending order if false.
991 *
992 * @private
993 * @param {Object} object The object to compare to `other`.
994 * @param {Object} other The object to compare to `object`.
995 * @param {boolean[]} orders The order to sort by for each property.
996 * @returns {number} Returns the sort order indicator for `object`.
997 */
998 function compareMultiple(object, other, orders) {
999 var index = -1,
1000 objCriteria = object.criteria,
1001 othCriteria = other.criteria,
1002 length = objCriteria.length,
1003 ordersLength = orders.length;
1004
1005 while (++index < length) {
1006 var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
1007 if (result) {
1008 if (index >= ordersLength) {
1009 return result;
1010 }
1011 return result * (orders[index] ? 1 : -1);
1012 }
1013 }
1014 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
1015 // that causes it, under certain circumstances, to provide the same value for
1016 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
1017 // for more details.
1018 //
1019 // This also ensures a stable sort in V8 and other engines.
1020 // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
1021 return object.index - other.index;
1022 }
1023
1024 /**
1025 * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
1026 *
1027 * @private
1028 * @param {string} letter The matched letter to deburr.
1029 * @returns {string} Returns the deburred letter.
1030 */
1031 function deburrLetter(letter) {
1032 return deburredLetters[letter];
1033 }
1034
1035 /**
1036 * Used by `_.escape` to convert characters to HTML entities.
1037 *
1038 * @private
1039 * @param {string} chr The matched character to escape.
1040 * @returns {string} Returns the escaped character.
1041 */
1042 function escapeHtmlChar(chr) {
1043 return htmlEscapes[chr];
1044 }
1045
1046 /**
1047 * Used by `_.template` to escape characters for inclusion in compiled
1048 * string literals.
1049 *
1050 * @private
1051 * @param {string} chr The matched character to escape.
1052 * @returns {string} Returns the escaped character.
1053 */
1054 function escapeStringChar(chr) {
1055 return '\\' + stringEscapes[chr];
1056 }
1057
1058 /**
1059 * Gets the index at which the first occurrence of `NaN` is found in `array`.
1060 *
1061 * @private
1062 * @param {Array} array The array to search.
1063 * @param {number} fromIndex The index to search from.
1064 * @param {boolean} [fromRight] Specify iterating from right to left.
1065 * @returns {number} Returns the index of the matched `NaN`, else `-1`.
1066 */
1067 function indexOfNaN(array, fromIndex, fromRight) {
1068 var length = array.length,
1069 index = fromIndex + (fromRight ? 0 : -1);
1070
1071 while ((fromRight ? index-- : ++index < length)) {
1072 var other = array[index];
1073 if (other !== other) {
1074 return index;
1075 }
1076 }
1077 return -1;
1078 }
1079
1080 /**
1081 * Checks if `value` is object-like.
1082 *
1083 * @private
1084 * @param {*} value The value to check.
1085 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1086 */
1087 function isObjectLike(value) {
1088 return !!value && typeof value == 'object';
1089 }
1090
1091 /**
1092 * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
1093 * character code is whitespace.
1094 *
1095 * @private
1096 * @param {number} charCode The character code to inspect.
1097 * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
1098 */
1099 function isSpace(charCode) {
1100 return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
1101 (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
1102 }
1103
1104 /**
1105 * Replaces all `placeholder` elements in `array` with an internal placeholder
1106 * and returns an array of their indexes.
1107 *
1108 * @private
1109 * @param {Array} array The array to modify.
1110 * @param {*} placeholder The placeholder to replace.
1111 * @returns {Array} Returns the new array of placeholder indexes.
1112 */
1113 function replaceHolders(array, placeholder) {
1114 var index = -1,
1115 length = array.length,
1116 resIndex = -1,
1117 result = [];
1118
1119 while (++index < length) {
1120 if (array[index] === placeholder) {
1121 array[index] = PLACEHOLDER;
1122 result[++resIndex] = index;
1123 }
1124 }
1125 return result;
1126 }
1127
1128 /**
1129 * An implementation of `_.uniq` optimized for sorted arrays without support
1130 * for callback shorthands and `this` binding.
1131 *
1132 * @private
1133 * @param {Array} array The array to inspect.
1134 * @param {Function} [iteratee] The function invoked per iteration.
1135 * @returns {Array} Returns the new duplicate-value-free array.
1136 */
1137 function sortedUniq(array, iteratee) {
1138 var seen,
1139 index = -1,
1140 length = array.length,
1141 resIndex = -1,
1142 result = [];
1143
1144 while (++index < length) {
1145 var value = array[index],
1146 computed = iteratee ? iteratee(value, index, array) : value;
1147
1148 if (!index || seen !== computed) {
1149 seen = computed;
1150 result[++resIndex] = value;
1151 }
1152 }
1153 return result;
1154 }
1155
1156 /**
1157 * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
1158 * character of `string`.
1159 *
1160 * @private
1161 * @param {string} string The string to inspect.
1162 * @returns {number} Returns the index of the first non-whitespace character.
1163 */
1164 function trimmedLeftIndex(string) {
1165 var index = -1,
1166 length = string.length;
1167
1168 while (++index < length && isSpace(string.charCodeAt(index))) {}
1169 return index;
1170 }
1171
1172 /**
1173 * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
1174 * character of `string`.
1175 *
1176 * @private
1177 * @param {string} string The string to inspect.
1178 * @returns {number} Returns the index of the last non-whitespace character.
1179 */
1180 function trimmedRightIndex(string) {
1181 var index = string.length;
1182
1183 while (index-- && isSpace(string.charCodeAt(index))) {}
1184 return index;
1185 }
1186
1187 /**
1188 * Used by `_.unescape` to convert HTML entities to characters.
1189 *
1190 * @private
1191 * @param {string} chr The matched character to unescape.
1192 * @returns {string} Returns the unescaped character.
1193 */
1194 function unescapeHtmlChar(chr) {
1195 return htmlUnescapes[chr];
1196 }
1197
1198 /*--------------------------------------------------------------------------*/
1199
1200 /**
1201 * Create a new pristine `lodash` function using the given `context` object.
1202 *
1203 * @static
1204 * @memberOf _
1205 * @category Utility
1206 * @param {Object} [context=root] The context object.
1207 * @returns {Function} Returns a new `lodash` function.
1208 * @example
1209 *
1210 * _.mixin({ 'foo': _.constant('foo') });
1211 *
1212 * var lodash = _.runInContext();
1213 * lodash.mixin({ 'bar': lodash.constant('bar') });
1214 *
1215 * _.isFunction(_.foo);
1216 * // => true
1217 * _.isFunction(_.bar);
1218 * // => false
1219 *
1220 * lodash.isFunction(lodash.foo);
1221 * // => false
1222 * lodash.isFunction(lodash.bar);
1223 * // => true
1224 *
1225 * // using `context` to mock `Date#getTime` use in `_.now`
1226 * var mock = _.runInContext({
1227 * 'Date': function() {
1228 * return { 'getTime': getTimeMock };
1229 * }
1230 * });
1231 *
1232 * // or creating a suped-up `defer` in Node.js
1233 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
1234 */
1235 function runInContext(context) {
1236 // Avoid issues with some ES3 environments that attempt to use values, named
1237 // after built-in constructors like `Object`, for the creation of literals.
1238 // ES5 clears this up by stating that literals must use built-in constructors.
1239 // See https://es5.github.io/#x11.1.5 for more details.
1240 context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
1241
1242 /** Native constructor references. */
1243 var Array = context.Array,
1244 Date = context.Date,
1245 Error = context.Error,
1246 Function = context.Function,
1247 Math = context.Math,
1248 Number = context.Number,
1249 Object = context.Object,
1250 RegExp = context.RegExp,
1251 String = context.String,
1252 TypeError = context.TypeError;
1253
1254 /** Used for native method references. */
1255 var arrayProto = Array.prototype,
1256 objectProto = Object.prototype,
1257 stringProto = String.prototype;
1258
1259 /** Used to detect DOM support. */
1260 var document = (document = context.window) && document.document;
1261
1262 /** Used to resolve the decompiled source of functions. */
1263 var fnToString = Function.prototype.toString;
1264
1265 /** Used to the length of n-tuples for `_.unzip`. */
1266 var getLength = baseProperty('length');
1267
1268 /** Used to check objects for own properties. */
1269 var hasOwnProperty = objectProto.hasOwnProperty;
1270
1271 /** Used to generate unique IDs. */
1272 var idCounter = 0;
1273
1274 /**
1275 * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
1276 * of values.
1277 */
1278 var objToString = objectProto.toString;
1279
1280 /** Used to restore the original `_` reference in `_.noConflict`. */
1281 var oldDash = context._;
1282
1283 /** Used to detect if a method is native. */
1284 var reNative = RegExp('^' +
1285 escapeRegExp(objToString)
1286 .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
1287 );
1288
1289 /** Native method references. */
1290 var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer,
1291 bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
1292 ceil = Math.ceil,
1293 clearTimeout = context.clearTimeout,
1294 floor = Math.floor,
1295 getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
1296 push = arrayProto.push,
1297 propertyIsEnumerable = objectProto.propertyIsEnumerable,
1298 Set = isNative(Set = context.Set) && Set,
1299 setTimeout = context.setTimeout,
1300 splice = arrayProto.splice,
1301 Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
1302 WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap;
1303
1304 /** Used to clone array buffers. */
1305 var Float64Array = (function() {
1306 // Safari 5 errors when using an array buffer to initialize a typed array
1307 // where the array buffer's `byteLength` is not a multiple of the typed
1308 // array's `BYTES_PER_ELEMENT`.
1309 try {
1310 var func = isNative(func = context.Float64Array) && func,
1311 result = new func(new ArrayBuffer(10), 0, 1) && func;
1312 } catch(e) {}
1313 return result;
1314 }());
1315
1316 /* Native method references for those with the same name as other `lodash` methods. */
1317 var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
1318 nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
1319 nativeIsFinite = context.isFinite,
1320 nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
1321 nativeMax = Math.max,
1322 nativeMin = Math.min,
1323 nativeNow = isNative(nativeNow = Date.now) && nativeNow,
1324 nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite,
1325 nativeParseInt = context.parseInt,
1326 nativeRandom = Math.random;
1327
1328 /** Used as references for `-Infinity` and `Infinity`. */
1329 var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
1330 POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
1331
1332 /** Used as references for the maximum length and index of an array. */
1333 var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
1334 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
1335 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
1336
1337 /** Used as the size, in bytes, of each `Float64Array` element. */
1338 var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
1339
1340 /**
1341 * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
1342 * of an array-like value.
1343 */
1344 var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
1345
1346 /** Used to store function metadata. */
1347 var metaMap = WeakMap && new WeakMap;
1348
1349 /** Used to lookup unminified function names. */
1350 var realNames = {};
1351
1352 /*------------------------------------------------------------------------*/
1353
1354 /**
1355 * Creates a `lodash` object which wraps `value` to enable implicit chaining.
1356 * Methods that operate on and return arrays, collections, and functions can
1357 * be chained together. Methods that return a boolean or single value will
1358 * automatically end the chain returning the unwrapped value. Explicit chaining
1359 * may be enabled using `_.chain`. The execution of chained methods is lazy,
1360 * that is, execution is deferred until `_#value` is implicitly or explicitly
1361 * called.
1362 *
1363 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
1364 * fusion is an optimization that merges iteratees to avoid creating intermediate
1365 * arrays and reduce the number of iteratee executions.
1366 *
1367 * Chaining is supported in custom builds as long as the `_#value` method is
1368 * directly or indirectly included in the build.
1369 *
1370 * In addition to lodash methods, wrappers have `Array` and `String` methods.
1371 *
1372 * The wrapper `Array` methods are:
1373 * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
1374 * `splice`, and `unshift`
1375 *
1376 * The wrapper `String` methods are:
1377 * `replace` and `split`
1378 *
1379 * The wrapper methods that support shortcut fusion are:
1380 * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
1381 * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
1382 * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
1383 * and `where`
1384 *
1385 * The chainable wrapper methods are:
1386 * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
1387 * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
1388 * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
1389 * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
1390 * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
1391 * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
1392 * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
1393 * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
1394 * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
1395 * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
1396 * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
1397 * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
1398 * `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
1399 * `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
1400 * `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
1401 * `without`, `wrap`, `xor`, `zip`, and `zipObject`
1402 *
1403 * The wrapper methods that are **not** chainable by default are:
1404 * `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
1405 * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
1406 * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
1407 * `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
1408 * `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
1409 * `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
1410 * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
1411 * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
1412 * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
1413 * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
1414 * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
1415 * `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
1416 * `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
1417 *
1418 * The wrapper method `sample` will return a wrapped value when `n` is provided,
1419 * otherwise an unwrapped value is returned.
1420 *
1421 * @name _
1422 * @constructor
1423 * @category Chain
1424 * @param {*} value The value to wrap in a `lodash` instance.
1425 * @returns {Object} Returns the new `lodash` wrapper instance.
1426 * @example
1427 *
1428 * var wrapped = _([1, 2, 3]);
1429 *
1430 * // returns an unwrapped value
1431 * wrapped.reduce(function(sum, n) {
1432 * return sum + n;
1433 * });
1434 * // => 6
1435 *
1436 * // returns a wrapped value
1437 * var squares = wrapped.map(function(n) {
1438 * return n * n;
1439 * });
1440 *
1441 * _.isArray(squares);
1442 * // => false
1443 *
1444 * _.isArray(squares.value());
1445 * // => true
1446 */
1447 function lodash(value) {
1448 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
1449 if (value instanceof LodashWrapper) {
1450 return value;
1451 }
1452 if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
1453 return wrapperClone(value);
1454 }
1455 }
1456 return new LodashWrapper(value);
1457 }
1458
1459 /**
1460 * The function whose prototype all chaining wrappers inherit from.
1461 *
1462 * @private
1463 */
1464 function baseLodash() {
1465 // No operation performed.
1466 }
1467
1468 /**
1469 * The base constructor for creating `lodash` wrapper objects.
1470 *
1471 * @private
1472 * @param {*} value The value to wrap.
1473 * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
1474 * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
1475 */
1476 function LodashWrapper(value, chainAll, actions) {
1477 this.__wrapped__ = value;
1478 this.__actions__ = actions || [];
1479 this.__chain__ = !!chainAll;
1480 }
1481
1482 /**
1483 * An object environment feature flags.
1484 *
1485 * @static
1486 * @memberOf _
1487 * @type Object
1488 */
1489 var support = lodash.support = {};
1490
1491 (function(x) {
1492
1493 /**
1494 * Detect if functions can be decompiled by `Function#toString`
1495 * (all but Firefox OS certified apps, older Opera mobile browsers, and
1496 * the PlayStation 3; forced `false` for Windows 8 apps).
1497 *
1498 * @memberOf _.support
1499 * @type boolean
1500 */
1501 support.funcDecomp = /\bthis\b/.test(function() { return this; });
1502
1503 /**
1504 * Detect if `Function#name` is supported (all but IE).
1505 *
1506 * @memberOf _.support
1507 * @type boolean
1508 */
1509 support.funcNames = typeof Function.name == 'string';
1510
1511 /**
1512 * Detect if the DOM is supported.
1513 *
1514 * @memberOf _.support
1515 * @type boolean
1516 */
1517 try {
1518 support.dom = document.createDocumentFragment().nodeType === 11;
1519 } catch(e) {
1520 support.dom = false;
1521 }
1522
1523 /**
1524 * Detect if `arguments` object indexes are non-enumerable.
1525 *
1526 * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
1527 * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
1528 * `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
1529 * checks for indexes that exceed their function's formal parameters with
1530 * associated values of `0`.
1531 *
1532 * @memberOf _.support
1533 * @type boolean
1534 */
1535 try {
1536 support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
1537 } catch(e) {
1538 support.nonEnumArgs = true;
1539 }
1540 }(0, 0));
1541
1542 /**
1543 * By default, the template delimiters used by lodash are like those in
1544 * embedded Ruby (ERB). Change the following template settings to use
1545 * alternative delimiters.
1546 *
1547 * @static
1548 * @memberOf _
1549 * @type Object
1550 */
1551 lodash.templateSettings = {
1552
1553 /**
1554 * Used to detect `data` property values to be HTML-escaped.
1555 *
1556 * @memberOf _.templateSettings
1557 * @type RegExp
1558 */
1559 'escape': reEscape,
1560
1561 /**
1562 * Used to detect code to be evaluated.
1563 *
1564 * @memberOf _.templateSettings
1565 * @type RegExp
1566 */
1567 'evaluate': reEvaluate,
1568
1569 /**
1570 * Used to detect `data` property values to inject.
1571 *
1572 * @memberOf _.templateSettings
1573 * @type RegExp
1574 */
1575 'interpolate': reInterpolate,
1576
1577 /**
1578 * Used to reference the data object in the template text.
1579 *
1580 * @memberOf _.templateSettings
1581 * @type string
1582 */
1583 'variable': '',
1584
1585 /**
1586 * Used to import variables into the compiled template.
1587 *
1588 * @memberOf _.templateSettings
1589 * @type Object
1590 */
1591 'imports': {
1592
1593 /**
1594 * A reference to the `lodash` function.
1595 *
1596 * @memberOf _.templateSettings.imports
1597 * @type Function
1598 */
1599 '_': lodash
1600 }
1601 };
1602
1603 /*------------------------------------------------------------------------*/
1604
1605 /**
1606 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
1607 *
1608 * @private
1609 * @param {*} value The value to wrap.
1610 */
1611 function LazyWrapper(value) {
1612 this.__wrapped__ = value;
1613 this.__actions__ = null;
1614 this.__dir__ = 1;
1615 this.__dropCount__ = 0;
1616 this.__filtered__ = false;
1617 this.__iteratees__ = null;
1618 this.__takeCount__ = POSITIVE_INFINITY;
1619 this.__views__ = null;
1620 }
1621
1622 /**
1623 * Creates a clone of the lazy wrapper object.
1624 *
1625 * @private
1626 * @name clone
1627 * @memberOf LazyWrapper
1628 * @returns {Object} Returns the cloned `LazyWrapper` object.
1629 */
1630 function lazyClone() {
1631 var actions = this.__actions__,
1632 iteratees = this.__iteratees__,
1633 views = this.__views__,
1634 result = new LazyWrapper(this.__wrapped__);
1635
1636 result.__actions__ = actions ? arrayCopy(actions) : null;
1637 result.__dir__ = this.__dir__;
1638 result.__filtered__ = this.__filtered__;
1639 result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
1640 result.__takeCount__ = this.__takeCount__;
1641 result.__views__ = views ? arrayCopy(views) : null;
1642 return result;
1643 }
1644
1645 /**
1646 * Reverses the direction of lazy iteration.
1647 *
1648 * @private
1649 * @name reverse
1650 * @memberOf LazyWrapper
1651 * @returns {Object} Returns the new reversed `LazyWrapper` object.
1652 */
1653 function lazyReverse() {
1654 if (this.__filtered__) {
1655 var result = new LazyWrapper(this);
1656 result.__dir__ = -1;
1657 result.__filtered__ = true;
1658 } else {
1659 result = this.clone();
1660 result.__dir__ *= -1;
1661 }
1662 return result;
1663 }
1664
1665 /**
1666 * Extracts the unwrapped value from its lazy wrapper.
1667 *
1668 * @private
1669 * @name value
1670 * @memberOf LazyWrapper
1671 * @returns {*} Returns the unwrapped value.
1672 */
1673 function lazyValue() {
1674 var array = this.__wrapped__.value();
1675 if (!isArray(array)) {
1676 return baseWrapperValue(array, this.__actions__);
1677 }
1678 var dir = this.__dir__,
1679 isRight = dir < 0,
1680 view = getView(0, array.length, this.__views__),
1681 start = view.start,
1682 end = view.end,
1683 length = end - start,
1684 index = isRight ? end : (start - 1),
1685 takeCount = nativeMin(length, this.__takeCount__),
1686 iteratees = this.__iteratees__,
1687 iterLength = iteratees ? iteratees.length : 0,
1688 resIndex = 0,
1689 result = [];
1690
1691 outer:
1692 while (length-- && resIndex < takeCount) {
1693 index += dir;
1694
1695 var iterIndex = -1,
1696 value = array[index];
1697
1698 while (++iterIndex < iterLength) {
1699 var data = iteratees[iterIndex],
1700 iteratee = data.iteratee,
1701 type = data.type;
1702
1703 if (type == LAZY_DROP_WHILE_FLAG) {
1704 if (data.done && (isRight ? (index > data.index) : (index < data.index))) {
1705 data.count = 0;
1706 data.done = false;
1707 }
1708 data.index = index;
1709 if (!data.done) {
1710 var limit = data.limit;
1711 if (!(data.done = limit > -1 ? (data.count++ >= limit) : !iteratee(value))) {
1712 continue outer;
1713 }
1714 }
1715 } else {
1716 var computed = iteratee(value);
1717 if (type == LAZY_MAP_FLAG) {
1718 value = computed;
1719 } else if (!computed) {
1720 if (type == LAZY_FILTER_FLAG) {
1721 continue outer;
1722 } else {
1723 break outer;
1724 }
1725 }
1726 }
1727 }
1728 result[resIndex++] = value;
1729 }
1730 return result;
1731 }
1732
1733 /*------------------------------------------------------------------------*/
1734
1735 /**
1736 * Creates a cache object to store key/value pairs.
1737 *
1738 * @private
1739 * @static
1740 * @name Cache
1741 * @memberOf _.memoize
1742 */
1743 function MapCache() {
1744 this.__data__ = {};
1745 }
1746
1747 /**
1748 * Removes `key` and its value from the cache.
1749 *
1750 * @private
1751 * @name delete
1752 * @memberOf _.memoize.Cache
1753 * @param {string} key The key of the value to remove.
1754 * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
1755 */
1756 function mapDelete(key) {
1757 return this.has(key) && delete this.__data__[key];
1758 }
1759
1760 /**
1761 * Gets the cached value for `key`.
1762 *
1763 * @private
1764 * @name get
1765 * @memberOf _.memoize.Cache
1766 * @param {string} key The key of the value to get.
1767 * @returns {*} Returns the cached value.
1768 */
1769 function mapGet(key) {
1770 return key == '__proto__' ? undefined : this.__data__[key];
1771 }
1772
1773 /**
1774 * Checks if a cached value for `key` exists.
1775 *
1776 * @private
1777 * @name has
1778 * @memberOf _.memoize.Cache
1779 * @param {string} key The key of the entry to check.
1780 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
1781 */
1782 function mapHas(key) {
1783 return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
1784 }
1785
1786 /**
1787 * Adds `value` to `key` of the cache.
1788 *
1789 * @private
1790 * @name set
1791 * @memberOf _.memoize.Cache
1792 * @param {string} key The key of the value to cache.
1793 * @param {*} value The value to cache.
1794 * @returns {Object} Returns the cache object.
1795 */
1796 function mapSet(key, value) {
1797 if (key != '__proto__') {
1798 this.__data__[key] = value;
1799 }
1800 return this;
1801 }
1802
1803 /*------------------------------------------------------------------------*/
1804
1805 /**
1806 *
1807 * Creates a cache object to store unique values.
1808 *
1809 * @private
1810 * @param {Array} [values] The values to cache.
1811 */
1812 function SetCache(values) {
1813 var length = values ? values.length : 0;
1814
1815 this.data = { 'hash': nativeCreate(null), 'set': new Set };
1816 while (length--) {
1817 this.push(values[length]);
1818 }
1819 }
1820
1821 /**
1822 * Checks if `value` is in `cache` mimicking the return signature of
1823 * `_.indexOf` by returning `0` if the value is found, else `-1`.
1824 *
1825 * @private
1826 * @param {Object} cache The cache to search.
1827 * @param {*} value The value to search for.
1828 * @returns {number} Returns `0` if `value` is found, else `-1`.
1829 */
1830 function cacheIndexOf(cache, value) {
1831 var data = cache.data,
1832 result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
1833
1834 return result ? 0 : -1;
1835 }
1836
1837 /**
1838 * Adds `value` to the cache.
1839 *
1840 * @private
1841 * @name push
1842 * @memberOf SetCache
1843 * @param {*} value The value to cache.
1844 */
1845 function cachePush(value) {
1846 var data = this.data;
1847 if (typeof value == 'string' || isObject(value)) {
1848 data.set.add(value);
1849 } else {
1850 data.hash[value] = true;
1851 }
1852 }
1853
1854 /*------------------------------------------------------------------------*/
1855
1856 /**
1857 * Copies the values of `source` to `array`.
1858 *
1859 * @private
1860 * @param {Array} source The array to copy values from.
1861 * @param {Array} [array=[]] The array to copy values to.
1862 * @returns {Array} Returns `array`.
1863 */
1864 function arrayCopy(source, array) {
1865 var index = -1,
1866 length = source.length;
1867
1868 array || (array = Array(length));
1869 while (++index < length) {
1870 array[index] = source[index];
1871 }
1872 return array;
1873 }
1874
1875 /**
1876 * A specialized version of `_.forEach` for arrays without support for callback
1877 * shorthands and `this` binding.
1878 *
1879 * @private
1880 * @param {Array} array The array to iterate over.
1881 * @param {Function} iteratee The function invoked per iteration.
1882 * @returns {Array} Returns `array`.
1883 */
1884 function arrayEach(array, iteratee) {
1885 var index = -1,
1886 length = array.length;
1887
1888 while (++index < length) {
1889 if (iteratee(array[index], index, array) === false) {
1890 break;
1891 }
1892 }
1893 return array;
1894 }
1895
1896 /**
1897 * A specialized version of `_.forEachRight` for arrays without support for
1898 * callback shorthands and `this` binding.
1899 *
1900 * @private
1901 * @param {Array} array The array to iterate over.
1902 * @param {Function} iteratee The function invoked per iteration.
1903 * @returns {Array} Returns `array`.
1904 */
1905 function arrayEachRight(array, iteratee) {
1906 var length = array.length;
1907
1908 while (length--) {
1909 if (iteratee(array[length], length, array) === false) {
1910 break;
1911 }
1912 }
1913 return array;
1914 }
1915
1916 /**
1917 * A specialized version of `_.every` for arrays without support for callback
1918 * shorthands and `this` binding.
1919 *
1920 * @private
1921 * @param {Array} array The array to iterate over.
1922 * @param {Function} predicate The function invoked per iteration.
1923 * @returns {boolean} Returns `true` if all elements pass the predicate check,
1924 * else `false`.
1925 */
1926 function arrayEvery(array, predicate) {
1927 var index = -1,
1928 length = array.length;
1929
1930 while (++index < length) {
1931 if (!predicate(array[index], index, array)) {
1932 return false;
1933 }
1934 }
1935 return true;
1936 }
1937
1938 /**
1939 * A specialized version of `_.filter` for arrays without support for callback
1940 * shorthands and `this` binding.
1941 *
1942 * @private
1943 * @param {Array} array The array to iterate over.
1944 * @param {Function} predicate The function invoked per iteration.
1945 * @returns {Array} Returns the new filtered array.
1946 */
1947 function arrayFilter(array, predicate) {
1948 var index = -1,
1949 length = array.length,
1950 resIndex = -1,
1951 result = [];
1952
1953 while (++index < length) {
1954 var value = array[index];
1955 if (predicate(value, index, array)) {
1956 result[++resIndex] = value;
1957 }
1958 }
1959 return result;
1960 }
1961
1962 /**
1963 * A specialized version of `_.map` for arrays without support for callback
1964 * shorthands and `this` binding.
1965 *
1966 * @private
1967 * @param {Array} array The array to iterate over.
1968 * @param {Function} iteratee The function invoked per iteration.
1969 * @returns {Array} Returns the new mapped array.
1970 */
1971 function arrayMap(array, iteratee) {
1972 var index = -1,
1973 length = array.length,
1974 result = Array(length);
1975
1976 while (++index < length) {
1977 result[index] = iteratee(array[index], index, array);
1978 }
1979 return result;
1980 }
1981
1982 /**
1983 * A specialized version of `_.max` for arrays without support for iteratees.
1984 *
1985 * @private
1986 * @param {Array} array The array to iterate over.
1987 * @returns {*} Returns the maximum value.
1988 */
1989 function arrayMax(array) {
1990 var index = -1,
1991 length = array.length,
1992 result = NEGATIVE_INFINITY;
1993
1994 while (++index < length) {
1995 var value = array[index];
1996 if (value > result) {
1997 result = value;
1998 }
1999 }
2000 return result;
2001 }
2002
2003 /**
2004 * A specialized version of `_.min` for arrays without support for iteratees.
2005 *
2006 * @private
2007 * @param {Array} array The array to iterate over.
2008 * @returns {*} Returns the minimum value.
2009 */
2010 function arrayMin(array) {
2011 var index = -1,
2012 length = array.length,
2013 result = POSITIVE_INFINITY;
2014
2015 while (++index < length) {
2016 var value = array[index];
2017 if (value < result) {
2018 result = value;
2019 }
2020 }
2021 return result;
2022 }
2023
2024 /**
2025 * A specialized version of `_.reduce` for arrays without support for callback
2026 * shorthands and `this` binding.
2027 *
2028 * @private
2029 * @param {Array} array The array to iterate over.
2030 * @param {Function} iteratee The function invoked per iteration.
2031 * @param {*} [accumulator] The initial value.
2032 * @param {boolean} [initFromArray] Specify using the first element of `array`
2033 * as the initial value.
2034 * @returns {*} Returns the accumulated value.
2035 */
2036 function arrayReduce(array, iteratee, accumulator, initFromArray) {
2037 var index = -1,
2038 length = array.length;
2039
2040 if (initFromArray && length) {
2041 accumulator = array[++index];
2042 }
2043 while (++index < length) {
2044 accumulator = iteratee(accumulator, array[index], index, array);
2045 }
2046 return accumulator;
2047 }
2048
2049 /**
2050 * A specialized version of `_.reduceRight` for arrays without support for
2051 * callback shorthands and `this` binding.
2052 *
2053 * @private
2054 * @param {Array} array The array to iterate over.
2055 * @param {Function} iteratee The function invoked per iteration.
2056 * @param {*} [accumulator] The initial value.
2057 * @param {boolean} [initFromArray] Specify using the last element of `array`
2058 * as the initial value.
2059 * @returns {*} Returns the accumulated value.
2060 */
2061 function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
2062 var length = array.length;
2063 if (initFromArray && length) {
2064 accumulator = array[--length];
2065 }
2066 while (length--) {
2067 accumulator = iteratee(accumulator, array[length], length, array);
2068 }
2069 return accumulator;
2070 }
2071
2072 /**
2073 * A specialized version of `_.some` for arrays without support for callback
2074 * shorthands and `this` binding.
2075 *
2076 * @private
2077 * @param {Array} array The array to iterate over.
2078 * @param {Function} predicate The function invoked per iteration.
2079 * @returns {boolean} Returns `true` if any element passes the predicate check,
2080 * else `false`.
2081 */
2082 function arraySome(array, predicate) {
2083 var index = -1,
2084 length = array.length;
2085
2086 while (++index < length) {
2087 if (predicate(array[index], index, array)) {
2088 return true;
2089 }
2090 }
2091 return false;
2092 }
2093
2094 /**
2095 * A specialized version of `_.sum` for arrays without support for iteratees.
2096 *
2097 * @private
2098 * @param {Array} array The array to iterate over.
2099 * @returns {number} Returns the sum.
2100 */
2101 function arraySum(array) {
2102 var length = array.length,
2103 result = 0;
2104
2105 while (length--) {
2106 result += +array[length] || 0;
2107 }
2108 return result;
2109 }
2110
2111 /**
2112 * Used by `_.defaults` to customize its `_.assign` use.
2113 *
2114 * @private
2115 * @param {*} objectValue The destination object property value.
2116 * @param {*} sourceValue The source object property value.
2117 * @returns {*} Returns the value to assign to the destination object.
2118 */
2119 function assignDefaults(objectValue, sourceValue) {
2120 return typeof objectValue == 'undefined' ? sourceValue : objectValue;
2121 }
2122
2123 /**
2124 * Used by `_.template` to customize its `_.assign` use.
2125 *
2126 * **Note:** This method is like `assignDefaults` except that it ignores
2127 * inherited property values when checking if a property is `undefined`.
2128 *
2129 * @private
2130 * @param {*} objectValue The destination object property value.
2131 * @param {*} sourceValue The source object property value.
2132 * @param {string} key The key associated with the object and source values.
2133 * @param {Object} object The destination object.
2134 * @returns {*} Returns the value to assign to the destination object.
2135 */
2136 function assignOwnDefaults(objectValue, sourceValue, key, object) {
2137 return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
2138 ? sourceValue
2139 : objectValue;
2140 }
2141
2142 /**
2143 * The base implementation of `_.assign` without support for argument juggling,
2144 * multiple sources, and `this` binding `customizer` functions.
2145 *
2146 * @private
2147 * @param {Object} object The destination object.
2148 * @param {Object} source The source object.
2149 * @param {Function} [customizer] The function to customize assigning values.
2150 * @returns {Object} Returns the destination object.
2151 */
2152 function baseAssign(object, source, customizer) {
2153 var props = keys(source);
2154 if (!customizer) {
2155 return baseCopy(source, object, props);
2156 }
2157 var index = -1,
2158 length = props.length;
2159
2160 while (++index < length) {
2161 var key = props[index],
2162 value = object[key],
2163 result = customizer(value, source[key], key, object, source);
2164
2165 if ((result === result ? (result !== value) : (value === value)) ||
2166 (typeof value == 'undefined' && !(key in object))) {
2167 object[key] = result;
2168 }
2169 }
2170 return object;
2171 }
2172
2173 /**
2174 * The base implementation of `_.at` without support for strings and individual
2175 * key arguments.
2176 *
2177 * @private
2178 * @param {Array|Object} collection The collection to iterate over.
2179 * @param {number[]|string[]} [props] The property names or indexes of elements to pick.
2180 * @returns {Array} Returns the new array of picked elements.
2181 */
2182 function baseAt(collection, props) {
2183 var index = -1,
2184 length = collection.length,
2185 isArr = isLength(length),
2186 propsLength = props.length,
2187 result = Array(propsLength);
2188
2189 while(++index < propsLength) {
2190 var key = props[index];
2191 if (isArr) {
2192 key = parseFloat(key);
2193 result[index] = isIndex(key, length) ? collection[key] : undefined;
2194 } else {
2195 result[index] = collection[key];
2196 }
2197 }
2198 return result;
2199 }
2200
2201 /**
2202 * Copies the properties of `source` to `object`.
2203 *
2204 * @private
2205 * @param {Object} source The object to copy properties from.
2206 * @param {Object} [object={}] The object to copy properties to.
2207 * @param {Array} props The property names to copy.
2208 * @returns {Object} Returns `object`.
2209 */
2210 function baseCopy(source, object, props) {
2211 if (!props) {
2212 props = object;
2213 object = {};
2214 }
2215 var index = -1,
2216 length = props.length;
2217
2218 while (++index < length) {
2219 var key = props[index];
2220 object[key] = source[key];
2221 }
2222 return object;
2223 }
2224
2225 /**
2226 * The base implementation of `_.callback` which supports specifying the
2227 * number of arguments to provide to `func`.
2228 *
2229 * @private
2230 * @param {*} [func=_.identity] The value to convert to a callback.
2231 * @param {*} [thisArg] The `this` binding of `func`.
2232 * @param {number} [argCount] The number of arguments to provide to `func`.
2233 * @returns {Function} Returns the callback.
2234 */
2235 function baseCallback(func, thisArg, argCount) {
2236 var type = typeof func;
2237 if (type == 'function') {
2238 return typeof thisArg == 'undefined'
2239 ? func
2240 : bindCallback(func, thisArg, argCount);
2241 }
2242 if (func == null) {
2243 return identity;
2244 }
2245 if (type == 'object') {
2246 return baseMatches(func);
2247 }
2248 return typeof thisArg == 'undefined'
2249 ? baseProperty(func + '')
2250 : baseMatchesProperty(func + '', thisArg);
2251 }
2252
2253 /**
2254 * The base implementation of `_.clone` without support for argument juggling
2255 * and `this` binding `customizer` functions.
2256 *
2257 * @private
2258 * @param {*} value The value to clone.
2259 * @param {boolean} [isDeep] Specify a deep clone.
2260 * @param {Function} [customizer] The function to customize cloning values.
2261 * @param {string} [key] The key of `value`.
2262 * @param {Object} [object] The object `value` belongs to.
2263 * @param {Array} [stackA=[]] Tracks traversed source objects.
2264 * @param {Array} [stackB=[]] Associates clones with source counterparts.
2265 * @returns {*} Returns the cloned value.
2266 */
2267 function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
2268 var result;
2269 if (customizer) {
2270 result = object ? customizer(value, key, object) : customizer(value);
2271 }
2272 if (typeof result != 'undefined') {
2273 return result;
2274 }
2275 if (!isObject(value)) {
2276 return value;
2277 }
2278 var isArr = isArray(value);
2279 if (isArr) {
2280 result = initCloneArray(value);
2281 if (!isDeep) {
2282 return arrayCopy(value, result);
2283 }
2284 } else {
2285 var tag = objToString.call(value),
2286 isFunc = tag == funcTag;
2287
2288 if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2289 result = initCloneObject(isFunc ? {} : value);
2290 if (!isDeep) {
2291 return baseCopy(value, result, keys(value));
2292 }
2293 } else {
2294 return cloneableTags[tag]
2295 ? initCloneByTag(value, tag, isDeep)
2296 : (object ? value : {});
2297 }
2298 }
2299 // Check for circular references and return corresponding clone.
2300 stackA || (stackA = []);
2301 stackB || (stackB = []);
2302
2303 var length = stackA.length;
2304 while (length--) {
2305 if (stackA[length] == value) {
2306 return stackB[length];
2307 }
2308 }
2309 // Add the source value to the stack of traversed objects and associate it with its clone.
2310 stackA.push(value);
2311 stackB.push(result);
2312
2313 // Recursively populate clone (susceptible to call stack limits).
2314 (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
2315 result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
2316 });
2317 return result;
2318 }
2319
2320 /**
2321 * The base implementation of `_.create` without support for assigning
2322 * properties to the created object.
2323 *
2324 * @private
2325 * @param {Object} prototype The object to inherit from.
2326 * @returns {Object} Returns the new object.
2327 */
2328 var baseCreate = (function() {
2329 function Object() {}
2330 return function(prototype) {
2331 if (isObject(prototype)) {
2332 Object.prototype = prototype;
2333 var result = new Object;
2334 Object.prototype = null;
2335 }
2336 return result || context.Object();
2337 };
2338 }());
2339
2340 /**
2341 * The base implementation of `_.delay` and `_.defer` which accepts an index
2342 * of where to slice the arguments to provide to `func`.
2343 *
2344 * @private
2345 * @param {Function} func The function to delay.
2346 * @param {number} wait The number of milliseconds to delay invocation.
2347 * @param {Object} args The arguments provide to `func`.
2348 * @returns {number} Returns the timer id.
2349 */
2350 function baseDelay(func, wait, args) {
2351 if (typeof func != 'function') {
2352 throw new TypeError(FUNC_ERROR_TEXT);
2353 }
2354 return setTimeout(function() { func.apply(undefined, args); }, wait);
2355 }
2356
2357 /**
2358 * The base implementation of `_.difference` which accepts a single array
2359 * of values to exclude.
2360 *
2361 * @private
2362 * @param {Array} array The array to inspect.
2363 * @param {Array} values The values to exclude.
2364 * @returns {Array} Returns the new array of filtered values.
2365 */
2366 function baseDifference(array, values) {
2367 var length = array ? array.length : 0,
2368 result = [];
2369
2370 if (!length) {
2371 return result;
2372 }
2373 var index = -1,
2374 indexOf = getIndexOf(),
2375 isCommon = indexOf == baseIndexOf,
2376 cache = (isCommon && values.length >= 200) ? createCache(values) : null,
2377 valuesLength = values.length;
2378
2379 if (cache) {
2380 indexOf = cacheIndexOf;
2381 isCommon = false;
2382 values = cache;
2383 }
2384 outer:
2385 while (++index < length) {
2386 var value = array[index];
2387
2388 if (isCommon && value === value) {
2389 var valuesIndex = valuesLength;
2390 while (valuesIndex--) {
2391 if (values[valuesIndex] === value) {
2392 continue outer;
2393 }
2394 }
2395 result.push(value);
2396 }
2397 else if (indexOf(values, value, 0) < 0) {
2398 result.push(value);
2399 }
2400 }
2401 return result;
2402 }
2403
2404 /**
2405 * The base implementation of `_.forEach` without support for callback
2406 * shorthands and `this` binding.
2407 *
2408 * @private
2409 * @param {Array|Object|string} collection The collection to iterate over.
2410 * @param {Function} iteratee The function invoked per iteration.
2411 * @returns {Array|Object|string} Returns `collection`.
2412 */
2413 var baseEach = createBaseEach(baseForOwn);
2414
2415 /**
2416 * The base implementation of `_.forEachRight` without support for callback
2417 * shorthands and `this` binding.
2418 *
2419 * @private
2420 * @param {Array|Object|string} collection The collection to iterate over.
2421 * @param {Function} iteratee The function invoked per iteration.
2422 * @returns {Array|Object|string} Returns `collection`.
2423 */
2424 var baseEachRight = createBaseEach(baseForOwnRight, true);
2425
2426 /**
2427 * The base implementation of `_.every` without support for callback
2428 * shorthands and `this` binding.
2429 *
2430 * @private
2431 * @param {Array|Object|string} collection The collection to iterate over.
2432 * @param {Function} predicate The function invoked per iteration.
2433 * @returns {boolean} Returns `true` if all elements pass the predicate check,
2434 * else `false`
2435 */
2436 function baseEvery(collection, predicate) {
2437 var result = true;
2438 baseEach(collection, function(value, index, collection) {
2439 result = !!predicate(value, index, collection);
2440 return result;
2441 });
2442 return result;
2443 }
2444
2445 /**
2446 * The base implementation of `_.fill` without an iteratee call guard.
2447 *
2448 * @private
2449 * @param {Array} array The array to fill.
2450 * @param {*} value The value to fill `array` with.
2451 * @param {number} [start=0] The start position.
2452 * @param {number} [end=array.length] The end position.
2453 * @returns {Array} Returns `array`.
2454 */
2455 function baseFill(array, value, start, end) {
2456 var length = array.length;
2457
2458 start = start == null ? 0 : (+start || 0);
2459 if (start < 0) {
2460 start = -start > length ? 0 : (length + start);
2461 }
2462 end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
2463 if (end < 0) {
2464 end += length;
2465 }
2466 length = start > end ? 0 : (end >>> 0);
2467 start >>>= 0;
2468
2469 while (start < length) {
2470 array[start++] = value;
2471 }
2472 return array;
2473 }
2474
2475 /**
2476 * The base implementation of `_.filter` without support for callback
2477 * shorthands and `this` binding.
2478 *
2479 * @private
2480 * @param {Array|Object|string} collection The collection to iterate over.
2481 * @param {Function} predicate The function invoked per iteration.
2482 * @returns {Array} Returns the new filtered array.
2483 */
2484 function baseFilter(collection, predicate) {
2485 var result = [];
2486 baseEach(collection, function(value, index, collection) {
2487 if (predicate(value, index, collection)) {
2488 result.push(value);
2489 }
2490 });
2491 return result;
2492 }
2493
2494 /**
2495 * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
2496 * without support for callback shorthands and `this` binding, which iterates
2497 * over `collection` using the provided `eachFunc`.
2498 *
2499 * @private
2500 * @param {Array|Object|string} collection The collection to search.
2501 * @param {Function} predicate The function invoked per iteration.
2502 * @param {Function} eachFunc The function to iterate over `collection`.
2503 * @param {boolean} [retKey] Specify returning the key of the found element
2504 * instead of the element itself.
2505 * @returns {*} Returns the found element or its key, else `undefined`.
2506 */
2507 function baseFind(collection, predicate, eachFunc, retKey) {
2508 var result;
2509 eachFunc(collection, function(value, key, collection) {
2510 if (predicate(value, key, collection)) {
2511 result = retKey ? key : value;
2512 return false;
2513 }
2514 });
2515 return result;
2516 }
2517
2518 /**
2519 * The base implementation of `_.flatten` with added support for restricting
2520 * flattening and specifying the start index.
2521 *
2522 * @private
2523 * @param {Array} array The array to flatten.
2524 * @param {boolean} isDeep Specify a deep flatten.
2525 * @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
2526 * @returns {Array} Returns the new flattened array.
2527 */
2528 function baseFlatten(array, isDeep, isStrict) {
2529 var index = -1,
2530 length = array.length,
2531 resIndex = -1,
2532 result = [];
2533
2534 while (++index < length) {
2535 var value = array[index];
2536
2537 if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
2538 if (isDeep) {
2539 // Recursively flatten arrays (susceptible to call stack limits).
2540 value = baseFlatten(value, isDeep, isStrict);
2541 }
2542 var valIndex = -1,
2543 valLength = value.length;
2544
2545 result.length += valLength;
2546 while (++valIndex < valLength) {
2547 result[++resIndex] = value[valIndex];
2548 }
2549 } else if (!isStrict) {
2550 result[++resIndex] = value;
2551 }
2552 }
2553 return result;
2554 }
2555
2556 /**
2557 * The base implementation of `baseForIn` and `baseForOwn` which iterates
2558 * over `object` properties returned by `keysFunc` invoking `iteratee` for
2559 * each property. Iterator functions may exit iteration early by explicitly
2560 * returning `false`.
2561 *
2562 * @private
2563 * @param {Object} object The object to iterate over.
2564 * @param {Function} iteratee The function invoked per iteration.
2565 * @param {Function} keysFunc The function to get the keys of `object`.
2566 * @returns {Object} Returns `object`.
2567 */
2568 var baseFor = createBaseFor();
2569
2570 /**
2571 * This function is like `baseFor` except that it iterates over properties
2572 * in the opposite order.
2573 *
2574 * @private
2575 * @param {Object} object The object to iterate over.
2576 * @param {Function} iteratee The function invoked per iteration.
2577 * @param {Function} keysFunc The function to get the keys of `object`.
2578 * @returns {Object} Returns `object`.
2579 */
2580 var baseForRight = createBaseFor(true);
2581
2582 /**
2583 * The base implementation of `_.forIn` without support for callback
2584 * shorthands and `this` binding.
2585 *
2586 * @private
2587 * @param {Object} object The object to iterate over.
2588 * @param {Function} iteratee The function invoked per iteration.
2589 * @returns {Object} Returns `object`.
2590 */
2591 function baseForIn(object, iteratee) {
2592 return baseFor(object, iteratee, keysIn);
2593 }
2594
2595 /**
2596 * The base implementation of `_.forOwn` without support for callback
2597 * shorthands and `this` binding.
2598 *
2599 * @private
2600 * @param {Object} object The object to iterate over.
2601 * @param {Function} iteratee The function invoked per iteration.
2602 * @returns {Object} Returns `object`.
2603 */
2604 function baseForOwn(object, iteratee) {
2605 return baseFor(object, iteratee, keys);
2606 }
2607
2608 /**
2609 * The base implementation of `_.forOwnRight` without support for callback
2610 * shorthands and `this` binding.
2611 *
2612 * @private
2613 * @param {Object} object The object to iterate over.
2614 * @param {Function} iteratee The function invoked per iteration.
2615 * @returns {Object} Returns `object`.
2616 */
2617 function baseForOwnRight(object, iteratee) {
2618 return baseForRight(object, iteratee, keys);
2619 }
2620
2621 /**
2622 * The base implementation of `_.functions` which creates an array of
2623 * `object` function property names filtered from those provided.
2624 *
2625 * @private
2626 * @param {Object} object The object to inspect.
2627 * @param {Array} props The property names to filter.
2628 * @returns {Array} Returns the new array of filtered property names.
2629 */
2630 function baseFunctions(object, props) {
2631 var index = -1,
2632 length = props.length,
2633 resIndex = -1,
2634 result = [];
2635
2636 while (++index < length) {
2637 var key = props[index];
2638 if (isFunction(object[key])) {
2639 result[++resIndex] = key;
2640 }
2641 }
2642 return result;
2643 }
2644
2645 /**
2646 * The base implementation of `_.isEqual` without support for `this` binding
2647 * `customizer` functions.
2648 *
2649 * @private
2650 * @param {*} value The value to compare.
2651 * @param {*} other The other value to compare.
2652 * @param {Function} [customizer] The function to customize comparing values.
2653 * @param {boolean} [isLoose] Specify performing partial comparisons.
2654 * @param {Array} [stackA] Tracks traversed `value` objects.
2655 * @param {Array} [stackB] Tracks traversed `other` objects.
2656 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
2657 */
2658 function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
2659 // Exit early for identical values.
2660 if (value === other) {
2661 // Treat `+0` vs. `-0` as not equal.
2662 return value !== 0 || (1 / value == 1 / other);
2663 }
2664 var valType = typeof value,
2665 othType = typeof other;
2666
2667 // Exit early for unlike primitive values.
2668 if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') ||
2669 value == null || other == null) {
2670 // Return `false` unless both values are `NaN`.
2671 return value !== value && other !== other;
2672 }
2673 return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
2674 }
2675
2676 /**
2677 * A specialized version of `baseIsEqual` for arrays and objects which performs
2678 * deep comparisons and tracks traversed objects enabling objects with circular
2679 * references to be compared.
2680 *
2681 * @private
2682 * @param {Object} object The object to compare.
2683 * @param {Object} other The other object to compare.
2684 * @param {Function} equalFunc The function to determine equivalents of values.
2685 * @param {Function} [customizer] The function to customize comparing objects.
2686 * @param {boolean} [isLoose] Specify performing partial comparisons.
2687 * @param {Array} [stackA=[]] Tracks traversed `value` objects.
2688 * @param {Array} [stackB=[]] Tracks traversed `other` objects.
2689 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2690 */
2691 function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
2692 var objIsArr = isArray(object),
2693 othIsArr = isArray(other),
2694 objTag = arrayTag,
2695 othTag = arrayTag;
2696
2697 if (!objIsArr) {
2698 objTag = objToString.call(object);
2699 if (objTag == argsTag) {
2700 objTag = objectTag;
2701 } else if (objTag != objectTag) {
2702 objIsArr = isTypedArray(object);
2703 }
2704 }
2705 if (!othIsArr) {
2706 othTag = objToString.call(other);
2707 if (othTag == argsTag) {
2708 othTag = objectTag;
2709 } else if (othTag != objectTag) {
2710 othIsArr = isTypedArray(other);
2711 }
2712 }
2713 var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)),
2714 othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)),
2715 isSameTag = objTag == othTag;
2716
2717 if (isSameTag && !(objIsArr || objIsObj)) {
2718 return equalByTag(object, other, objTag);
2719 }
2720 if (isLoose) {
2721 if (!isSameTag && !(objIsObj && othIsObj)) {
2722 return false;
2723 }
2724 } else {
2725 var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
2726 othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
2727
2728 if (valWrapped || othWrapped) {
2729 return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
2730 }
2731 if (!isSameTag) {
2732 return false;
2733 }
2734 }
2735 // Assume cyclic values are equal.
2736 // For more information on detecting circular references see https://es5.github.io/#JO.
2737 stackA || (stackA = []);
2738 stackB || (stackB = []);
2739
2740 var length = stackA.length;
2741 while (length--) {
2742 if (stackA[length] == object) {
2743 return stackB[length] == other;
2744 }
2745 }
2746 // Add `object` and `other` to the stack of traversed objects.
2747 stackA.push(object);
2748 stackB.push(other);
2749
2750 var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
2751
2752 stackA.pop();
2753 stackB.pop();
2754
2755 return result;
2756 }
2757
2758 /**
2759 * The base implementation of `_.isMatch` without support for callback
2760 * shorthands and `this` binding.
2761 *
2762 * @private
2763 * @param {Object} object The object to inspect.
2764 * @param {Array} props The source property names to match.
2765 * @param {Array} values The source values to match.
2766 * @param {Array} strictCompareFlags Strict comparison flags for source values.
2767 * @param {Function} [customizer] The function to customize comparing objects.
2768 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
2769 */
2770 function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
2771 var index = -1,
2772 length = props.length,
2773 noCustomizer = !customizer;
2774
2775 while (++index < length) {
2776 if ((noCustomizer && strictCompareFlags[index])
2777 ? values[index] !== object[props[index]]
2778 : !(props[index] in object)
2779 ) {
2780 return false;
2781 }
2782 }
2783 index = -1;
2784 while (++index < length) {
2785 var key = props[index],
2786 objValue = object[key],
2787 srcValue = values[index];
2788
2789 if (noCustomizer && strictCompareFlags[index]) {
2790 var result = typeof objValue != 'undefined' || (key in object);
2791 } else {
2792 result = customizer ? customizer(objValue, srcValue, key) : undefined;
2793 if (typeof result == 'undefined') {
2794 result = baseIsEqual(srcValue, objValue, customizer, true);
2795 }
2796 }
2797 if (!result) {
2798 return false;
2799 }
2800 }
2801 return true;
2802 }
2803
2804 /**
2805 * The base implementation of `_.map` without support for callback shorthands
2806 * and `this` binding.
2807 *
2808 * @private
2809 * @param {Array|Object|string} collection The collection to iterate over.
2810 * @param {Function} iteratee The function invoked per iteration.
2811 * @returns {Array} Returns the new mapped array.
2812 */
2813 function baseMap(collection, iteratee) {
2814 var result = [];
2815 baseEach(collection, function(value, key, collection) {
2816 result.push(iteratee(value, key, collection));
2817 });
2818 return result;
2819 }
2820
2821 /**
2822 * The base implementation of `_.matches` which does not clone `source`.
2823 *
2824 * @private
2825 * @param {Object} source The object of property values to match.
2826 * @returns {Function} Returns the new function.
2827 */
2828 function baseMatches(source) {
2829 var props = keys(source),
2830 length = props.length;
2831
2832 if (!length) {
2833 return constant(true);
2834 }
2835 if (length == 1) {
2836 var key = props[0],
2837 value = source[key];
2838
2839 if (isStrictComparable(value)) {
2840 return function(object) {
2841 return object != null && object[key] === value &&
2842 (typeof value != 'undefined' || (key in toObject(object)));
2843 };
2844 }
2845 }
2846 var values = Array(length),
2847 strictCompareFlags = Array(length);
2848
2849 while (length--) {
2850 value = source[props[length]];
2851 values[length] = value;
2852 strictCompareFlags[length] = isStrictComparable(value);
2853 }
2854 return function(object) {
2855 return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
2856 };
2857 }
2858
2859 /**
2860 * The base implementation of `_.matchesProperty` which does not coerce `key`
2861 * to a string.
2862 *
2863 * @private
2864 * @param {string} key The key of the property to get.
2865 * @param {*} value The value to compare.
2866 * @returns {Function} Returns the new function.
2867 */
2868 function baseMatchesProperty(key, value) {
2869 if (isStrictComparable(value)) {
2870 return function(object) {
2871 return object != null && object[key] === value &&
2872 (typeof value != 'undefined' || (key in toObject(object)));
2873 };
2874 }
2875 return function(object) {
2876 return object != null && baseIsEqual(value, object[key], null, true);
2877 };
2878 }
2879
2880 /**
2881 * The base implementation of `_.merge` without support for argument juggling,
2882 * multiple sources, and `this` binding `customizer` functions.
2883 *
2884 * @private
2885 * @param {Object} object The destination object.
2886 * @param {Object} source The source object.
2887 * @param {Function} [customizer] The function to customize merging properties.
2888 * @param {Array} [stackA=[]] Tracks traversed source objects.
2889 * @param {Array} [stackB=[]] Associates values with source counterparts.
2890 * @returns {Object} Returns the destination object.
2891 */
2892 function baseMerge(object, source, customizer, stackA, stackB) {
2893 if (!isObject(object)) {
2894 return object;
2895 }
2896 var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
2897 (isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
2898 if (isObjectLike(srcValue)) {
2899 stackA || (stackA = []);
2900 stackB || (stackB = []);
2901 return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
2902 }
2903 var value = object[key],
2904 result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
2905 isCommon = typeof result == 'undefined';
2906
2907 if (isCommon) {
2908 result = srcValue;
2909 }
2910 if ((isSrcArr || typeof result != 'undefined') &&
2911 (isCommon || (result === result ? (result !== value) : (value === value)))) {
2912 object[key] = result;
2913 }
2914 });
2915 return object;
2916 }
2917
2918 /**
2919 * A specialized version of `baseMerge` for arrays and objects which performs
2920 * deep merges and tracks traversed objects enabling objects with circular
2921 * references to be merged.
2922 *
2923 * @private
2924 * @param {Object} object The destination object.
2925 * @param {Object} source The source object.
2926 * @param {string} key The key of the value to merge.
2927 * @param {Function} mergeFunc The function to merge values.
2928 * @param {Function} [customizer] The function to customize merging properties.
2929 * @param {Array} [stackA=[]] Tracks traversed source objects.
2930 * @param {Array} [stackB=[]] Associates values with source counterparts.
2931 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
2932 */
2933 function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
2934 var length = stackA.length,
2935 srcValue = source[key];
2936
2937 while (length--) {
2938 if (stackA[length] == srcValue) {
2939 object[key] = stackB[length];
2940 return;
2941 }
2942 }
2943 var value = object[key],
2944 result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
2945 isCommon = typeof result == 'undefined';
2946
2947 if (isCommon) {
2948 result = srcValue;
2949 if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
2950 result = isArray(value)
2951 ? value
2952 : ((value && value.length) ? arrayCopy(value) : []);
2953 }
2954 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
2955 result = isArguments(value)
2956 ? toPlainObject(value)
2957 : (isPlainObject(value) ? value : {});
2958 }
2959 else {
2960 isCommon = false;
2961 }
2962 }
2963 // Add the source value to the stack of traversed objects and associate
2964 // it with its merged value.
2965 stackA.push(srcValue);
2966 stackB.push(result);
2967
2968 if (isCommon) {
2969 // Recursively merge objects and arrays (susceptible to call stack limits).
2970 object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
2971 } else if (result === result ? (result !== value) : (value === value)) {
2972 object[key] = result;
2973 }
2974 }
2975
2976 /**
2977 * The base implementation of `_.property` which does not coerce `key` to a string.
2978 *
2979 * @private
2980 * @param {string} key The key of the property to get.
2981 * @returns {Function} Returns the new function.
2982 */
2983 function baseProperty(key) {
2984 return function(object) {
2985 return object == null ? undefined : object[key];
2986 };
2987 }
2988
2989 /**
2990 * The base implementation of `_.random` without support for argument juggling
2991 * and returning floating-point numbers.
2992 *
2993 * @private
2994 * @param {number} min The minimum possible value.
2995 * @param {number} max The maximum possible value.
2996 * @returns {number} Returns the random number.
2997 */
2998 function baseRandom(min, max) {
2999 return min + floor(nativeRandom() * (max - min + 1));
3000 }
3001
3002 /**
3003 * The base implementation of `_.reduce` and `_.reduceRight` without support
3004 * for callback shorthands and `this` binding, which iterates over `collection`
3005 * using the provided `eachFunc`.
3006 *
3007 * @private
3008 * @param {Array|Object|string} collection The collection to iterate over.
3009 * @param {Function} iteratee The function invoked per iteration.
3010 * @param {*} accumulator The initial value.
3011 * @param {boolean} initFromCollection Specify using the first or last element
3012 * of `collection` as the initial value.
3013 * @param {Function} eachFunc The function to iterate over `collection`.
3014 * @returns {*} Returns the accumulated value.
3015 */
3016 function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
3017 eachFunc(collection, function(value, index, collection) {
3018 accumulator = initFromCollection
3019 ? (initFromCollection = false, value)
3020 : iteratee(accumulator, value, index, collection);
3021 });
3022 return accumulator;
3023 }
3024
3025 /**
3026 * The base implementation of `setData` without support for hot loop detection.
3027 *
3028 * @private
3029 * @param {Function} func The function to associate metadata with.
3030 * @param {*} data The metadata.
3031 * @returns {Function} Returns `func`.
3032 */
3033 var baseSetData = !metaMap ? identity : function(func, data) {
3034 metaMap.set(func, data);
3035 return func;
3036 };
3037
3038 /**
3039 * The base implementation of `_.slice` without an iteratee call guard.
3040 *
3041 * @private
3042 * @param {Array} array The array to slice.
3043 * @param {number} [start=0] The start position.
3044 * @param {number} [end=array.length] The end position.
3045 * @returns {Array} Returns the slice of `array`.
3046 */
3047 function baseSlice(array, start, end) {
3048 var index = -1,
3049 length = array.length;
3050
3051 start = start == null ? 0 : (+start || 0);
3052 if (start < 0) {
3053 start = -start > length ? 0 : (length + start);
3054 }
3055 end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
3056 if (end < 0) {
3057 end += length;
3058 }
3059 length = start > end ? 0 : ((end - start) >>> 0);
3060 start >>>= 0;
3061
3062 var result = Array(length);
3063 while (++index < length) {
3064 result[index] = array[index + start];
3065 }
3066 return result;
3067 }
3068
3069 /**
3070 * The base implementation of `_.some` without support for callback shorthands
3071 * and `this` binding.
3072 *
3073 * @private
3074 * @param {Array|Object|string} collection The collection to iterate over.
3075 * @param {Function} predicate The function invoked per iteration.
3076 * @returns {boolean} Returns `true` if any element passes the predicate check,
3077 * else `false`.
3078 */
3079 function baseSome(collection, predicate) {
3080 var result;
3081
3082 baseEach(collection, function(value, index, collection) {
3083 result = predicate(value, index, collection);
3084 return !result;
3085 });
3086 return !!result;
3087 }
3088
3089 /**
3090 * The base implementation of `_.sortBy` which uses `comparer` to define
3091 * the sort order of `array` and replaces criteria objects with their
3092 * corresponding values.
3093 *
3094 * @private
3095 * @param {Array} array The array to sort.
3096 * @param {Function} comparer The function to define sort order.
3097 * @returns {Array} Returns `array`.
3098 */
3099 function baseSortBy(array, comparer) {
3100 var length = array.length;
3101
3102 array.sort(comparer);
3103 while (length--) {
3104 array[length] = array[length].value;
3105 }
3106 return array;
3107 }
3108
3109 /**
3110 * The base implementation of `_.sortByOrder` without param guards.
3111 *
3112 * @private
3113 * @param {Array|Object|string} collection The collection to iterate over.
3114 * @param {string[]} props The property names to sort by.
3115 * @param {boolean[]} orders The sort orders of `props`.
3116 * @returns {Array} Returns the new sorted array.
3117 */
3118 function baseSortByOrder(collection, props, orders) {
3119 var index = -1,
3120 length = collection.length,
3121 result = isLength(length) ? Array(length) : [];
3122
3123 baseEach(collection, function(value) {
3124 var length = props.length,
3125 criteria = Array(length);
3126
3127 while (length--) {
3128 criteria[length] = value == null ? undefined : value[props[length]];
3129 }
3130 result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
3131 });
3132
3133 return baseSortBy(result, function(object, other) {
3134 return compareMultiple(object, other, orders);
3135 });
3136 }
3137
3138 /**
3139 * The base implementation of `_.sum` without support for callback shorthands
3140 * and `this` binding.
3141 *
3142 * @private
3143 * @param {Array|Object|string} collection The collection to iterate over.
3144 * @param {Function} iteratee The function invoked per iteration.
3145 * @returns {number} Returns the sum.
3146 */
3147 function baseSum(collection, iteratee) {
3148 var result = 0;
3149 baseEach(collection, function(value, index, collection) {
3150 result += +iteratee(value, index, collection) || 0;
3151 });
3152 return result;
3153 }
3154
3155 /**
3156 * The base implementation of `_.uniq` without support for callback shorthands
3157 * and `this` binding.
3158 *
3159 * @private
3160 * @param {Array} array The array to inspect.
3161 * @param {Function} [iteratee] The function invoked per iteration.
3162 * @returns {Array} Returns the new duplicate-value-free array.
3163 */
3164 function baseUniq(array, iteratee) {
3165 var index = -1,
3166 indexOf = getIndexOf(),
3167 length = array.length,
3168 isCommon = indexOf == baseIndexOf,
3169 isLarge = isCommon && length >= 200,
3170 seen = isLarge ? createCache() : null,
3171 result = [];
3172
3173 if (seen) {
3174 indexOf = cacheIndexOf;
3175 isCommon = false;
3176 } else {
3177 isLarge = false;
3178 seen = iteratee ? [] : result;
3179 }
3180 outer:
3181 while (++index < length) {
3182 var value = array[index],
3183 computed = iteratee ? iteratee(value, index, array) : value;
3184
3185 if (isCommon && value === value) {
3186 var seenIndex = seen.length;
3187 while (seenIndex--) {
3188 if (seen[seenIndex] === computed) {
3189 continue outer;
3190 }
3191 }
3192 if (iteratee) {
3193 seen.push(computed);
3194 }
3195 result.push(value);
3196 }
3197 else if (indexOf(seen, computed, 0) < 0) {
3198 if (iteratee || isLarge) {
3199 seen.push(computed);
3200 }
3201 result.push(value);
3202 }
3203 }
3204 return result;
3205 }
3206
3207 /**
3208 * The base implementation of `_.values` and `_.valuesIn` which creates an
3209 * array of `object` property values corresponding to the property names
3210 * returned by `keysFunc`.
3211 *
3212 * @private
3213 * @param {Object} object The object to query.
3214 * @param {Array} props The property names to get values for.
3215 * @returns {Object} Returns the array of property values.
3216 */
3217 function baseValues(object, props) {
3218 var index = -1,
3219 length = props.length,
3220 result = Array(length);
3221
3222 while (++index < length) {
3223 result[index] = object[props[index]];
3224 }
3225 return result;
3226 }
3227
3228 /**
3229 * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
3230 * and `_.takeWhile` without support for callback shorthands and `this` binding.
3231 *
3232 * @private
3233 * @param {Array} array The array to query.
3234 * @param {Function} predicate The function invoked per iteration.
3235 * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
3236 * @param {boolean} [fromRight] Specify iterating from right to left.
3237 * @returns {Array} Returns the slice of `array`.
3238 */
3239 function baseWhile(array, predicate, isDrop, fromRight) {
3240 var length = array.length,
3241 index = fromRight ? length : -1;
3242
3243 while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
3244 return isDrop
3245 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
3246 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
3247 }
3248
3249 /**
3250 * The base implementation of `wrapperValue` which returns the result of
3251 * performing a sequence of actions on the unwrapped `value`, where each
3252 * successive action is supplied the return value of the previous.
3253 *
3254 * @private
3255 * @param {*} value The unwrapped value.
3256 * @param {Array} actions Actions to peform to resolve the unwrapped value.
3257 * @returns {*} Returns the resolved value.
3258 */
3259 function baseWrapperValue(value, actions) {
3260 var result = value;
3261 if (result instanceof LazyWrapper) {
3262 result = result.value();
3263 }
3264 var index = -1,
3265 length = actions.length;
3266
3267 while (++index < length) {
3268 var args = [result],
3269 action = actions[index];
3270
3271 push.apply(args, action.args);
3272 result = action.func.apply(action.thisArg, args);
3273 }
3274 return result;
3275 }
3276
3277 /**
3278 * Performs a binary search of `array` to determine the index at which `value`
3279 * should be inserted into `array` in order to maintain its sort order.
3280 *
3281 * @private
3282 * @param {Array} array The sorted array to inspect.
3283 * @param {*} value The value to evaluate.
3284 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3285 * @returns {number} Returns the index at which `value` should be inserted
3286 * into `array`.
3287 */
3288 function binaryIndex(array, value, retHighest) {
3289 var low = 0,
3290 high = array ? array.length : low;
3291
3292 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
3293 while (low < high) {
3294 var mid = (low + high) >>> 1,
3295 computed = array[mid];
3296
3297 if (retHighest ? (computed <= value) : (computed < value)) {
3298 low = mid + 1;
3299 } else {
3300 high = mid;
3301 }
3302 }
3303 return high;
3304 }
3305 return binaryIndexBy(array, value, identity, retHighest);
3306 }
3307
3308 /**
3309 * This function is like `binaryIndex` except that it invokes `iteratee` for
3310 * `value` and each element of `array` to compute their sort ranking. The
3311 * iteratee is invoked with one argument; (value).
3312 *
3313 * @private
3314 * @param {Array} array The sorted array to inspect.
3315 * @param {*} value The value to evaluate.
3316 * @param {Function} iteratee The function invoked per iteration.
3317 * @param {boolean} [retHighest] Specify returning the highest qualified index.
3318 * @returns {number} Returns the index at which `value` should be inserted
3319 * into `array`.
3320 */
3321 function binaryIndexBy(array, value, iteratee, retHighest) {
3322 value = iteratee(value);
3323
3324 var low = 0,
3325 high = array ? array.length : 0,
3326 valIsNaN = value !== value,
3327 valIsUndef = typeof value == 'undefined';
3328
3329 while (low < high) {
3330 var mid = floor((low + high) / 2),
3331 computed = iteratee(array[mid]),
3332 isReflexive = computed === computed;
3333
3334 if (valIsNaN) {
3335 var setLow = isReflexive || retHighest;
3336 } else if (valIsUndef) {
3337 setLow = isReflexive && (retHighest || typeof computed != 'undefined');
3338 } else {
3339 setLow = retHighest ? (computed <= value) : (computed < value);
3340 }
3341 if (setLow) {
3342 low = mid + 1;
3343 } else {
3344 high = mid;
3345 }
3346 }
3347 return nativeMin(high, MAX_ARRAY_INDEX);
3348 }
3349
3350 /**
3351 * A specialized version of `baseCallback` which only supports `this` binding
3352 * and specifying the number of arguments to provide to `func`.
3353 *
3354 * @private
3355 * @param {Function} func The function to bind.
3356 * @param {*} thisArg The `this` binding of `func`.
3357 * @param {number} [argCount] The number of arguments to provide to `func`.
3358 * @returns {Function} Returns the callback.
3359 */
3360 function bindCallback(func, thisArg, argCount) {
3361 if (typeof func != 'function') {
3362 return identity;
3363 }
3364 if (typeof thisArg == 'undefined') {
3365 return func;
3366 }
3367 switch (argCount) {
3368 case 1: return function(value) {
3369 return func.call(thisArg, value);
3370 };
3371 case 3: return function(value, index, collection) {
3372 return func.call(thisArg, value, index, collection);
3373 };
3374 case 4: return function(accumulator, value, index, collection) {
3375 return func.call(thisArg, accumulator, value, index, collection);
3376 };
3377 case 5: return function(value, other, key, object, source) {
3378 return func.call(thisArg, value, other, key, object, source);
3379 };
3380 }
3381 return function() {
3382 return func.apply(thisArg, arguments);
3383 };
3384 }
3385
3386 /**
3387 * Creates a clone of the given array buffer.
3388 *
3389 * @private
3390 * @param {ArrayBuffer} buffer The array buffer to clone.
3391 * @returns {ArrayBuffer} Returns the cloned array buffer.
3392 */
3393 function bufferClone(buffer) {
3394 return bufferSlice.call(buffer, 0);
3395 }
3396 if (!bufferSlice) {
3397 // PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array`.
3398 bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buffer) {
3399 var byteLength = buffer.byteLength,
3400 floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0,
3401 offset = floatLength * FLOAT64_BYTES_PER_ELEMENT,
3402 result = new ArrayBuffer(byteLength);
3403
3404 if (floatLength) {
3405 var view = new Float64Array(result, 0, floatLength);
3406 view.set(new Float64Array(buffer, 0, floatLength));
3407 }
3408 if (byteLength != offset) {
3409 view = new Uint8Array(result, offset);
3410 view.set(new Uint8Array(buffer, offset));
3411 }
3412 return result;
3413 };
3414 }
3415
3416 /**
3417 * Creates an array that is the composition of partially applied arguments,
3418 * placeholders, and provided arguments into a single array of arguments.
3419 *
3420 * @private
3421 * @param {Array|Object} args The provided arguments.
3422 * @param {Array} partials The arguments to prepend to those provided.
3423 * @param {Array} holders The `partials` placeholder indexes.
3424 * @returns {Array} Returns the new array of composed arguments.
3425 */
3426 function composeArgs(args, partials, holders) {
3427 var holdersLength = holders.length,
3428 argsIndex = -1,
3429 argsLength = nativeMax(args.length - holdersLength, 0),
3430 leftIndex = -1,
3431 leftLength = partials.length,
3432 result = Array(argsLength + leftLength);
3433
3434 while (++leftIndex < leftLength) {
3435 result[leftIndex] = partials[leftIndex];
3436 }
3437 while (++argsIndex < holdersLength) {
3438 result[holders[argsIndex]] = args[argsIndex];
3439 }
3440 while (argsLength--) {
3441 result[leftIndex++] = args[argsIndex++];
3442 }
3443 return result;
3444 }
3445
3446 /**
3447 * This function is like `composeArgs` except that the arguments composition
3448 * is tailored for `_.partialRight`.
3449 *
3450 * @private
3451 * @param {Array|Object} args The provided arguments.
3452 * @param {Array} partials The arguments to append to those provided.
3453 * @param {Array} holders The `partials` placeholder indexes.
3454 * @returns {Array} Returns the new array of composed arguments.
3455 */
3456 function composeArgsRight(args, partials, holders) {
3457 var holdersIndex = -1,
3458 holdersLength = holders.length,
3459 argsIndex = -1,
3460 argsLength = nativeMax(args.length - holdersLength, 0),
3461 rightIndex = -1,
3462 rightLength = partials.length,
3463 result = Array(argsLength + rightLength);
3464
3465 while (++argsIndex < argsLength) {
3466 result[argsIndex] = args[argsIndex];
3467 }
3468 var pad = argsIndex;
3469 while (++rightIndex < rightLength) {
3470 result[pad + rightIndex] = partials[rightIndex];
3471 }
3472 while (++holdersIndex < holdersLength) {
3473 result[pad + holders[holdersIndex]] = args[argsIndex++];
3474 }
3475 return result;
3476 }
3477
3478 /**
3479 * Creates a function that aggregates a collection, creating an accumulator
3480 * object composed from the results of running each element in the collection
3481 * through an iteratee.
3482 *
3483 * **Note:** This function is used to create `_.countBy`, `_.groupBy`, `_.indexBy`,
3484 * and `_.partition`.
3485 *
3486 * @private
3487 * @param {Function} setter The function to set keys and values of the accumulator object.
3488 * @param {Function} [initializer] The function to initialize the accumulator object.
3489 * @returns {Function} Returns the new aggregator function.
3490 */
3491 function createAggregator(setter, initializer) {
3492 return function(collection, iteratee, thisArg) {
3493 var result = initializer ? initializer() : {};
3494 iteratee = getCallback(iteratee, thisArg, 3);
3495
3496 if (isArray(collection)) {
3497 var index = -1,
3498 length = collection.length;
3499
3500 while (++index < length) {
3501 var value = collection[index];
3502 setter(result, value, iteratee(value, index, collection), collection);
3503 }
3504 } else {
3505 baseEach(collection, function(value, key, collection) {
3506 setter(result, value, iteratee(value, key, collection), collection);
3507 });
3508 }
3509 return result;
3510 };
3511 }
3512
3513 /**
3514 * Creates a function that assigns properties of source object(s) to a given
3515 * destination object.
3516 *
3517 * **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`.
3518 *
3519 * @private
3520 * @param {Function} assigner The function to assign values.
3521 * @returns {Function} Returns the new assigner function.
3522 */
3523 function createAssigner(assigner) {
3524 return function() {
3525 var args = arguments,
3526 length = args.length,
3527 object = args[0];
3528
3529 if (length < 2 || object == null) {
3530 return object;
3531 }
3532 var customizer = args[length - 2],
3533 thisArg = args[length - 1],
3534 guard = args[3];
3535
3536 if (length > 3 && typeof customizer == 'function') {
3537 customizer = bindCallback(customizer, thisArg, 5);
3538 length -= 2;
3539 } else {
3540 customizer = (length > 2 && typeof thisArg == 'function') ? thisArg : null;
3541 length -= (customizer ? 1 : 0);
3542 }
3543 if (guard && isIterateeCall(args[1], args[2], guard)) {
3544 customizer = length == 3 ? null : customizer;
3545 length = 2;
3546 }
3547 var index = 0;
3548 while (++index < length) {
3549 var source = args[index];
3550 if (source) {
3551 assigner(object, source, customizer);
3552 }
3553 }
3554 return object;
3555 };
3556 }
3557
3558 /**
3559 * Creates a `baseEach` or `baseEachRight` function.
3560 *
3561 * @private
3562 * @param {Function} eachFunc The function to iterate over a collection.
3563 * @param {boolean} [fromRight] Specify iterating from right to left.
3564 * @returns {Function} Returns the new base function.
3565 */
3566 function createBaseEach(eachFunc, fromRight) {
3567 return function(collection, iteratee) {
3568 var length = collection ? collection.length : 0;
3569 if (!isLength(length)) {
3570 return eachFunc(collection, iteratee);
3571 }
3572 var index = fromRight ? length : -1,
3573 iterable = toObject(collection);
3574
3575 while ((fromRight ? index-- : ++index < length)) {
3576 if (iteratee(iterable[index], index, iterable) === false) {
3577 break;
3578 }
3579 }
3580 return collection;
3581 };
3582 }
3583
3584 /**
3585 * Creates a base function for `_.forIn` or `_.forInRight`.
3586 *
3587 * @private
3588 * @param {boolean} [fromRight] Specify iterating from right to left.
3589 * @returns {Function} Returns the new base function.
3590 */
3591 function createBaseFor(fromRight) {
3592 return function(object, iteratee, keysFunc) {
3593 var iterable = toObject(object),
3594 props = keysFunc(object),
3595 length = props.length,
3596 index = fromRight ? length : -1;
3597
3598 while ((fromRight ? index-- : ++index < length)) {
3599 var key = props[index];
3600 if (iteratee(iterable[key], key, iterable) === false) {
3601 break;
3602 }
3603 }
3604 return object;
3605 };
3606 }
3607
3608 /**
3609 * Creates a function that wraps `func` and invokes it with the `this`
3610 * binding of `thisArg`.
3611 *
3612 * @private
3613 * @param {Function} func The function to bind.
3614 * @param {*} [thisArg] The `this` binding of `func`.
3615 * @returns {Function} Returns the new bound function.
3616 */
3617 function createBindWrapper(func, thisArg) {
3618 var Ctor = createCtorWrapper(func);
3619
3620 function wrapper() {
3621 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
3622 return fn.apply(thisArg, arguments);
3623 }
3624 return wrapper;
3625 }
3626
3627 /**
3628 * Creates a `Set` cache object to optimize linear searches of large arrays.
3629 *
3630 * @private
3631 * @param {Array} [values] The values to cache.
3632 * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
3633 */
3634 var createCache = !(nativeCreate && Set) ? constant(null) : function(values) {
3635 return new SetCache(values);
3636 };
3637
3638 /**
3639 * Creates a function that produces compound words out of the words in a
3640 * given string.
3641 *
3642 * @private
3643 * @param {Function} callback The function to combine each word.
3644 * @returns {Function} Returns the new compounder function.
3645 */
3646 function createCompounder(callback) {
3647 return function(string) {
3648 var index = -1,
3649 array = words(deburr(string)),
3650 length = array.length,
3651 result = '';
3652
3653 while (++index < length) {
3654 result = callback(result, array[index], index);
3655 }
3656 return result;
3657 };
3658 }
3659
3660 /**
3661 * Creates a function that produces an instance of `Ctor` regardless of
3662 * whether it was invoked as part of a `new` expression or by `call` or `apply`.
3663 *
3664 * @private
3665 * @param {Function} Ctor The constructor to wrap.
3666 * @returns {Function} Returns the new wrapped function.
3667 */
3668 function createCtorWrapper(Ctor) {
3669 return function() {
3670 var thisBinding = baseCreate(Ctor.prototype),
3671 result = Ctor.apply(thisBinding, arguments);
3672
3673 // Mimic the constructor's `return` behavior.
3674 // See https://es5.github.io/#x13.2.2 for more details.
3675 return isObject(result) ? result : thisBinding;
3676 };
3677 }
3678
3679 /**
3680 * Creates a `_.curry` or `_.curryRight` function.
3681 *
3682 * @private
3683 * @param {boolean} flag The curry bit flag.
3684 * @returns {Function} Returns the new curry function.
3685 */
3686 function createCurry(flag) {
3687 function curryFunc(func, arity, guard) {
3688 if (guard && isIterateeCall(func, arity, guard)) {
3689 arity = null;
3690 }
3691 var result = createWrapper(func, flag, null, null, null, null, null, arity);
3692 result.placeholder = curryFunc.placeholder;
3693 return result;
3694 }
3695 return curryFunc;
3696 }
3697
3698 /**
3699 * Creates a `_.max` or `_.min` function.
3700 *
3701 * @private
3702 * @param {Function} arrayFunc The function to get the extremum value from an array.
3703 * @param {boolean} [isMin] Specify returning the minimum, instead of the maximum,
3704 * extremum value.
3705 * @returns {Function} Returns the new extremum function.
3706 */
3707 function createExtremum(arrayFunc, isMin) {
3708 return function(collection, iteratee, thisArg) {
3709 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
3710 iteratee = null;
3711 }
3712 var func = getCallback(),
3713 noIteratee = iteratee == null;
3714
3715 if (!(func === baseCallback && noIteratee)) {
3716 noIteratee = false;
3717 iteratee = func(iteratee, thisArg, 3);
3718 }
3719 if (noIteratee) {
3720 var isArr = isArray(collection);
3721 if (!isArr && isString(collection)) {
3722 iteratee = charAtCallback;
3723 } else {
3724 return arrayFunc(isArr ? collection : toIterable(collection));
3725 }
3726 }
3727 return extremumBy(collection, iteratee, isMin);
3728 };
3729 }
3730
3731 /**
3732 * Creates a `_.find` or `_.findLast` function.
3733 *
3734 * @private
3735 * @param {Function} eachFunc The function to iterate over a collection.
3736 * @param {boolean} [fromRight] Specify iterating from right to left.
3737 * @returns {Function} Returns the new find function.
3738 */
3739 function createFind(eachFunc, fromRight) {
3740 return function(collection, predicate, thisArg) {
3741 predicate = getCallback(predicate, thisArg, 3);
3742 if (isArray(collection)) {
3743 var index = baseFindIndex(collection, predicate, fromRight);
3744 return index > -1 ? collection[index] : undefined;
3745 }
3746 return baseFind(collection, predicate, eachFunc);
3747 }
3748 }
3749
3750 /**
3751 * Creates a `_.findIndex` or `_.findLastIndex` function.
3752 *
3753 * @private
3754 * @param {boolean} [fromRight] Specify iterating from right to left.
3755 * @returns {Function} Returns the new find function.
3756 */
3757 function createFindIndex(fromRight) {
3758 return function(array, predicate, thisArg) {
3759 if (!(array && array.length)) {
3760 return -1;
3761 }
3762 predicate = getCallback(predicate, thisArg, 3);
3763 return baseFindIndex(array, predicate, fromRight);
3764 };
3765 }
3766
3767 /**
3768 * Creates a `_.findKey` or `_.findLastKey` function.
3769 *
3770 * @private
3771 * @param {Function} objectFunc The function to iterate over an object.
3772 * @returns {Function} Returns the new find function.
3773 */
3774 function createFindKey(objectFunc) {
3775 return function(object, predicate, thisArg) {
3776 predicate = getCallback(predicate, thisArg, 3);
3777 return baseFind(object, predicate, objectFunc, true);
3778 };
3779 }
3780
3781 /**
3782 * Creates a `_.flow` or `_.flowRight` function.
3783 *
3784 * @private
3785 * @param {boolean} [fromRight] Specify iterating from right to left.
3786 * @returns {Function} Returns the new flow function.
3787 */
3788 function createFlow(fromRight) {
3789 return function() {
3790 var length = arguments.length;
3791 if (!length) {
3792 return function() { return arguments[0]; };
3793 }
3794 var wrapper,
3795 index = fromRight ? length : -1,
3796 leftIndex = 0,
3797 funcs = Array(length);
3798
3799 while ((fromRight ? index-- : ++index < length)) {
3800 var func = funcs[leftIndex++] = arguments[index];
3801 if (typeof func != 'function') {
3802 throw new TypeError(FUNC_ERROR_TEXT);
3803 }
3804 var funcName = wrapper ? '' : getFuncName(func);
3805 wrapper = funcName == 'wrapper' ? new LodashWrapper([]) : wrapper;
3806 }
3807 index = wrapper ? -1 : length;
3808 while (++index < length) {
3809 func = funcs[index];
3810 funcName = getFuncName(func);
3811
3812 var data = funcName == 'wrapper' ? getData(func) : null;
3813 if (data && isLaziable(data[0])) {
3814 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
3815 } else {
3816 wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
3817 }
3818 }
3819 return function() {
3820 var args = arguments;
3821 if (wrapper && args.length == 1 && isArray(args[0])) {
3822 return wrapper.plant(args[0]).value();
3823 }
3824 var index = 0,
3825 result = funcs[index].apply(this, args);
3826
3827 while (++index < length) {
3828 result = funcs[index].call(this, result);
3829 }
3830 return result;
3831 };
3832 };
3833 }
3834
3835 /**
3836 * Creates a function for `_.forEach` or `_.forEachRight`.
3837 *
3838 * @private
3839 * @param {Function} arrayFunc The function to iterate over an array.
3840 * @param {Function} eachFunc The function to iterate over a collection.
3841 * @returns {Function} Returns the new each function.
3842 */
3843 function createForEach(arrayFunc, eachFunc) {
3844 return function(collection, iteratee, thisArg) {
3845 return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
3846 ? arrayFunc(collection, iteratee)
3847 : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
3848 };
3849 }
3850
3851 /**
3852 * Creates a function for `_.forIn` or `_.forInRight`.
3853 *
3854 * @private
3855 * @param {Function} objectFunc The function to iterate over an object.
3856 * @returns {Function} Returns the new each function.
3857 */
3858 function createForIn(objectFunc) {
3859 return function(object, iteratee, thisArg) {
3860 if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
3861 iteratee = bindCallback(iteratee, thisArg, 3);
3862 }
3863 return objectFunc(object, iteratee, keysIn);
3864 };
3865 }
3866
3867 /**
3868 * Creates a function for `_.forOwn` or `_.forOwnRight`.
3869 *
3870 * @private
3871 * @param {Function} objectFunc The function to iterate over an object.
3872 * @returns {Function} Returns the new each function.
3873 */
3874 function createForOwn(objectFunc) {
3875 return function(object, iteratee, thisArg) {
3876 if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
3877 iteratee = bindCallback(iteratee, thisArg, 3);
3878 }
3879 return objectFunc(object, iteratee);
3880 };
3881 }
3882
3883 /**
3884 * Creates a function for `_.padLeft` or `_.padRight`.
3885 *
3886 * @private
3887 * @param {boolean} [fromRight] Specify padding from the right.
3888 * @returns {Function} Returns the new pad function.
3889 */
3890 function createPadDir(fromRight) {
3891 return function(string, length, chars) {
3892 string = baseToString(string);
3893 return string && ((fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string));
3894 };
3895 }
3896
3897 /**
3898 * Creates a `_.partial` or `_.partialRight` function.
3899 *
3900 * @private
3901 * @param {boolean} flag The partial bit flag.
3902 * @returns {Function} Returns the new partial function.
3903 */
3904 function createPartial(flag) {
3905 var partialFunc = restParam(function(func, partials) {
3906 var holders = replaceHolders(partials, partialFunc.placeholder);
3907 return createWrapper(func, flag, null, partials, holders);
3908 });
3909 return partialFunc;
3910 }
3911
3912 /**
3913 * Creates a function for `_.reduce` or `_.reduceRight`.
3914 *
3915 * @private
3916 * @param {Function} arrayFunc The function to iterate over an array.
3917 * @param {Function} eachFunc The function to iterate over a collection.
3918 * @returns {Function} Returns the new each function.
3919 */
3920 function createReduce(arrayFunc, eachFunc) {
3921 return function(collection, iteratee, accumulator, thisArg) {
3922 var initFromArray = arguments.length < 3;
3923 return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
3924 ? arrayFunc(collection, iteratee, accumulator, initFromArray)
3925 : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
3926 };
3927 }
3928
3929 /**
3930 * Creates a function that wraps `func` and invokes it with optional `this`
3931 * binding of, partial application, and currying.
3932 *
3933 * @private
3934 * @param {Function|string} func The function or method name to reference.
3935 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
3936 * @param {*} [thisArg] The `this` binding of `func`.
3937 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
3938 * @param {Array} [holders] The `partials` placeholder indexes.
3939 * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
3940 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
3941 * @param {Array} [argPos] The argument positions of the new function.
3942 * @param {number} [ary] The arity cap of `func`.
3943 * @param {number} [arity] The arity of `func`.
3944 * @returns {Function} Returns the new wrapped function.
3945 */
3946 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
3947 var isAry = bitmask & ARY_FLAG,
3948 isBind = bitmask & BIND_FLAG,
3949 isBindKey = bitmask & BIND_KEY_FLAG,
3950 isCurry = bitmask & CURRY_FLAG,
3951 isCurryBound = bitmask & CURRY_BOUND_FLAG,
3952 isCurryRight = bitmask & CURRY_RIGHT_FLAG;
3953
3954 var Ctor = !isBindKey && createCtorWrapper(func),
3955 key = func;
3956
3957 function wrapper() {
3958 // Avoid `arguments` object use disqualifying optimizations by
3959 // converting it to an array before providing it to other functions.
3960 var length = arguments.length,
3961 index = length,
3962 args = Array(length);
3963
3964 while (index--) {
3965 args[index] = arguments[index];
3966 }
3967 if (partials) {
3968 args = composeArgs(args, partials, holders);
3969 }
3970 if (partialsRight) {
3971 args = composeArgsRight(args, partialsRight, holdersRight);
3972 }
3973 if (isCurry || isCurryRight) {
3974 var placeholder = wrapper.placeholder,
3975 argsHolders = replaceHolders(args, placeholder);
3976
3977 length -= argsHolders.length;
3978 if (length < arity) {
3979 var newArgPos = argPos ? arrayCopy(argPos) : null,
3980 newArity = nativeMax(arity - length, 0),
3981 newsHolders = isCurry ? argsHolders : null,
3982 newHoldersRight = isCurry ? null : argsHolders,
3983 newPartials = isCurry ? args : null,
3984 newPartialsRight = isCurry ? null : args;
3985
3986 bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
3987 bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
3988
3989 if (!isCurryBound) {
3990 bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
3991 }
3992 var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
3993 result = createHybridWrapper.apply(undefined, newData);
3994
3995 if (isLaziable(func)) {
3996 setData(result, newData);
3997 }
3998 result.placeholder = placeholder;
3999 return result;
4000 }
4001 }
4002 var thisBinding = isBind ? thisArg : this;
4003 if (isBindKey) {
4004 func = thisBinding[key];
4005 }
4006 if (argPos) {
4007 args = reorder(args, argPos);
4008 }
4009 if (isAry && ary < args.length) {
4010 args.length = ary;
4011 }
4012 var fn = (this && this !== root && this instanceof wrapper) ? (Ctor || createCtorWrapper(func)) : func;
4013 return fn.apply(thisBinding, args);
4014 }
4015 return wrapper;
4016 }
4017
4018 /**
4019 * Creates the padding required for `string` based on the given `length`.
4020 * The `chars` string is truncated if the number of characters exceeds `length`.
4021 *
4022 * @private
4023 * @param {string} string The string to create padding for.
4024 * @param {number} [length=0] The padding length.
4025 * @param {string} [chars=' '] The string used as padding.
4026 * @returns {string} Returns the pad for `string`.
4027 */
4028 function createPadding(string, length, chars) {
4029 var strLength = string.length;
4030 length = +length;
4031
4032 if (strLength >= length || !nativeIsFinite(length)) {
4033 return '';
4034 }
4035 var padLength = length - strLength;
4036 chars = chars == null ? ' ' : (chars + '');
4037 return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
4038 }
4039
4040 /**
4041 * Creates a function that wraps `func` and invokes it with the optional `this`
4042 * binding of `thisArg` and the `partials` prepended to those provided to
4043 * the wrapper.
4044 *
4045 * @private
4046 * @param {Function} func The function to partially apply arguments to.
4047 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
4048 * @param {*} thisArg The `this` binding of `func`.
4049 * @param {Array} partials The arguments to prepend to those provided to the new function.
4050 * @returns {Function} Returns the new bound function.
4051 */
4052 function createPartialWrapper(func, bitmask, thisArg, partials) {
4053 var isBind = bitmask & BIND_FLAG,
4054 Ctor = createCtorWrapper(func);
4055
4056 function wrapper() {
4057 // Avoid `arguments` object use disqualifying optimizations by
4058 // converting it to an array before providing it `func`.
4059 var argsIndex = -1,
4060 argsLength = arguments.length,
4061 leftIndex = -1,
4062 leftLength = partials.length,
4063 args = Array(argsLength + leftLength);
4064
4065 while (++leftIndex < leftLength) {
4066 args[leftIndex] = partials[leftIndex];
4067 }
4068 while (argsLength--) {
4069 args[leftIndex++] = arguments[++argsIndex];
4070 }
4071 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
4072 return fn.apply(isBind ? thisArg : this, args);
4073 }
4074 return wrapper;
4075 }
4076
4077 /**
4078 * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
4079 *
4080 * @private
4081 * @param {boolean} [retHighest] Specify returning the highest qualified index.
4082 * @returns {Function} Returns the new index function.
4083 */
4084 function createSortedIndex(retHighest) {
4085 return function(array, value, iteratee, thisArg) {
4086 var func = getCallback(iteratee);
4087 return (func === baseCallback && iteratee == null)
4088 ? binaryIndex(array, value, retHighest)
4089 : binaryIndexBy(array, value, func(iteratee, thisArg, 1), retHighest);
4090 };
4091 }
4092
4093 /**
4094 * Creates a function that either curries or invokes `func` with optional
4095 * `this` binding and partially applied arguments.
4096 *
4097 * @private
4098 * @param {Function|string} func The function or method name to reference.
4099 * @param {number} bitmask The bitmask of flags.
4100 * The bitmask may be composed of the following flags:
4101 * 1 - `_.bind`
4102 * 2 - `_.bindKey`
4103 * 4 - `_.curry` or `_.curryRight` of a bound function
4104 * 8 - `_.curry`
4105 * 16 - `_.curryRight`
4106 * 32 - `_.partial`
4107 * 64 - `_.partialRight`
4108 * 128 - `_.rearg`
4109 * 256 - `_.ary`
4110 * @param {*} [thisArg] The `this` binding of `func`.
4111 * @param {Array} [partials] The arguments to be partially applied.
4112 * @param {Array} [holders] The `partials` placeholder indexes.
4113 * @param {Array} [argPos] The argument positions of the new function.
4114 * @param {number} [ary] The arity cap of `func`.
4115 * @param {number} [arity] The arity of `func`.
4116 * @returns {Function} Returns the new wrapped function.
4117 */
4118 function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
4119 var isBindKey = bitmask & BIND_KEY_FLAG;
4120 if (!isBindKey && typeof func != 'function') {
4121 throw new TypeError(FUNC_ERROR_TEXT);
4122 }
4123 var length = partials ? partials.length : 0;
4124 if (!length) {
4125 bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
4126 partials = holders = null;
4127 }
4128 length -= (holders ? holders.length : 0);
4129 if (bitmask & PARTIAL_RIGHT_FLAG) {
4130 var partialsRight = partials,
4131 holdersRight = holders;
4132
4133 partials = holders = null;
4134 }
4135 var data = isBindKey ? null : getData(func),
4136 newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
4137
4138 if (data) {
4139 mergeData(newData, data);
4140 bitmask = newData[1];
4141 arity = newData[9];
4142 }
4143 newData[9] = arity == null
4144 ? (isBindKey ? 0 : func.length)
4145 : (nativeMax(arity - length, 0) || 0);
4146
4147 if (bitmask == BIND_FLAG) {
4148 var result = createBindWrapper(newData[0], newData[2]);
4149 } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
4150 result = createPartialWrapper.apply(undefined, newData);
4151 } else {
4152 result = createHybridWrapper.apply(undefined, newData);
4153 }
4154 var setter = data ? baseSetData : setData;
4155 return setter(result, newData);
4156 }
4157
4158 /**
4159 * A specialized version of `baseIsEqualDeep` for arrays with support for
4160 * partial deep comparisons.
4161 *
4162 * @private
4163 * @param {Array} array The array to compare.
4164 * @param {Array} other The other array to compare.
4165 * @param {Function} equalFunc The function to determine equivalents of values.
4166 * @param {Function} [customizer] The function to customize comparing arrays.
4167 * @param {boolean} [isLoose] Specify performing partial comparisons.
4168 * @param {Array} [stackA] Tracks traversed `value` objects.
4169 * @param {Array} [stackB] Tracks traversed `other` objects.
4170 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
4171 */
4172 function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
4173 var index = -1,
4174 arrLength = array.length,
4175 othLength = other.length,
4176 result = true;
4177
4178 if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
4179 return false;
4180 }
4181 // Deep compare the contents, ignoring non-numeric properties.
4182 while (result && ++index < arrLength) {
4183 var arrValue = array[index],
4184 othValue = other[index];
4185
4186 result = undefined;
4187 if (customizer) {
4188 result = isLoose
4189 ? customizer(othValue, arrValue, index)
4190 : customizer(arrValue, othValue, index);
4191 }
4192 if (typeof result == 'undefined') {
4193 // Recursively compare arrays (susceptible to call stack limits).
4194 if (isLoose) {
4195 var othIndex = othLength;
4196 while (othIndex--) {
4197 othValue = other[othIndex];
4198 result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
4199 if (result) {
4200 break;
4201 }
4202 }
4203 } else {
4204 result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
4205 }
4206 }
4207 }
4208 return !!result;
4209 }
4210
4211 /**
4212 * A specialized version of `baseIsEqualDeep` for comparing objects of
4213 * the same `toStringTag`.
4214 *
4215 * **Note:** This function only supports comparing values with tags of
4216 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4217 *
4218 * @private
4219 * @param {Object} value The object to compare.
4220 * @param {Object} other The other object to compare.
4221 * @param {string} tag The `toStringTag` of the objects to compare.
4222 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
4223 */
4224 function equalByTag(object, other, tag) {
4225 switch (tag) {
4226 case boolTag:
4227 case dateTag:
4228 // Coerce dates and booleans to numbers, dates to milliseconds and booleans
4229 // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
4230 return +object == +other;
4231
4232 case errorTag:
4233 return object.name == other.name && object.message == other.message;
4234
4235 case numberTag:
4236 // Treat `NaN` vs. `NaN` as equal.
4237 return (object != +object)
4238 ? other != +other
4239 // But, treat `-0` vs. `+0` as not equal.
4240 : (object == 0 ? ((1 / object) == (1 / other)) : object == +other);
4241
4242 case regexpTag:
4243 case stringTag:
4244 // Coerce regexes to strings and treat strings primitives and string
4245 // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
4246 return object == (other + '');
4247 }
4248 return false;
4249 }
4250
4251 /**
4252 * A specialized version of `baseIsEqualDeep` for objects with support for
4253 * partial deep comparisons.
4254 *
4255 * @private
4256 * @param {Object} object The object to compare.
4257 * @param {Object} other The other object to compare.
4258 * @param {Function} equalFunc The function to determine equivalents of values.
4259 * @param {Function} [customizer] The function to customize comparing values.
4260 * @param {boolean} [isLoose] Specify performing partial comparisons.
4261 * @param {Array} [stackA] Tracks traversed `value` objects.
4262 * @param {Array} [stackB] Tracks traversed `other` objects.
4263 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
4264 */
4265 function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
4266 var objProps = keys(object),
4267 objLength = objProps.length,
4268 othProps = keys(other),
4269 othLength = othProps.length;
4270
4271 if (objLength != othLength && !isLoose) {
4272 return false;
4273 }
4274 var skipCtor = isLoose,
4275 index = -1;
4276
4277 while (++index < objLength) {
4278 var key = objProps[index],
4279 result = isLoose ? key in other : hasOwnProperty.call(other, key);
4280
4281 if (result) {
4282 var objValue = object[key],
4283 othValue = other[key];
4284
4285 result = undefined;
4286 if (customizer) {
4287 result = isLoose
4288 ? customizer(othValue, objValue, key)
4289 : customizer(objValue, othValue, key);
4290 }
4291 if (typeof result == 'undefined') {
4292 // Recursively compare objects (susceptible to call stack limits).
4293 result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB);
4294 }
4295 }
4296 if (!result) {
4297 return false;
4298 }
4299 skipCtor || (skipCtor = key == 'constructor');
4300 }
4301 if (!skipCtor) {
4302 var objCtor = object.constructor,
4303 othCtor = other.constructor;
4304
4305 // Non `Object` object instances with different constructors are not equal.
4306 if (objCtor != othCtor &&
4307 ('constructor' in object && 'constructor' in other) &&
4308 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
4309 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
4310 return false;
4311 }
4312 }
4313 return true;
4314 }
4315
4316 /**
4317 * Gets the extremum value of `collection` invoking `iteratee` for each value
4318 * in `collection` to generate the criterion by which the value is ranked.
4319 * The `iteratee` is invoked with three arguments: (value, index, collection).
4320 *
4321 * @private
4322 * @param {Array|Object|string} collection The collection to iterate over.
4323 * @param {Function} iteratee The function invoked per iteration.
4324 * @param {boolean} [isMin] Specify returning the minimum, instead of the
4325 * maximum, extremum value.
4326 * @returns {*} Returns the extremum value.
4327 */
4328 function extremumBy(collection, iteratee, isMin) {
4329 var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY,
4330 computed = exValue,
4331 result = computed;
4332
4333 baseEach(collection, function(value, index, collection) {
4334 var current = iteratee(value, index, collection);
4335 if ((isMin ? (current < computed) : (current > computed)) ||
4336 (current === exValue && current === result)) {
4337 computed = current;
4338 result = value;
4339 }
4340 });
4341 return result;
4342 }
4343
4344 /**
4345 * Gets the appropriate "callback" function. If the `_.callback` method is
4346 * customized this function returns the custom method, otherwise it returns
4347 * the `baseCallback` function. If arguments are provided the chosen function
4348 * is invoked with them and its result is returned.
4349 *
4350 * @private
4351 * @returns {Function} Returns the chosen function or its result.
4352 */
4353 function getCallback(func, thisArg, argCount) {
4354 var result = lodash.callback || callback;
4355 result = result === callback ? baseCallback : result;
4356 return argCount ? result(func, thisArg, argCount) : result;
4357 }
4358
4359 /**
4360 * Gets metadata for `func`.
4361 *
4362 * @private
4363 * @param {Function} func The function to query.
4364 * @returns {*} Returns the metadata for `func`.
4365 */
4366 var getData = !metaMap ? noop : function(func) {
4367 return metaMap.get(func);
4368 };
4369
4370 /**
4371 * Gets the name of `func`.
4372 *
4373 * @private
4374 * @param {Function} func The function to query.
4375 * @returns {string} Returns the function name.
4376 */
4377 var getFuncName = (function() {
4378 if (!support.funcNames) {
4379 return constant('');
4380 }
4381 if (constant.name == 'constant') {
4382 return baseProperty('name');
4383 }
4384 return function(func) {
4385 var result = func.name,
4386 array = realNames[result],
4387 length = array ? array.length : 0;
4388
4389 while (length--) {
4390 var data = array[length],
4391 otherFunc = data.func;
4392
4393 if (otherFunc == null || otherFunc == func) {
4394 return data.name;
4395 }
4396 }
4397 return result;
4398 };
4399 }());
4400
4401 /**
4402 * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
4403 * customized this function returns the custom method, otherwise it returns
4404 * the `baseIndexOf` function. If arguments are provided the chosen function
4405 * is invoked with them and its result is returned.
4406 *
4407 * @private
4408 * @returns {Function|number} Returns the chosen function or its result.
4409 */
4410 function getIndexOf(collection, target, fromIndex) {
4411 var result = lodash.indexOf || indexOf;
4412 result = result === indexOf ? baseIndexOf : result;
4413 return collection ? result(collection, target, fromIndex) : result;
4414 }
4415
4416 /**
4417 * Gets the view, applying any `transforms` to the `start` and `end` positions.
4418 *
4419 * @private
4420 * @param {number} start The start of the view.
4421 * @param {number} end The end of the view.
4422 * @param {Array} [transforms] The transformations to apply to the view.
4423 * @returns {Object} Returns an object containing the `start` and `end`
4424 * positions of the view.
4425 */
4426 function getView(start, end, transforms) {
4427 var index = -1,
4428 length = transforms ? transforms.length : 0;
4429
4430 while (++index < length) {
4431 var data = transforms[index],
4432 size = data.size;
4433
4434 switch (data.type) {
4435 case 'drop': start += size; break;
4436 case 'dropRight': end -= size; break;
4437 case 'take': end = nativeMin(end, start + size); break;
4438 case 'takeRight': start = nativeMax(start, end - size); break;
4439 }
4440 }
4441 return { 'start': start, 'end': end };
4442 }
4443
4444 /**
4445 * Initializes an array clone.
4446 *
4447 * @private
4448 * @param {Array} array The array to clone.
4449 * @returns {Array} Returns the initialized clone.
4450 */
4451 function initCloneArray(array) {
4452 var length = array.length,
4453 result = new array.constructor(length);
4454
4455 // Add array properties assigned by `RegExp#exec`.
4456 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
4457 result.index = array.index;
4458 result.input = array.input;
4459 }
4460 return result;
4461 }
4462
4463 /**
4464 * Initializes an object clone.
4465 *
4466 * @private
4467 * @param {Object} object The object to clone.
4468 * @returns {Object} Returns the initialized clone.
4469 */
4470 function initCloneObject(object) {
4471 var Ctor = object.constructor;
4472 if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
4473 Ctor = Object;
4474 }
4475 return new Ctor;
4476 }
4477
4478 /**
4479 * Initializes an object clone based on its `toStringTag`.
4480 *
4481 * **Note:** This function only supports cloning values with tags of
4482 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
4483 *
4484 *
4485 * @private
4486 * @param {Object} object The object to clone.
4487 * @param {string} tag The `toStringTag` of the object to clone.
4488 * @param {boolean} [isDeep] Specify a deep clone.
4489 * @returns {Object} Returns the initialized clone.
4490 */
4491 function initCloneByTag(object, tag, isDeep) {
4492 var Ctor = object.constructor;
4493 switch (tag) {
4494 case arrayBufferTag:
4495 return bufferClone(object);
4496
4497 case boolTag:
4498 case dateTag:
4499 return new Ctor(+object);
4500
4501 case float32Tag: case float64Tag:
4502 case int8Tag: case int16Tag: case int32Tag:
4503 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
4504 var buffer = object.buffer;
4505 return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
4506
4507 case numberTag:
4508 case stringTag:
4509 return new Ctor(object);
4510
4511 case regexpTag:
4512 var result = new Ctor(object.source, reFlags.exec(object));
4513 result.lastIndex = object.lastIndex;
4514 }
4515 return result;
4516 }
4517
4518 /**
4519 * Checks if `value` is a valid array-like index.
4520 *
4521 * @private
4522 * @param {*} value The value to check.
4523 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
4524 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
4525 */
4526 function isIndex(value, length) {
4527 value = +value;
4528 length = length == null ? MAX_SAFE_INTEGER : length;
4529 return value > -1 && value % 1 == 0 && value < length;
4530 }
4531
4532 /**
4533 * Checks if the provided arguments are from an iteratee call.
4534 *
4535 * @private
4536 * @param {*} value The potential iteratee value argument.
4537 * @param {*} index The potential iteratee index or key argument.
4538 * @param {*} object The potential iteratee object argument.
4539 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
4540 */
4541 function isIterateeCall(value, index, object) {
4542 if (!isObject(object)) {
4543 return false;
4544 }
4545 var type = typeof index;
4546 if (type == 'number') {
4547 var length = object.length,
4548 prereq = isLength(length) && isIndex(index, length);
4549 } else {
4550 prereq = type == 'string' && index in object;
4551 }
4552 if (prereq) {
4553 var other = object[index];
4554 return value === value ? (value === other) : (other !== other);
4555 }
4556 return false;
4557 }
4558
4559 /**
4560 * Checks if `func` has a lazy counterpart.
4561 *
4562 * @private
4563 * @param {Function} func The function to check.
4564 * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
4565 */
4566 function isLaziable(func) {
4567 var funcName = getFuncName(func);
4568 return !!funcName && func === lodash[funcName] && funcName in LazyWrapper.prototype;
4569 }
4570
4571 /**
4572 * Checks if `value` is a valid array-like length.
4573 *
4574 * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
4575 *
4576 * @private
4577 * @param {*} value The value to check.
4578 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
4579 */
4580 function isLength(value) {
4581 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
4582 }
4583
4584 /**
4585 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
4586 *
4587 * @private
4588 * @param {*} value The value to check.
4589 * @returns {boolean} Returns `true` if `value` if suitable for strict
4590 * equality comparisons, else `false`.
4591 */
4592 function isStrictComparable(value) {
4593 return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value));
4594 }
4595
4596 /**
4597 * Merges the function metadata of `source` into `data`.
4598 *
4599 * Merging metadata reduces the number of wrappers required to invoke a function.
4600 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
4601 * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
4602 * augment function arguments, making the order in which they are executed important,
4603 * preventing the merging of metadata. However, we make an exception for a safe
4604 * common case where curried functions have `_.ary` and or `_.rearg` applied.
4605 *
4606 * @private
4607 * @param {Array} data The destination metadata.
4608 * @param {Array} source The source metadata.
4609 * @returns {Array} Returns `data`.
4610 */
4611 function mergeData(data, source) {
4612 var bitmask = data[1],
4613 srcBitmask = source[1],
4614 newBitmask = bitmask | srcBitmask,
4615 isCommon = newBitmask < ARY_FLAG;
4616
4617 var isCombo =
4618 (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
4619 (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
4620 (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
4621
4622 // Exit early if metadata can't be merged.
4623 if (!(isCommon || isCombo)) {
4624 return data;
4625 }
4626 // Use source `thisArg` if available.
4627 if (srcBitmask & BIND_FLAG) {
4628 data[2] = source[2];
4629 // Set when currying a bound function.
4630 newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
4631 }
4632 // Compose partial arguments.
4633 var value = source[3];
4634 if (value) {
4635 var partials = data[3];
4636 data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
4637 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
4638 }
4639 // Compose partial right arguments.
4640 value = source[5];
4641 if (value) {
4642 partials = data[5];
4643 data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
4644 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
4645 }
4646 // Use source `argPos` if available.
4647 value = source[7];
4648 if (value) {
4649 data[7] = arrayCopy(value);
4650 }
4651 // Use source `ary` if it's smaller.
4652 if (srcBitmask & ARY_FLAG) {
4653 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
4654 }
4655 // Use source `arity` if one is not provided.
4656 if (data[9] == null) {
4657 data[9] = source[9];
4658 }
4659 // Use source `func` and merge bitmasks.
4660 data[0] = source[0];
4661 data[1] = newBitmask;
4662
4663 return data;
4664 }
4665
4666 /**
4667 * A specialized version of `_.pick` that picks `object` properties specified
4668 * by the `props` array.
4669 *
4670 * @private
4671 * @param {Object} object The source object.
4672 * @param {string[]} props The property names to pick.
4673 * @returns {Object} Returns the new object.
4674 */
4675 function pickByArray(object, props) {
4676 object = toObject(object);
4677
4678 var index = -1,
4679 length = props.length,
4680 result = {};
4681
4682 while (++index < length) {
4683 var key = props[index];
4684 if (key in object) {
4685 result[key] = object[key];
4686 }
4687 }
4688 return result;
4689 }
4690
4691 /**
4692 * A specialized version of `_.pick` that picks `object` properties `predicate`
4693 * returns truthy for.
4694 *
4695 * @private
4696 * @param {Object} object The source object.
4697 * @param {Function} predicate The function invoked per iteration.
4698 * @returns {Object} Returns the new object.
4699 */
4700 function pickByCallback(object, predicate) {
4701 var result = {};
4702 baseForIn(object, function(value, key, object) {
4703 if (predicate(value, key, object)) {
4704 result[key] = value;
4705 }
4706 });
4707 return result;
4708 }
4709
4710 /**
4711 * Reorder `array` according to the specified indexes where the element at
4712 * the first index is assigned as the first element, the element at
4713 * the second index is assigned as the second element, and so on.
4714 *
4715 * @private
4716 * @param {Array} array The array to reorder.
4717 * @param {Array} indexes The arranged array indexes.
4718 * @returns {Array} Returns `array`.
4719 */
4720 function reorder(array, indexes) {
4721 var arrLength = array.length,
4722 length = nativeMin(indexes.length, arrLength),
4723 oldArray = arrayCopy(array);
4724
4725 while (length--) {
4726 var index = indexes[length];
4727 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
4728 }
4729 return array;
4730 }
4731
4732 /**
4733 * Sets metadata for `func`.
4734 *
4735 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
4736 * period of time, it will trip its breaker and transition to an identity function
4737 * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
4738 * for more details.
4739 *
4740 * @private
4741 * @param {Function} func The function to associate metadata with.
4742 * @param {*} data The metadata.
4743 * @returns {Function} Returns `func`.
4744 */
4745 var setData = (function() {
4746 var count = 0,
4747 lastCalled = 0;
4748
4749 return function(key, value) {
4750 var stamp = now(),
4751 remaining = HOT_SPAN - (stamp - lastCalled);
4752
4753 lastCalled = stamp;
4754 if (remaining > 0) {
4755 if (++count >= HOT_COUNT) {
4756 return key;
4757 }
4758 } else {
4759 count = 0;
4760 }
4761 return baseSetData(key, value);
4762 };
4763 }());
4764
4765 /**
4766 * A fallback implementation of `_.isPlainObject` which checks if `value`
4767 * is an object created by the `Object` constructor or has a `[[Prototype]]`
4768 * of `null`.
4769 *
4770 * @private
4771 * @param {*} value The value to check.
4772 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
4773 */
4774 function shimIsPlainObject(value) {
4775 var Ctor,
4776 support = lodash.support;
4777
4778 // Exit early for non `Object` objects.
4779 if (!(isObjectLike(value) && objToString.call(value) == objectTag) ||
4780 (!hasOwnProperty.call(value, 'constructor') &&
4781 (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
4782 return false;
4783 }
4784 // IE < 9 iterates inherited properties before own properties. If the first
4785 // iterated property is an object's own property then there are no inherited
4786 // enumerable properties.
4787 var result;
4788 // In most environments an object's own properties are iterated before
4789 // its inherited properties. If the last iterated property is an object's
4790 // own property then there are no inherited enumerable properties.
4791 baseForIn(value, function(subValue, key) {
4792 result = key;
4793 });
4794 return typeof result == 'undefined' || hasOwnProperty.call(value, result);
4795 }
4796
4797 /**
4798 * A fallback implementation of `Object.keys` which creates an array of the
4799 * own enumerable property names of `object`.
4800 *
4801 * @private
4802 * @param {Object} object The object to inspect.
4803 * @returns {Array} Returns the array of property names.
4804 */
4805 function shimKeys(object) {
4806 var props = keysIn(object),
4807 propsLength = props.length,
4808 length = propsLength && object.length,
4809 support = lodash.support;
4810
4811 var allowIndexes = length && isLength(length) &&
4812 (isArray(object) || (support.nonEnumArgs && isArguments(object)));
4813
4814 var index = -1,
4815 result = [];
4816
4817 while (++index < propsLength) {
4818 var key = props[index];
4819 if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
4820 result.push(key);
4821 }
4822 }
4823 return result;
4824 }
4825
4826 /**
4827 * Converts `value` to an array-like object if it is not one.
4828 *
4829 * @private
4830 * @param {*} value The value to process.
4831 * @returns {Array|Object} Returns the array-like object.
4832 */
4833 function toIterable(value) {
4834 if (value == null) {
4835 return [];
4836 }
4837 if (!isLength(value.length)) {
4838 return values(value);
4839 }
4840 return isObject(value) ? value : Object(value);
4841 }
4842
4843 /**
4844 * Converts `value` to an object if it is not one.
4845 *
4846 * @private
4847 * @param {*} value The value to process.
4848 * @returns {Object} Returns the object.
4849 */
4850 function toObject(value) {
4851 return isObject(value) ? value : Object(value);
4852 }
4853
4854 /**
4855 * Creates a clone of `wrapper`.
4856 *
4857 * @private
4858 * @param {Object} wrapper The wrapper to clone.
4859 * @returns {Object} Returns the cloned wrapper.
4860 */
4861 function wrapperClone(wrapper) {
4862 return wrapper instanceof LazyWrapper
4863 ? wrapper.clone()
4864 : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
4865 }
4866
4867 /*------------------------------------------------------------------------*/
4868
4869 /**
4870 * Creates an array of elements split into groups the length of `size`.
4871 * If `collection` can't be split evenly, the final chunk will be the remaining
4872 * elements.
4873 *
4874 * @static
4875 * @memberOf _
4876 * @category Array
4877 * @param {Array} array The array to process.
4878 * @param {number} [size=1] The length of each chunk.
4879 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4880 * @returns {Array} Returns the new array containing chunks.
4881 * @example
4882 *
4883 * _.chunk(['a', 'b', 'c', 'd'], 2);
4884 * // => [['a', 'b'], ['c', 'd']]
4885 *
4886 * _.chunk(['a', 'b', 'c', 'd'], 3);
4887 * // => [['a', 'b', 'c'], ['d']]
4888 */
4889 function chunk(array, size, guard) {
4890 if (guard ? isIterateeCall(array, size, guard) : size == null) {
4891 size = 1;
4892 } else {
4893 size = nativeMax(+size || 1, 1);
4894 }
4895 var index = 0,
4896 length = array ? array.length : 0,
4897 resIndex = -1,
4898 result = Array(ceil(length / size));
4899
4900 while (index < length) {
4901 result[++resIndex] = baseSlice(array, index, (index += size));
4902 }
4903 return result;
4904 }
4905
4906 /**
4907 * Creates an array with all falsey values removed. The values `false`, `null`,
4908 * `0`, `""`, `undefined`, and `NaN` are falsey.
4909 *
4910 * @static
4911 * @memberOf _
4912 * @category Array
4913 * @param {Array} array The array to compact.
4914 * @returns {Array} Returns the new array of filtered values.
4915 * @example
4916 *
4917 * _.compact([0, 1, false, 2, '', 3]);
4918 * // => [1, 2, 3]
4919 */
4920 function compact(array) {
4921 var index = -1,
4922 length = array ? array.length : 0,
4923 resIndex = -1,
4924 result = [];
4925
4926 while (++index < length) {
4927 var value = array[index];
4928 if (value) {
4929 result[++resIndex] = value;
4930 }
4931 }
4932 return result;
4933 }
4934
4935 /**
4936 * Creates an array excluding all values of the provided arrays using
4937 * `SameValueZero` for equality comparisons.
4938 *
4939 * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
4940 * comparisons are like strict equality comparisons, e.g. `===`, except that
4941 * `NaN` matches `NaN`.
4942 *
4943 * @static
4944 * @memberOf _
4945 * @category Array
4946 * @param {Array} array The array to inspect.
4947 * @param {...Array} [values] The arrays of values to exclude.
4948 * @returns {Array} Returns the new array of filtered values.
4949 * @example
4950 *
4951 * _.difference([1, 2, 3], [4, 2]);
4952 * // => [1, 3]
4953 */
4954 var difference = restParam(function(array, values) {
4955 return (isArray(array) || isArguments(array))
4956 ? baseDifference(array, baseFlatten(values, false, true))
4957 : [];
4958 });
4959
4960 /**
4961 * Creates a slice of `array` with `n` elements dropped from the beginning.
4962 *
4963 * @static
4964 * @memberOf _
4965 * @category Array
4966 * @param {Array} array The array to query.
4967 * @param {number} [n=1] The number of elements to drop.
4968 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
4969 * @returns {Array} Returns the slice of `array`.
4970 * @example
4971 *
4972 * _.drop([1, 2, 3]);
4973 * // => [2, 3]
4974 *
4975 * _.drop([1, 2, 3], 2);
4976 * // => [3]
4977 *
4978 * _.drop([1, 2, 3], 5);
4979 * // => []
4980 *
4981 * _.drop([1, 2, 3], 0);
4982 * // => [1, 2, 3]
4983 */
4984 function drop(array, n, guard) {
4985 var length = array ? array.length : 0;
4986 if (!length) {
4987 return [];
4988 }
4989 if (guard ? isIterateeCall(array, n, guard) : n == null) {
4990 n = 1;
4991 }
4992 return baseSlice(array, n < 0 ? 0 : n);
4993 }
4994
4995 /**
4996 * Creates a slice of `array` with `n` elements dropped from the end.
4997 *
4998 * @static
4999 * @memberOf _
5000 * @category Array
5001 * @param {Array} array The array to query.
5002 * @param {number} [n=1] The number of elements to drop.
5003 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5004 * @returns {Array} Returns the slice of `array`.
5005 * @example
5006 *
5007 * _.dropRight([1, 2, 3]);
5008 * // => [1, 2]
5009 *
5010 * _.dropRight([1, 2, 3], 2);
5011 * // => [1]
5012 *
5013 * _.dropRight([1, 2, 3], 5);
5014 * // => []
5015 *
5016 * _.dropRight([1, 2, 3], 0);
5017 * // => [1, 2, 3]
5018 */
5019 function dropRight(array, n, guard) {
5020 var length = array ? array.length : 0;
5021 if (!length) {
5022 return [];
5023 }
5024 if (guard ? isIterateeCall(array, n, guard) : n == null) {
5025 n = 1;
5026 }
5027 n = length - (+n || 0);
5028 return baseSlice(array, 0, n < 0 ? 0 : n);
5029 }
5030
5031 /**
5032 * Creates a slice of `array` excluding elements dropped from the end.
5033 * Elements are dropped until `predicate` returns falsey. The predicate is
5034 * bound to `thisArg` and invoked with three arguments: (value, index, array).
5035 *
5036 * If a property name is provided for `predicate` the created `_.property`
5037 * style callback returns the property value of the given element.
5038 *
5039 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5040 * style callback returns `true` for elements that have a matching property
5041 * value, else `false`.
5042 *
5043 * If an object is provided for `predicate` the created `_.matches` style
5044 * callback returns `true` for elements that match the properties of the given
5045 * object, else `false`.
5046 *
5047 * @static
5048 * @memberOf _
5049 * @category Array
5050 * @param {Array} array The array to query.
5051 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5052 * per iteration.
5053 * @param {*} [thisArg] The `this` binding of `predicate`.
5054 * @returns {Array} Returns the slice of `array`.
5055 * @example
5056 *
5057 * _.dropRightWhile([1, 2, 3], function(n) {
5058 * return n > 1;
5059 * });
5060 * // => [1]
5061 *
5062 * var users = [
5063 * { 'user': 'barney', 'active': true },
5064 * { 'user': 'fred', 'active': false },
5065 * { 'user': 'pebbles', 'active': false }
5066 * ];
5067 *
5068 * // using the `_.matches` callback shorthand
5069 * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
5070 * // => ['barney', 'fred']
5071 *
5072 * // using the `_.matchesProperty` callback shorthand
5073 * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
5074 * // => ['barney']
5075 *
5076 * // using the `_.property` callback shorthand
5077 * _.pluck(_.dropRightWhile(users, 'active'), 'user');
5078 * // => ['barney', 'fred', 'pebbles']
5079 */
5080 function dropRightWhile(array, predicate, thisArg) {
5081 return (array && array.length)
5082 ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
5083 : [];
5084 }
5085
5086 /**
5087 * Creates a slice of `array` excluding elements dropped from the beginning.
5088 * Elements are dropped until `predicate` returns falsey. The predicate is
5089 * bound to `thisArg` and invoked with three arguments: (value, index, array).
5090 *
5091 * If a property name is provided for `predicate` the created `_.property`
5092 * style callback returns the property value of the given element.
5093 *
5094 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5095 * style callback returns `true` for elements that have a matching property
5096 * value, else `false`.
5097 *
5098 * If an object is provided for `predicate` the created `_.matches` style
5099 * callback returns `true` for elements that have the properties of the given
5100 * object, else `false`.
5101 *
5102 * @static
5103 * @memberOf _
5104 * @category Array
5105 * @param {Array} array The array to query.
5106 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5107 * per iteration.
5108 * @param {*} [thisArg] The `this` binding of `predicate`.
5109 * @returns {Array} Returns the slice of `array`.
5110 * @example
5111 *
5112 * _.dropWhile([1, 2, 3], function(n) {
5113 * return n < 3;
5114 * });
5115 * // => [3]
5116 *
5117 * var users = [
5118 * { 'user': 'barney', 'active': false },
5119 * { 'user': 'fred', 'active': false },
5120 * { 'user': 'pebbles', 'active': true }
5121 * ];
5122 *
5123 * // using the `_.matches` callback shorthand
5124 * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
5125 * // => ['fred', 'pebbles']
5126 *
5127 * // using the `_.matchesProperty` callback shorthand
5128 * _.pluck(_.dropWhile(users, 'active', false), 'user');
5129 * // => ['pebbles']
5130 *
5131 * // using the `_.property` callback shorthand
5132 * _.pluck(_.dropWhile(users, 'active'), 'user');
5133 * // => ['barney', 'fred', 'pebbles']
5134 */
5135 function dropWhile(array, predicate, thisArg) {
5136 return (array && array.length)
5137 ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
5138 : [];
5139 }
5140
5141 /**
5142 * Fills elements of `array` with `value` from `start` up to, but not
5143 * including, `end`.
5144 *
5145 * **Note:** This method mutates `array`.
5146 *
5147 * @static
5148 * @memberOf _
5149 * @category Array
5150 * @param {Array} array The array to fill.
5151 * @param {*} value The value to fill `array` with.
5152 * @param {number} [start=0] The start position.
5153 * @param {number} [end=array.length] The end position.
5154 * @returns {Array} Returns `array`.
5155 * @example
5156 *
5157 * var array = [1, 2, 3];
5158 *
5159 * _.fill(array, 'a');
5160 * console.log(array);
5161 * // => ['a', 'a', 'a']
5162 *
5163 * _.fill(Array(3), 2);
5164 * // => [2, 2, 2]
5165 *
5166 * _.fill([4, 6, 8], '*', 1, 2);
5167 * // => [4, '*', 8]
5168 */
5169 function fill(array, value, start, end) {
5170 var length = array ? array.length : 0;
5171 if (!length) {
5172 return [];
5173 }
5174 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
5175 start = 0;
5176 end = length;
5177 }
5178 return baseFill(array, value, start, end);
5179 }
5180
5181 /**
5182 * This method is like `_.find` except that it returns the index of the first
5183 * element `predicate` returns truthy for instead of the element itself.
5184 *
5185 * If a property name is provided for `predicate` the created `_.property`
5186 * style callback returns the property value of the given element.
5187 *
5188 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5189 * style callback returns `true` for elements that have a matching property
5190 * value, else `false`.
5191 *
5192 * If an object is provided for `predicate` the created `_.matches` style
5193 * callback returns `true` for elements that have the properties of the given
5194 * object, else `false`.
5195 *
5196 * @static
5197 * @memberOf _
5198 * @category Array
5199 * @param {Array} array The array to search.
5200 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5201 * per iteration.
5202 * @param {*} [thisArg] The `this` binding of `predicate`.
5203 * @returns {number} Returns the index of the found element, else `-1`.
5204 * @example
5205 *
5206 * var users = [
5207 * { 'user': 'barney', 'active': false },
5208 * { 'user': 'fred', 'active': false },
5209 * { 'user': 'pebbles', 'active': true }
5210 * ];
5211 *
5212 * _.findIndex(users, function(chr) {
5213 * return chr.user == 'barney';
5214 * });
5215 * // => 0
5216 *
5217 * // using the `_.matches` callback shorthand
5218 * _.findIndex(users, { 'user': 'fred', 'active': false });
5219 * // => 1
5220 *
5221 * // using the `_.matchesProperty` callback shorthand
5222 * _.findIndex(users, 'active', false);
5223 * // => 0
5224 *
5225 * // using the `_.property` callback shorthand
5226 * _.findIndex(users, 'active');
5227 * // => 2
5228 */
5229 var findIndex = createFindIndex();
5230
5231 /**
5232 * This method is like `_.findIndex` except that it iterates over elements
5233 * of `collection` from right to left.
5234 *
5235 * If a property name is provided for `predicate` the created `_.property`
5236 * style callback returns the property value of the given element.
5237 *
5238 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5239 * style callback returns `true` for elements that have a matching property
5240 * value, else `false`.
5241 *
5242 * If an object is provided for `predicate` the created `_.matches` style
5243 * callback returns `true` for elements that have the properties of the given
5244 * object, else `false`.
5245 *
5246 * @static
5247 * @memberOf _
5248 * @category Array
5249 * @param {Array} array The array to search.
5250 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5251 * per iteration.
5252 * @param {*} [thisArg] The `this` binding of `predicate`.
5253 * @returns {number} Returns the index of the found element, else `-1`.
5254 * @example
5255 *
5256 * var users = [
5257 * { 'user': 'barney', 'active': true },
5258 * { 'user': 'fred', 'active': false },
5259 * { 'user': 'pebbles', 'active': false }
5260 * ];
5261 *
5262 * _.findLastIndex(users, function(chr) {
5263 * return chr.user == 'pebbles';
5264 * });
5265 * // => 2
5266 *
5267 * // using the `_.matches` callback shorthand
5268 * _.findLastIndex(users, { 'user': 'barney', 'active': true });
5269 * // => 0
5270 *
5271 * // using the `_.matchesProperty` callback shorthand
5272 * _.findLastIndex(users, 'active', false);
5273 * // => 2
5274 *
5275 * // using the `_.property` callback shorthand
5276 * _.findLastIndex(users, 'active');
5277 * // => 0
5278 */
5279 var findLastIndex = createFindIndex(true);
5280
5281 /**
5282 * Gets the first element of `array`.
5283 *
5284 * @static
5285 * @memberOf _
5286 * @alias head
5287 * @category Array
5288 * @param {Array} array The array to query.
5289 * @returns {*} Returns the first element of `array`.
5290 * @example
5291 *
5292 * _.first([1, 2, 3]);
5293 * // => 1
5294 *
5295 * _.first([]);
5296 * // => undefined
5297 */
5298 function first(array) {
5299 return array ? array[0] : undefined;
5300 }
5301
5302 /**
5303 * Flattens a nested array. If `isDeep` is `true` the array is recursively
5304 * flattened, otherwise it is only flattened a single level.
5305 *
5306 * @static
5307 * @memberOf _
5308 * @category Array
5309 * @param {Array} array The array to flatten.
5310 * @param {boolean} [isDeep] Specify a deep flatten.
5311 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5312 * @returns {Array} Returns the new flattened array.
5313 * @example
5314 *
5315 * _.flatten([1, [2, 3, [4]]]);
5316 * // => [1, 2, 3, [4]]
5317 *
5318 * // using `isDeep`
5319 * _.flatten([1, [2, 3, [4]]], true);
5320 * // => [1, 2, 3, 4]
5321 */
5322 function flatten(array, isDeep, guard) {
5323 var length = array ? array.length : 0;
5324 if (guard && isIterateeCall(array, isDeep, guard)) {
5325 isDeep = false;
5326 }
5327 return length ? baseFlatten(array, isDeep) : [];
5328 }
5329
5330 /**
5331 * Recursively flattens a nested array.
5332 *
5333 * @static
5334 * @memberOf _
5335 * @category Array
5336 * @param {Array} array The array to recursively flatten.
5337 * @returns {Array} Returns the new flattened array.
5338 * @example
5339 *
5340 * _.flattenDeep([1, [2, 3, [4]]]);
5341 * // => [1, 2, 3, 4]
5342 */
5343 function flattenDeep(array) {
5344 var length = array ? array.length : 0;
5345 return length ? baseFlatten(array, true) : [];
5346 }
5347
5348 /**
5349 * Gets the index at which the first occurrence of `value` is found in `array`
5350 * using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
5351 * it is used as the offset from the end of `array`. If `array` is sorted
5352 * providing `true` for `fromIndex` performs a faster binary search.
5353 *
5354 * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
5355 * comparisons are like strict equality comparisons, e.g. `===`, except that
5356 * `NaN` matches `NaN`.
5357 *
5358 * @static
5359 * @memberOf _
5360 * @category Array
5361 * @param {Array} array The array to search.
5362 * @param {*} value The value to search for.
5363 * @param {boolean|number} [fromIndex=0] The index to search from or `true`
5364 * to perform a binary search on a sorted array.
5365 * @returns {number} Returns the index of the matched value, else `-1`.
5366 * @example
5367 *
5368 * _.indexOf([1, 2, 1, 2], 2);
5369 * // => 1
5370 *
5371 * // using `fromIndex`
5372 * _.indexOf([1, 2, 1, 2], 2, 2);
5373 * // => 3
5374 *
5375 * // performing a binary search
5376 * _.indexOf([1, 1, 2, 2], 2, true);
5377 * // => 2
5378 */
5379 function indexOf(array, value, fromIndex) {
5380 var length = array ? array.length : 0;
5381 if (!length) {
5382 return -1;
5383 }
5384 if (typeof fromIndex == 'number') {
5385 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
5386 } else if (fromIndex) {
5387 var index = binaryIndex(array, value),
5388 other = array[index];
5389
5390 if (value === value ? (value === other) : (other !== other)) {
5391 return index;
5392 }
5393 return -1;
5394 }
5395 return baseIndexOf(array, value, fromIndex || 0);
5396 }
5397
5398 /**
5399 * Gets all but the last element of `array`.
5400 *
5401 * @static
5402 * @memberOf _
5403 * @category Array
5404 * @param {Array} array The array to query.
5405 * @returns {Array} Returns the slice of `array`.
5406 * @example
5407 *
5408 * _.initial([1, 2, 3]);
5409 * // => [1, 2]
5410 */
5411 function initial(array) {
5412 return dropRight(array, 1);
5413 }
5414
5415 /**
5416 * Creates an array of unique values in all provided arrays using `SameValueZero`
5417 * for equality comparisons.
5418 *
5419 * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
5420 * comparisons are like strict equality comparisons, e.g. `===`, except that
5421 * `NaN` matches `NaN`.
5422 *
5423 * @static
5424 * @memberOf _
5425 * @category Array
5426 * @param {...Array} [arrays] The arrays to inspect.
5427 * @returns {Array} Returns the new array of shared values.
5428 * @example
5429 * _.intersection([1, 2], [4, 2], [2, 1]);
5430 * // => [2]
5431 */
5432 function intersection() {
5433 var args = [],
5434 argsIndex = -1,
5435 argsLength = arguments.length,
5436 caches = [],
5437 indexOf = getIndexOf(),
5438 isCommon = indexOf == baseIndexOf;
5439
5440 while (++argsIndex < argsLength) {
5441 var value = arguments[argsIndex];
5442 if (isArray(value) || isArguments(value)) {
5443 args.push(value);
5444 caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
5445 }
5446 }
5447 argsLength = args.length;
5448 var array = args[0],
5449 index = -1,
5450 length = array ? array.length : 0,
5451 result = [],
5452 seen = caches[0];
5453
5454 outer:
5455 while (++index < length) {
5456 value = array[index];
5457 if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
5458 argsIndex = argsLength;
5459 while (--argsIndex) {
5460 var cache = caches[argsIndex];
5461 if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) {
5462 continue outer;
5463 }
5464 }
5465 if (seen) {
5466 seen.push(value);
5467 }
5468 result.push(value);
5469 }
5470 }
5471 return result;
5472 }
5473
5474 /**
5475 * Gets the last element of `array`.
5476 *
5477 * @static
5478 * @memberOf _
5479 * @category Array
5480 * @param {Array} array The array to query.
5481 * @returns {*} Returns the last element of `array`.
5482 * @example
5483 *
5484 * _.last([1, 2, 3]);
5485 * // => 3
5486 */
5487 function last(array) {
5488 var length = array ? array.length : 0;
5489 return length ? array[length - 1] : undefined;
5490 }
5491
5492 /**
5493 * This method is like `_.indexOf` except that it iterates over elements of
5494 * `array` from right to left.
5495 *
5496 * @static
5497 * @memberOf _
5498 * @category Array
5499 * @param {Array} array The array to search.
5500 * @param {*} value The value to search for.
5501 * @param {boolean|number} [fromIndex=array.length-1] The index to search from
5502 * or `true` to perform a binary search on a sorted array.
5503 * @returns {number} Returns the index of the matched value, else `-1`.
5504 * @example
5505 *
5506 * _.lastIndexOf([1, 2, 1, 2], 2);
5507 * // => 3
5508 *
5509 * // using `fromIndex`
5510 * _.lastIndexOf([1, 2, 1, 2], 2, 2);
5511 * // => 1
5512 *
5513 * // performing a binary search
5514 * _.lastIndexOf([1, 1, 2, 2], 2, true);
5515 * // => 3
5516 */
5517 function lastIndexOf(array, value, fromIndex) {
5518 var length = array ? array.length : 0;
5519 if (!length) {
5520 return -1;
5521 }
5522 var index = length;
5523 if (typeof fromIndex == 'number') {
5524 index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
5525 } else if (fromIndex) {
5526 index = binaryIndex(array, value, true) - 1;
5527 var other = array[index];
5528 if (value === value ? (value === other) : (other !== other)) {
5529 return index;
5530 }
5531 return -1;
5532 }
5533 if (value !== value) {
5534 return indexOfNaN(array, index, true);
5535 }
5536 while (index--) {
5537 if (array[index] === value) {
5538 return index;
5539 }
5540 }
5541 return -1;
5542 }
5543
5544 /**
5545 * Removes all provided values from `array` using `SameValueZero` for equality
5546 * comparisons.
5547 *
5548 * **Notes:**
5549 * - Unlike `_.without`, this method mutates `array`
5550 * - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
5551 * comparisons are like strict equality comparisons, e.g. `===`, except
5552 * that `NaN` matches `NaN`
5553 *
5554 * @static
5555 * @memberOf _
5556 * @category Array
5557 * @param {Array} array The array to modify.
5558 * @param {...*} [values] The values to remove.
5559 * @returns {Array} Returns `array`.
5560 * @example
5561 *
5562 * var array = [1, 2, 3, 1, 2, 3];
5563 *
5564 * _.pull(array, 2, 3);
5565 * console.log(array);
5566 * // => [1, 1]
5567 */
5568 function pull() {
5569 var args = arguments,
5570 array = args[0];
5571
5572 if (!(array && array.length)) {
5573 return array;
5574 }
5575 var index = 0,
5576 indexOf = getIndexOf(),
5577 length = args.length;
5578
5579 while (++index < length) {
5580 var fromIndex = 0,
5581 value = args[index];
5582
5583 while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
5584 splice.call(array, fromIndex, 1);
5585 }
5586 }
5587 return array;
5588 }
5589
5590 /**
5591 * Removes elements from `array` corresponding to the given indexes and returns
5592 * an array of the removed elements. Indexes may be specified as an array of
5593 * indexes or as individual arguments.
5594 *
5595 * **Note:** Unlike `_.at`, this method mutates `array`.
5596 *
5597 * @static
5598 * @memberOf _
5599 * @category Array
5600 * @param {Array} array The array to modify.
5601 * @param {...(number|number[])} [indexes] The indexes of elements to remove,
5602 * specified as individual indexes or arrays of indexes.
5603 * @returns {Array} Returns the new array of removed elements.
5604 * @example
5605 *
5606 * var array = [5, 10, 15, 20];
5607 * var evens = _.pullAt(array, 1, 3);
5608 *
5609 * console.log(array);
5610 * // => [5, 15]
5611 *
5612 * console.log(evens);
5613 * // => [10, 20]
5614 */
5615 var pullAt = restParam(function(array, indexes) {
5616 array || (array = []);
5617 indexes = baseFlatten(indexes);
5618
5619 var length = indexes.length,
5620 result = baseAt(array, indexes);
5621
5622 indexes.sort(baseCompareAscending);
5623 while (length--) {
5624 var index = parseFloat(indexes[length]);
5625 if (index != previous && isIndex(index)) {
5626 var previous = index;
5627 splice.call(array, index, 1);
5628 }
5629 }
5630 return result;
5631 });
5632
5633 /**
5634 * Removes all elements from `array` that `predicate` returns truthy for
5635 * and returns an array of the removed elements. The predicate is bound to
5636 * `thisArg` and invoked with three arguments: (value, index, array).
5637 *
5638 * If a property name is provided for `predicate` the created `_.property`
5639 * style callback returns the property value of the given element.
5640 *
5641 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5642 * style callback returns `true` for elements that have a matching property
5643 * value, else `false`.
5644 *
5645 * If an object is provided for `predicate` the created `_.matches` style
5646 * callback returns `true` for elements that have the properties of the given
5647 * object, else `false`.
5648 *
5649 * **Note:** Unlike `_.filter`, this method mutates `array`.
5650 *
5651 * @static
5652 * @memberOf _
5653 * @category Array
5654 * @param {Array} array The array to modify.
5655 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5656 * per iteration.
5657 * @param {*} [thisArg] The `this` binding of `predicate`.
5658 * @returns {Array} Returns the new array of removed elements.
5659 * @example
5660 *
5661 * var array = [1, 2, 3, 4];
5662 * var evens = _.remove(array, function(n) {
5663 * return n % 2 == 0;
5664 * });
5665 *
5666 * console.log(array);
5667 * // => [1, 3]
5668 *
5669 * console.log(evens);
5670 * // => [2, 4]
5671 */
5672 function remove(array, predicate, thisArg) {
5673 var index = -1,
5674 length = array ? array.length : 0,
5675 result = [];
5676
5677 predicate = getCallback(predicate, thisArg, 3);
5678 while (++index < length) {
5679 var value = array[index];
5680 if (predicate(value, index, array)) {
5681 result.push(value);
5682 splice.call(array, index--, 1);
5683 length--;
5684 }
5685 }
5686 return result;
5687 }
5688
5689 /**
5690 * Gets all but the first element of `array`.
5691 *
5692 * @static
5693 * @memberOf _
5694 * @alias tail
5695 * @category Array
5696 * @param {Array} array The array to query.
5697 * @returns {Array} Returns the slice of `array`.
5698 * @example
5699 *
5700 * _.rest([1, 2, 3]);
5701 * // => [2, 3]
5702 */
5703 function rest(array) {
5704 return drop(array, 1);
5705 }
5706
5707 /**
5708 * Creates a slice of `array` from `start` up to, but not including, `end`.
5709 *
5710 * **Note:** This function is used instead of `Array#slice` to support node
5711 * lists in IE < 9 and to ensure dense arrays are returned.
5712 *
5713 * @static
5714 * @memberOf _
5715 * @category Array
5716 * @param {Array} array The array to slice.
5717 * @param {number} [start=0] The start position.
5718 * @param {number} [end=array.length] The end position.
5719 * @returns {Array} Returns the slice of `array`.
5720 */
5721 function slice(array, start, end) {
5722 var length = array ? array.length : 0;
5723 if (!length) {
5724 return [];
5725 }
5726 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
5727 start = 0;
5728 end = length;
5729 }
5730 return baseSlice(array, start, end);
5731 }
5732
5733 /**
5734 * Uses a binary search to determine the lowest index at which `value` should
5735 * be inserted into `array` in order to maintain its sort order. If an iteratee
5736 * function is provided it is invoked for `value` and each element of `array`
5737 * to compute their sort ranking. The iteratee is bound to `thisArg` and
5738 * invoked with one argument; (value).
5739 *
5740 * If a property name is provided for `iteratee` the created `_.property`
5741 * style callback returns the property value of the given element.
5742 *
5743 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5744 * style callback returns `true` for elements that have a matching property
5745 * value, else `false`.
5746 *
5747 * If an object is provided for `iteratee` the created `_.matches` style
5748 * callback returns `true` for elements that have the properties of the given
5749 * object, else `false`.
5750 *
5751 * @static
5752 * @memberOf _
5753 * @category Array
5754 * @param {Array} array The sorted array to inspect.
5755 * @param {*} value The value to evaluate.
5756 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5757 * per iteration.
5758 * @param {*} [thisArg] The `this` binding of `iteratee`.
5759 * @returns {number} Returns the index at which `value` should be inserted
5760 * into `array`.
5761 * @example
5762 *
5763 * _.sortedIndex([30, 50], 40);
5764 * // => 1
5765 *
5766 * _.sortedIndex([4, 4, 5, 5], 5);
5767 * // => 2
5768 *
5769 * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
5770 *
5771 * // using an iteratee function
5772 * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
5773 * return this.data[word];
5774 * }, dict);
5775 * // => 1
5776 *
5777 * // using the `_.property` callback shorthand
5778 * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
5779 * // => 1
5780 */
5781 var sortedIndex = createSortedIndex();
5782
5783 /**
5784 * This method is like `_.sortedIndex` except that it returns the highest
5785 * index at which `value` should be inserted into `array` in order to
5786 * maintain its sort order.
5787 *
5788 * @static
5789 * @memberOf _
5790 * @category Array
5791 * @param {Array} array The sorted array to inspect.
5792 * @param {*} value The value to evaluate.
5793 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
5794 * per iteration.
5795 * @param {*} [thisArg] The `this` binding of `iteratee`.
5796 * @returns {number} Returns the index at which `value` should be inserted
5797 * into `array`.
5798 * @example
5799 *
5800 * _.sortedLastIndex([4, 4, 5, 5], 5);
5801 * // => 4
5802 */
5803 var sortedLastIndex = createSortedIndex(true);
5804
5805 /**
5806 * Creates a slice of `array` with `n` elements taken from the beginning.
5807 *
5808 * @static
5809 * @memberOf _
5810 * @category Array
5811 * @param {Array} array The array to query.
5812 * @param {number} [n=1] The number of elements to take.
5813 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5814 * @returns {Array} Returns the slice of `array`.
5815 * @example
5816 *
5817 * _.take([1, 2, 3]);
5818 * // => [1]
5819 *
5820 * _.take([1, 2, 3], 2);
5821 * // => [1, 2]
5822 *
5823 * _.take([1, 2, 3], 5);
5824 * // => [1, 2, 3]
5825 *
5826 * _.take([1, 2, 3], 0);
5827 * // => []
5828 */
5829 function take(array, n, guard) {
5830 var length = array ? array.length : 0;
5831 if (!length) {
5832 return [];
5833 }
5834 if (guard ? isIterateeCall(array, n, guard) : n == null) {
5835 n = 1;
5836 }
5837 return baseSlice(array, 0, n < 0 ? 0 : n);
5838 }
5839
5840 /**
5841 * Creates a slice of `array` with `n` elements taken from the end.
5842 *
5843 * @static
5844 * @memberOf _
5845 * @category Array
5846 * @param {Array} array The array to query.
5847 * @param {number} [n=1] The number of elements to take.
5848 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
5849 * @returns {Array} Returns the slice of `array`.
5850 * @example
5851 *
5852 * _.takeRight([1, 2, 3]);
5853 * // => [3]
5854 *
5855 * _.takeRight([1, 2, 3], 2);
5856 * // => [2, 3]
5857 *
5858 * _.takeRight([1, 2, 3], 5);
5859 * // => [1, 2, 3]
5860 *
5861 * _.takeRight([1, 2, 3], 0);
5862 * // => []
5863 */
5864 function takeRight(array, n, guard) {
5865 var length = array ? array.length : 0;
5866 if (!length) {
5867 return [];
5868 }
5869 if (guard ? isIterateeCall(array, n, guard) : n == null) {
5870 n = 1;
5871 }
5872 n = length - (+n || 0);
5873 return baseSlice(array, n < 0 ? 0 : n);
5874 }
5875
5876 /**
5877 * Creates a slice of `array` with elements taken from the end. Elements are
5878 * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
5879 * and invoked with three arguments: (value, index, array).
5880 *
5881 * If a property name is provided for `predicate` the created `_.property`
5882 * style callback returns the property value of the given element.
5883 *
5884 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5885 * style callback returns `true` for elements that have a matching property
5886 * value, else `false`.
5887 *
5888 * If an object is provided for `predicate` the created `_.matches` style
5889 * callback returns `true` for elements that have the properties of the given
5890 * object, else `false`.
5891 *
5892 * @static
5893 * @memberOf _
5894 * @category Array
5895 * @param {Array} array The array to query.
5896 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5897 * per iteration.
5898 * @param {*} [thisArg] The `this` binding of `predicate`.
5899 * @returns {Array} Returns the slice of `array`.
5900 * @example
5901 *
5902 * _.takeRightWhile([1, 2, 3], function(n) {
5903 * return n > 1;
5904 * });
5905 * // => [2, 3]
5906 *
5907 * var users = [
5908 * { 'user': 'barney', 'active': true },
5909 * { 'user': 'fred', 'active': false },
5910 * { 'user': 'pebbles', 'active': false }
5911 * ];
5912 *
5913 * // using the `_.matches` callback shorthand
5914 * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
5915 * // => ['pebbles']
5916 *
5917 * // using the `_.matchesProperty` callback shorthand
5918 * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
5919 * // => ['fred', 'pebbles']
5920 *
5921 * // using the `_.property` callback shorthand
5922 * _.pluck(_.takeRightWhile(users, 'active'), 'user');
5923 * // => []
5924 */
5925 function takeRightWhile(array, predicate, thisArg) {
5926 return (array && array.length)
5927 ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
5928 : [];
5929 }
5930
5931 /**
5932 * Creates a slice of `array` with elements taken from the beginning. Elements
5933 * are taken until `predicate` returns falsey. The predicate is bound to
5934 * `thisArg` and invoked with three arguments: (value, index, array).
5935 *
5936 * If a property name is provided for `predicate` the created `_.property`
5937 * style callback returns the property value of the given element.
5938 *
5939 * If a value is also provided for `thisArg` the created `_.matchesProperty`
5940 * style callback returns `true` for elements that have a matching property
5941 * value, else `false`.
5942 *
5943 * If an object is provided for `predicate` the created `_.matches` style
5944 * callback returns `true` for elements that have the properties of the given
5945 * object, else `false`.
5946 *
5947 * @static
5948 * @memberOf _
5949 * @category Array
5950 * @param {Array} array The array to query.
5951 * @param {Function|Object|string} [predicate=_.identity] The function invoked
5952 * per iteration.
5953 * @param {*} [thisArg] The `this` binding of `predicate`.
5954 * @returns {Array} Returns the slice of `array`.
5955 * @example
5956 *
5957 * _.takeWhile([1, 2, 3], function(n) {
5958 * return n < 3;
5959 * });
5960 * // => [1, 2]
5961 *
5962 * var users = [
5963 * { 'user': 'barney', 'active': false },
5964 * { 'user': 'fred', 'active': false},
5965 * { 'user': 'pebbles', 'active': true }
5966 * ];
5967 *
5968 * // using the `_.matches` callback shorthand
5969 * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
5970 * // => ['barney']
5971 *
5972 * // using the `_.matchesProperty` callback shorthand
5973 * _.pluck(_.takeWhile(users, 'active', false), 'user');
5974 * // => ['barney', 'fred']
5975 *
5976 * // using the `_.property` callback shorthand
5977 * _.pluck(_.takeWhile(users, 'active'), 'user');
5978 * // => []
5979 */
5980 function takeWhile(array, predicate, thisArg) {
5981 return (array && array.length)
5982 ? baseWhile(array, getCallback(predicate, thisArg, 3))
5983 : [];
5984 }
5985
5986 /**
5987 * Creates an array of unique values, in order, of the provided arrays using
5988 * `SameValueZero` for equality comparisons.
5989 *
5990 * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
5991 * comparisons are like strict equality comparisons, e.g. `===`, except that
5992 * `NaN` matches `NaN`.
5993 *
5994 * @static
5995 * @memberOf _
5996 * @category Array
5997 * @param {...Array} [arrays] The arrays to inspect.
5998 * @returns {Array} Returns the new array of combined values.
5999 * @example
6000 *
6001 * _.union([1, 2], [4, 2], [2, 1]);
6002 * // => [1, 2, 4]
6003 */
6004 var union = restParam(function(arrays) {
6005 return baseUniq(baseFlatten(arrays, false, true));
6006 });
6007
6008 /**
6009 * Creates a duplicate-value-free version of an array using `SameValueZero`
6010 * for equality comparisons. Providing `true` for `isSorted` performs a faster
6011 * search algorithm for sorted arrays. If an iteratee function is provided it
6012 * is invoked for each value in the array to generate the criterion by which
6013 * uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
6014 * with three arguments: (value, index, array).
6015 *
6016 * If a property name is provided for `iteratee` the created `_.property`
6017 * style callback returns the property value of the given element.
6018 *
6019 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6020 * style callback returns `true` for elements that have a matching property
6021 * value, else `false`.
6022 *
6023 * If an object is provided for `iteratee` the created `_.matches` style
6024 * callback returns `true` for elements that have the properties of the given
6025 * object, else `false`.
6026 *
6027 * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
6028 * comparisons are like strict equality comparisons, e.g. `===`, except that
6029 * `NaN` matches `NaN`.
6030 *
6031 * @static
6032 * @memberOf _
6033 * @alias unique
6034 * @category Array
6035 * @param {Array} array The array to inspect.
6036 * @param {boolean} [isSorted] Specify the array is sorted.
6037 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
6038 * @param {*} [thisArg] The `this` binding of `iteratee`.
6039 * @returns {Array} Returns the new duplicate-value-free array.
6040 * @example
6041 *
6042 * _.uniq([1, 2, 1]);
6043 * // => [1, 2]
6044 *
6045 * // using `isSorted`
6046 * _.uniq([1, 1, 2], true);
6047 * // => [1, 2]
6048 *
6049 * // using an iteratee function
6050 * _.uniq([1, 2.5, 1.5, 2], function(n) {
6051 * return this.floor(n);
6052 * }, Math);
6053 * // => [1, 2.5]
6054 *
6055 * // using the `_.property` callback shorthand
6056 * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
6057 * // => [{ 'x': 1 }, { 'x': 2 }]
6058 */
6059 function uniq(array, isSorted, iteratee, thisArg) {
6060 var length = array ? array.length : 0;
6061 if (!length) {
6062 return [];
6063 }
6064 if (isSorted != null && typeof isSorted != 'boolean') {
6065 thisArg = iteratee;
6066 iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
6067 isSorted = false;
6068 }
6069 var func = getCallback();
6070 if (!(func === baseCallback && iteratee == null)) {
6071 iteratee = func(iteratee, thisArg, 3);
6072 }
6073 return (isSorted && getIndexOf() == baseIndexOf)
6074 ? sortedUniq(array, iteratee)
6075 : baseUniq(array, iteratee);
6076 }
6077
6078 /**
6079 * This method is like `_.zip` except that it accepts an array of grouped
6080 * elements and creates an array regrouping the elements to their pre-`_.zip`
6081 * configuration.
6082 *
6083 * @static
6084 * @memberOf _
6085 * @category Array
6086 * @param {Array} array The array of grouped elements to process.
6087 * @returns {Array} Returns the new array of regrouped elements.
6088 * @example
6089 *
6090 * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
6091 * // => [['fred', 30, true], ['barney', 40, false]]
6092 *
6093 * _.unzip(zipped);
6094 * // => [['fred', 'barney'], [30, 40], [true, false]]
6095 */
6096 function unzip(array) {
6097 var index = -1,
6098 length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0,
6099 result = Array(length);
6100
6101 while (++index < length) {
6102 result[index] = arrayMap(array, baseProperty(index));
6103 }
6104 return result;
6105 }
6106
6107 /**
6108 * Creates an array excluding all provided values using `SameValueZero` for
6109 * equality comparisons.
6110 *
6111 * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
6112 * comparisons are like strict equality comparisons, e.g. `===`, except that
6113 * `NaN` matches `NaN`.
6114 *
6115 * @static
6116 * @memberOf _
6117 * @category Array
6118 * @param {Array} array The array to filter.
6119 * @param {...*} [values] The values to exclude.
6120 * @returns {Array} Returns the new array of filtered values.
6121 * @example
6122 *
6123 * _.without([1, 2, 1, 3], 1, 2);
6124 * // => [3]
6125 */
6126 var without = restParam(function(array, values) {
6127 return (isArray(array) || isArguments(array))
6128 ? baseDifference(array, values)
6129 : [];
6130 });
6131
6132 /**
6133 * Creates an array that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
6134 * of the provided arrays.
6135 *
6136 * @static
6137 * @memberOf _
6138 * @category Array
6139 * @param {...Array} [arrays] The arrays to inspect.
6140 * @returns {Array} Returns the new array of values.
6141 * @example
6142 *
6143 * _.xor([1, 2], [4, 2]);
6144 * // => [1, 4]
6145 */
6146 function xor() {
6147 var index = -1,
6148 length = arguments.length;
6149
6150 while (++index < length) {
6151 var array = arguments[index];
6152 if (isArray(array) || isArguments(array)) {
6153 var result = result
6154 ? baseDifference(result, array).concat(baseDifference(array, result))
6155 : array;
6156 }
6157 }
6158 return result ? baseUniq(result) : [];
6159 }
6160
6161 /**
6162 * Creates an array of grouped elements, the first of which contains the first
6163 * elements of the given arrays, the second of which contains the second elements
6164 * of the given arrays, and so on.
6165 *
6166 * @static
6167 * @memberOf _
6168 * @category Array
6169 * @param {...Array} [arrays] The arrays to process.
6170 * @returns {Array} Returns the new array of grouped elements.
6171 * @example
6172 *
6173 * _.zip(['fred', 'barney'], [30, 40], [true, false]);
6174 * // => [['fred', 30, true], ['barney', 40, false]]
6175 */
6176 var zip = restParam(unzip);
6177
6178 /**
6179 * The inverse of `_.pairs`; this method returns an object composed from arrays
6180 * of property names and values. Provide either a single two dimensional array,
6181 * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
6182 * and one of corresponding values.
6183 *
6184 * @static
6185 * @memberOf _
6186 * @alias object
6187 * @category Array
6188 * @param {Array} props The property names.
6189 * @param {Array} [values=[]] The property values.
6190 * @returns {Object} Returns the new object.
6191 * @example
6192 *
6193 * _.zipObject([['fred', 30], ['barney', 40]]);
6194 * // => { 'fred': 30, 'barney': 40 }
6195 *
6196 * _.zipObject(['fred', 'barney'], [30, 40]);
6197 * // => { 'fred': 30, 'barney': 40 }
6198 */
6199 function zipObject(props, values) {
6200 var index = -1,
6201 length = props ? props.length : 0,
6202 result = {};
6203
6204 if (length && !values && !isArray(props[0])) {
6205 values = [];
6206 }
6207 while (++index < length) {
6208 var key = props[index];
6209 if (values) {
6210 result[key] = values[index];
6211 } else if (key) {
6212 result[key[0]] = key[1];
6213 }
6214 }
6215 return result;
6216 }
6217
6218 /*------------------------------------------------------------------------*/
6219
6220 /**
6221 * Creates a `lodash` object that wraps `value` with explicit method
6222 * chaining enabled.
6223 *
6224 * @static
6225 * @memberOf _
6226 * @category Chain
6227 * @param {*} value The value to wrap.
6228 * @returns {Object} Returns the new `lodash` wrapper instance.
6229 * @example
6230 *
6231 * var users = [
6232 * { 'user': 'barney', 'age': 36 },
6233 * { 'user': 'fred', 'age': 40 },
6234 * { 'user': 'pebbles', 'age': 1 }
6235 * ];
6236 *
6237 * var youngest = _.chain(users)
6238 * .sortBy('age')
6239 * .map(function(chr) {
6240 * return chr.user + ' is ' + chr.age;
6241 * })
6242 * .first()
6243 * .value();
6244 * // => 'pebbles is 1'
6245 */
6246 function chain(value) {
6247 var result = lodash(value);
6248 result.__chain__ = true;
6249 return result;
6250 }
6251
6252 /**
6253 * This method invokes `interceptor` and returns `value`. The interceptor is
6254 * bound to `thisArg` and invoked with one argument; (value). The purpose of
6255 * this method is to "tap into" a method chain in order to perform operations
6256 * on intermediate results within the chain.
6257 *
6258 * @static
6259 * @memberOf _
6260 * @category Chain
6261 * @param {*} value The value to provide to `interceptor`.
6262 * @param {Function} interceptor The function to invoke.
6263 * @param {*} [thisArg] The `this` binding of `interceptor`.
6264 * @returns {*} Returns `value`.
6265 * @example
6266 *
6267 * _([1, 2, 3])
6268 * .tap(function(array) {
6269 * array.pop();
6270 * })
6271 * .reverse()
6272 * .value();
6273 * // => [2, 1]
6274 */
6275 function tap(value, interceptor, thisArg) {
6276 interceptor.call(thisArg, value);
6277 return value;
6278 }
6279
6280 /**
6281 * This method is like `_.tap` except that it returns the result of `interceptor`.
6282 *
6283 * @static
6284 * @memberOf _
6285 * @category Chain
6286 * @param {*} value The value to provide to `interceptor`.
6287 * @param {Function} interceptor The function to invoke.
6288 * @param {*} [thisArg] The `this` binding of `interceptor`.
6289 * @returns {*} Returns the result of `interceptor`.
6290 * @example
6291 *
6292 * _(' abc ')
6293 * .chain()
6294 * .trim()
6295 * .thru(function(value) {
6296 * return [value];
6297 * })
6298 * .value();
6299 * // => ['abc']
6300 */
6301 function thru(value, interceptor, thisArg) {
6302 return interceptor.call(thisArg, value);
6303 }
6304
6305 /**
6306 * Enables explicit method chaining on the wrapper object.
6307 *
6308 * @name chain
6309 * @memberOf _
6310 * @category Chain
6311 * @returns {Object} Returns the new `lodash` wrapper instance.
6312 * @example
6313 *
6314 * var users = [
6315 * { 'user': 'barney', 'age': 36 },
6316 * { 'user': 'fred', 'age': 40 }
6317 * ];
6318 *
6319 * // without explicit chaining
6320 * _(users).first();
6321 * // => { 'user': 'barney', 'age': 36 }
6322 *
6323 * // with explicit chaining
6324 * _(users).chain()
6325 * .first()
6326 * .pick('user')
6327 * .value();
6328 * // => { 'user': 'barney' }
6329 */
6330 function wrapperChain() {
6331 return chain(this);
6332 }
6333
6334 /**
6335 * Executes the chained sequence and returns the wrapped result.
6336 *
6337 * @name commit
6338 * @memberOf _
6339 * @category Chain
6340 * @returns {Object} Returns the new `lodash` wrapper instance.
6341 * @example
6342 *
6343 * var array = [1, 2];
6344 * var wrapper = _(array).push(3);
6345 *
6346 * console.log(array);
6347 * // => [1, 2]
6348 *
6349 * wrapper = wrapper.commit();
6350 * console.log(array);
6351 * // => [1, 2, 3]
6352 *
6353 * wrapper.last();
6354 * // => 3
6355 *
6356 * console.log(array);
6357 * // => [1, 2, 3]
6358 */
6359 function wrapperCommit() {
6360 return new LodashWrapper(this.value(), this.__chain__);
6361 }
6362
6363 /**
6364 * Creates a clone of the chained sequence planting `value` as the wrapped value.
6365 *
6366 * @name plant
6367 * @memberOf _
6368 * @category Chain
6369 * @returns {Object} Returns the new `lodash` wrapper instance.
6370 * @example
6371 *
6372 * var array = [1, 2];
6373 * var wrapper = _(array).map(function(value) {
6374 * return Math.pow(value, 2);
6375 * });
6376 *
6377 * var other = [3, 4];
6378 * var otherWrapper = wrapper.plant(other);
6379 *
6380 * otherWrapper.value();
6381 * // => [9, 16]
6382 *
6383 * wrapper.value();
6384 * // => [1, 4]
6385 */
6386 function wrapperPlant(value) {
6387 var result,
6388 parent = this;
6389
6390 while (parent instanceof baseLodash) {
6391 var clone = wrapperClone(parent);
6392 if (result) {
6393 previous.__wrapped__ = clone;
6394 } else {
6395 result = clone;
6396 }
6397 var previous = clone;
6398 parent = parent.__wrapped__;
6399 }
6400 previous.__wrapped__ = value;
6401 return result;
6402 }
6403
6404 /**
6405 * Reverses the wrapped array so the first element becomes the last, the
6406 * second element becomes the second to last, and so on.
6407 *
6408 * **Note:** This method mutates the wrapped array.
6409 *
6410 * @name reverse
6411 * @memberOf _
6412 * @category Chain
6413 * @returns {Object} Returns the new reversed `lodash` wrapper instance.
6414 * @example
6415 *
6416 * var array = [1, 2, 3];
6417 *
6418 * _(array).reverse().value()
6419 * // => [3, 2, 1]
6420 *
6421 * console.log(array);
6422 * // => [3, 2, 1]
6423 */
6424 function wrapperReverse() {
6425 var value = this.__wrapped__;
6426 if (value instanceof LazyWrapper) {
6427 if (this.__actions__.length) {
6428 value = new LazyWrapper(this);
6429 }
6430 return new LodashWrapper(value.reverse(), this.__chain__);
6431 }
6432 return this.thru(function(value) {
6433 return value.reverse();
6434 });
6435 }
6436
6437 /**
6438 * Produces the result of coercing the unwrapped value to a string.
6439 *
6440 * @name toString
6441 * @memberOf _
6442 * @category Chain
6443 * @returns {string} Returns the coerced string value.
6444 * @example
6445 *
6446 * _([1, 2, 3]).toString();
6447 * // => '1,2,3'
6448 */
6449 function wrapperToString() {
6450 return (this.value() + '');
6451 }
6452
6453 /**
6454 * Executes the chained sequence to extract the unwrapped value.
6455 *
6456 * @name value
6457 * @memberOf _
6458 * @alias run, toJSON, valueOf
6459 * @category Chain
6460 * @returns {*} Returns the resolved unwrapped value.
6461 * @example
6462 *
6463 * _([1, 2, 3]).value();
6464 * // => [1, 2, 3]
6465 */
6466 function wrapperValue() {
6467 return baseWrapperValue(this.__wrapped__, this.__actions__);
6468 }
6469
6470 /*------------------------------------------------------------------------*/
6471
6472 /**
6473 * Creates an array of elements corresponding to the given keys, or indexes,
6474 * of `collection`. Keys may be specified as individual arguments or as arrays
6475 * of keys.
6476 *
6477 * @static
6478 * @memberOf _
6479 * @category Collection
6480 * @param {Array|Object|string} collection The collection to iterate over.
6481 * @param {...(number|number[]|string|string[])} [props] The property names
6482 * or indexes of elements to pick, specified individually or in arrays.
6483 * @returns {Array} Returns the new array of picked elements.
6484 * @example
6485 *
6486 * _.at(['a', 'b', 'c'], [0, 2]);
6487 * // => ['a', 'c']
6488 *
6489 * _.at(['barney', 'fred', 'pebbles'], 0, 2);
6490 * // => ['barney', 'pebbles']
6491 */
6492 var at = restParam(function(collection, props) {
6493 var length = collection ? collection.length : 0;
6494 if (isLength(length)) {
6495 collection = toIterable(collection);
6496 }
6497 return baseAt(collection, baseFlatten(props));
6498 });
6499
6500 /**
6501 * Creates an object composed of keys generated from the results of running
6502 * each element of `collection` through `iteratee`. The corresponding value
6503 * of each key is the number of times the key was returned by `iteratee`.
6504 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6505 * (value, index|key, collection).
6506 *
6507 * If a property name is provided for `iteratee` the created `_.property`
6508 * style callback returns the property value of the given element.
6509 *
6510 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6511 * style callback returns `true` for elements that have a matching property
6512 * value, else `false`.
6513 *
6514 * If an object is provided for `iteratee` the created `_.matches` style
6515 * callback returns `true` for elements that have the properties of the given
6516 * object, else `false`.
6517 *
6518 * @static
6519 * @memberOf _
6520 * @category Collection
6521 * @param {Array|Object|string} collection The collection to iterate over.
6522 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6523 * per iteration.
6524 * @param {*} [thisArg] The `this` binding of `iteratee`.
6525 * @returns {Object} Returns the composed aggregate object.
6526 * @example
6527 *
6528 * _.countBy([4.3, 6.1, 6.4], function(n) {
6529 * return Math.floor(n);
6530 * });
6531 * // => { '4': 1, '6': 2 }
6532 *
6533 * _.countBy([4.3, 6.1, 6.4], function(n) {
6534 * return this.floor(n);
6535 * }, Math);
6536 * // => { '4': 1, '6': 2 }
6537 *
6538 * _.countBy(['one', 'two', 'three'], 'length');
6539 * // => { '3': 2, '5': 1 }
6540 */
6541 var countBy = createAggregator(function(result, value, key) {
6542 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
6543 });
6544
6545 /**
6546 * Checks if `predicate` returns truthy for **all** elements of `collection`.
6547 * The predicate is bound to `thisArg` and invoked with three arguments:
6548 * (value, index|key, collection).
6549 *
6550 * If a property name is provided for `predicate` the created `_.property`
6551 * style callback returns the property value of the given element.
6552 *
6553 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6554 * style callback returns `true` for elements that have a matching property
6555 * value, else `false`.
6556 *
6557 * If an object is provided for `predicate` the created `_.matches` style
6558 * callback returns `true` for elements that have the properties of the given
6559 * object, else `false`.
6560 *
6561 * @static
6562 * @memberOf _
6563 * @alias all
6564 * @category Collection
6565 * @param {Array|Object|string} collection The collection to iterate over.
6566 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6567 * per iteration.
6568 * @param {*} [thisArg] The `this` binding of `predicate`.
6569 * @returns {boolean} Returns `true` if all elements pass the predicate check,
6570 * else `false`.
6571 * @example
6572 *
6573 * _.every([true, 1, null, 'yes'], Boolean);
6574 * // => false
6575 *
6576 * var users = [
6577 * { 'user': 'barney', 'active': false },
6578 * { 'user': 'fred', 'active': false }
6579 * ];
6580 *
6581 * // using the `_.matches` callback shorthand
6582 * _.every(users, { 'user': 'barney', 'active': false });
6583 * // => false
6584 *
6585 * // using the `_.matchesProperty` callback shorthand
6586 * _.every(users, 'active', false);
6587 * // => true
6588 *
6589 * // using the `_.property` callback shorthand
6590 * _.every(users, 'active');
6591 * // => false
6592 */
6593 function every(collection, predicate, thisArg) {
6594 var func = isArray(collection) ? arrayEvery : baseEvery;
6595 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
6596 predicate = null;
6597 }
6598 if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
6599 predicate = getCallback(predicate, thisArg, 3);
6600 }
6601 return func(collection, predicate);
6602 }
6603
6604 /**
6605 * Iterates over elements of `collection`, returning an array of all elements
6606 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
6607 * invoked with three arguments: (value, index|key, collection).
6608 *
6609 * If a property name is provided for `predicate` the created `_.property`
6610 * style callback returns the property value of the given element.
6611 *
6612 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6613 * style callback returns `true` for elements that have a matching property
6614 * value, else `false`.
6615 *
6616 * If an object is provided for `predicate` the created `_.matches` style
6617 * callback returns `true` for elements that have the properties of the given
6618 * object, else `false`.
6619 *
6620 * @static
6621 * @memberOf _
6622 * @alias select
6623 * @category Collection
6624 * @param {Array|Object|string} collection The collection to iterate over.
6625 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6626 * per iteration.
6627 * @param {*} [thisArg] The `this` binding of `predicate`.
6628 * @returns {Array} Returns the new filtered array.
6629 * @example
6630 *
6631 * _.filter([4, 5, 6], function(n) {
6632 * return n % 2 == 0;
6633 * });
6634 * // => [4, 6]
6635 *
6636 * var users = [
6637 * { 'user': 'barney', 'age': 36, 'active': true },
6638 * { 'user': 'fred', 'age': 40, 'active': false }
6639 * ];
6640 *
6641 * // using the `_.matches` callback shorthand
6642 * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
6643 * // => ['barney']
6644 *
6645 * // using the `_.matchesProperty` callback shorthand
6646 * _.pluck(_.filter(users, 'active', false), 'user');
6647 * // => ['fred']
6648 *
6649 * // using the `_.property` callback shorthand
6650 * _.pluck(_.filter(users, 'active'), 'user');
6651 * // => ['barney']
6652 */
6653 function filter(collection, predicate, thisArg) {
6654 var func = isArray(collection) ? arrayFilter : baseFilter;
6655 predicate = getCallback(predicate, thisArg, 3);
6656 return func(collection, predicate);
6657 }
6658
6659 /**
6660 * Iterates over elements of `collection`, returning the first element
6661 * `predicate` returns truthy for. The predicate is bound to `thisArg` and
6662 * invoked with three arguments: (value, index|key, collection).
6663 *
6664 * If a property name is provided for `predicate` the created `_.property`
6665 * style callback returns the property value of the given element.
6666 *
6667 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6668 * style callback returns `true` for elements that have a matching property
6669 * value, else `false`.
6670 *
6671 * If an object is provided for `predicate` the created `_.matches` style
6672 * callback returns `true` for elements that have the properties of the given
6673 * object, else `false`.
6674 *
6675 * @static
6676 * @memberOf _
6677 * @alias detect
6678 * @category Collection
6679 * @param {Array|Object|string} collection The collection to search.
6680 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6681 * per iteration.
6682 * @param {*} [thisArg] The `this` binding of `predicate`.
6683 * @returns {*} Returns the matched element, else `undefined`.
6684 * @example
6685 *
6686 * var users = [
6687 * { 'user': 'barney', 'age': 36, 'active': true },
6688 * { 'user': 'fred', 'age': 40, 'active': false },
6689 * { 'user': 'pebbles', 'age': 1, 'active': true }
6690 * ];
6691 *
6692 * _.result(_.find(users, function(chr) {
6693 * return chr.age < 40;
6694 * }), 'user');
6695 * // => 'barney'
6696 *
6697 * // using the `_.matches` callback shorthand
6698 * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
6699 * // => 'pebbles'
6700 *
6701 * // using the `_.matchesProperty` callback shorthand
6702 * _.result(_.find(users, 'active', false), 'user');
6703 * // => 'fred'
6704 *
6705 * // using the `_.property` callback shorthand
6706 * _.result(_.find(users, 'active'), 'user');
6707 * // => 'barney'
6708 */
6709 var find = createFind(baseEach);
6710
6711 /**
6712 * This method is like `_.find` except that it iterates over elements of
6713 * `collection` from right to left.
6714 *
6715 * @static
6716 * @memberOf _
6717 * @category Collection
6718 * @param {Array|Object|string} collection The collection to search.
6719 * @param {Function|Object|string} [predicate=_.identity] The function invoked
6720 * per iteration.
6721 * @param {*} [thisArg] The `this` binding of `predicate`.
6722 * @returns {*} Returns the matched element, else `undefined`.
6723 * @example
6724 *
6725 * _.findLast([1, 2, 3, 4], function(n) {
6726 * return n % 2 == 1;
6727 * });
6728 * // => 3
6729 */
6730 var findLast = createFind(baseEachRight, true);
6731
6732 /**
6733 * Performs a deep comparison between each element in `collection` and the
6734 * source object, returning the first element that has equivalent property
6735 * values.
6736 *
6737 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
6738 * numbers, `Object` objects, regexes, and strings. Objects are compared by
6739 * their own, not inherited, enumerable properties. For comparing a single
6740 * own or inherited property value see `_.matchesProperty`.
6741 *
6742 * @static
6743 * @memberOf _
6744 * @category Collection
6745 * @param {Array|Object|string} collection The collection to search.
6746 * @param {Object} source The object of property values to match.
6747 * @returns {*} Returns the matched element, else `undefined`.
6748 * @example
6749 *
6750 * var users = [
6751 * { 'user': 'barney', 'age': 36, 'active': true },
6752 * { 'user': 'fred', 'age': 40, 'active': false }
6753 * ];
6754 *
6755 * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
6756 * // => 'barney'
6757 *
6758 * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
6759 * // => 'fred'
6760 */
6761 function findWhere(collection, source) {
6762 return find(collection, baseMatches(source));
6763 }
6764
6765 /**
6766 * Iterates over elements of `collection` invoking `iteratee` for each element.
6767 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6768 * (value, index|key, collection). Iterator functions may exit iteration early
6769 * by explicitly returning `false`.
6770 *
6771 * **Note:** As with other "Collections" methods, objects with a `length` property
6772 * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
6773 * may be used for object iteration.
6774 *
6775 * @static
6776 * @memberOf _
6777 * @alias each
6778 * @category Collection
6779 * @param {Array|Object|string} collection The collection to iterate over.
6780 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6781 * @param {*} [thisArg] The `this` binding of `iteratee`.
6782 * @returns {Array|Object|string} Returns `collection`.
6783 * @example
6784 *
6785 * _([1, 2]).forEach(function(n) {
6786 * console.log(n);
6787 * }).value();
6788 * // => logs each value from left to right and returns the array
6789 *
6790 * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
6791 * console.log(n, key);
6792 * });
6793 * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
6794 */
6795 var forEach = createForEach(arrayEach, baseEach);
6796
6797 /**
6798 * This method is like `_.forEach` except that it iterates over elements of
6799 * `collection` from right to left.
6800 *
6801 * @static
6802 * @memberOf _
6803 * @alias eachRight
6804 * @category Collection
6805 * @param {Array|Object|string} collection The collection to iterate over.
6806 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
6807 * @param {*} [thisArg] The `this` binding of `iteratee`.
6808 * @returns {Array|Object|string} Returns `collection`.
6809 * @example
6810 *
6811 * _([1, 2]).forEachRight(function(n) {
6812 * console.log(n);
6813 * }).value();
6814 * // => logs each value from right to left and returns the array
6815 */
6816 var forEachRight = createForEach(arrayEachRight, baseEachRight);
6817
6818 /**
6819 * Creates an object composed of keys generated from the results of running
6820 * each element of `collection` through `iteratee`. The corresponding value
6821 * of each key is an array of the elements responsible for generating the key.
6822 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
6823 * (value, index|key, collection).
6824 *
6825 * If a property name is provided for `iteratee` the created `_.property`
6826 * style callback returns the property value of the given element.
6827 *
6828 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6829 * style callback returns `true` for elements that have a matching property
6830 * value, else `false`.
6831 *
6832 * If an object is provided for `iteratee` the created `_.matches` style
6833 * callback returns `true` for elements that have the properties of the given
6834 * object, else `false`.
6835 *
6836 * @static
6837 * @memberOf _
6838 * @category Collection
6839 * @param {Array|Object|string} collection The collection to iterate over.
6840 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6841 * per iteration.
6842 * @param {*} [thisArg] The `this` binding of `iteratee`.
6843 * @returns {Object} Returns the composed aggregate object.
6844 * @example
6845 *
6846 * _.groupBy([4.2, 6.1, 6.4], function(n) {
6847 * return Math.floor(n);
6848 * });
6849 * // => { '4': [4.2], '6': [6.1, 6.4] }
6850 *
6851 * _.groupBy([4.2, 6.1, 6.4], function(n) {
6852 * return this.floor(n);
6853 * }, Math);
6854 * // => { '4': [4.2], '6': [6.1, 6.4] }
6855 *
6856 * // using the `_.property` callback shorthand
6857 * _.groupBy(['one', 'two', 'three'], 'length');
6858 * // => { '3': ['one', 'two'], '5': ['three'] }
6859 */
6860 var groupBy = createAggregator(function(result, value, key) {
6861 if (hasOwnProperty.call(result, key)) {
6862 result[key].push(value);
6863 } else {
6864 result[key] = [value];
6865 }
6866 });
6867
6868 /**
6869 * Checks if `value` is in `collection` using `SameValueZero` for equality
6870 * comparisons. If `fromIndex` is negative, it is used as the offset from
6871 * the end of `collection`.
6872 *
6873 * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
6874 * comparisons are like strict equality comparisons, e.g. `===`, except that
6875 * `NaN` matches `NaN`.
6876 *
6877 * @static
6878 * @memberOf _
6879 * @alias contains, include
6880 * @category Collection
6881 * @param {Array|Object|string} collection The collection to search.
6882 * @param {*} target The value to search for.
6883 * @param {number} [fromIndex=0] The index to search from.
6884 * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
6885 * @returns {boolean} Returns `true` if a matching element is found, else `false`.
6886 * @example
6887 *
6888 * _.includes([1, 2, 3], 1);
6889 * // => true
6890 *
6891 * _.includes([1, 2, 3], 1, 2);
6892 * // => false
6893 *
6894 * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
6895 * // => true
6896 *
6897 * _.includes('pebbles', 'eb');
6898 * // => true
6899 */
6900 function includes(collection, target, fromIndex, guard) {
6901 var length = collection ? collection.length : 0;
6902 if (!isLength(length)) {
6903 collection = values(collection);
6904 length = collection.length;
6905 }
6906 if (!length) {
6907 return false;
6908 }
6909 if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
6910 fromIndex = 0;
6911 } else {
6912 fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
6913 }
6914 return (typeof collection == 'string' || !isArray(collection) && isString(collection))
6915 ? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
6916 : (getIndexOf(collection, target, fromIndex) > -1);
6917 }
6918
6919 /**
6920 * Creates an object composed of keys generated from the results of running
6921 * each element of `collection` through `iteratee`. The corresponding value
6922 * of each key is the last element responsible for generating the key. The
6923 * iteratee function is bound to `thisArg` and invoked with three arguments:
6924 * (value, index|key, collection).
6925 *
6926 * If a property name is provided for `iteratee` the created `_.property`
6927 * style callback returns the property value of the given element.
6928 *
6929 * If a value is also provided for `thisArg` the created `_.matchesProperty`
6930 * style callback returns `true` for elements that have a matching property
6931 * value, else `false`.
6932 *
6933 * If an object is provided for `iteratee` the created `_.matches` style
6934 * callback returns `true` for elements that have the properties of the given
6935 * object, else `false`.
6936 *
6937 * @static
6938 * @memberOf _
6939 * @category Collection
6940 * @param {Array|Object|string} collection The collection to iterate over.
6941 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
6942 * per iteration.
6943 * @param {*} [thisArg] The `this` binding of `iteratee`.
6944 * @returns {Object} Returns the composed aggregate object.
6945 * @example
6946 *
6947 * var keyData = [
6948 * { 'dir': 'left', 'code': 97 },
6949 * { 'dir': 'right', 'code': 100 }
6950 * ];
6951 *
6952 * _.indexBy(keyData, 'dir');
6953 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
6954 *
6955 * _.indexBy(keyData, function(object) {
6956 * return String.fromCharCode(object.code);
6957 * });
6958 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
6959 *
6960 * _.indexBy(keyData, function(object) {
6961 * return this.fromCharCode(object.code);
6962 * }, String);
6963 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
6964 */
6965 var indexBy = createAggregator(function(result, value, key) {
6966 result[key] = value;
6967 });
6968
6969 /**
6970 * Invokes the method named by `methodName` on each element in `collection`,
6971 * returning an array of the results of each invoked method. Any additional
6972 * arguments are provided to each invoked method. If `methodName` is a function
6973 * it is invoked for, and `this` bound to, each element in `collection`.
6974 *
6975 * @static
6976 * @memberOf _
6977 * @category Collection
6978 * @param {Array|Object|string} collection The collection to iterate over.
6979 * @param {Function|string} methodName The name of the method to invoke or
6980 * the function invoked per iteration.
6981 * @param {...*} [args] The arguments to invoke the method with.
6982 * @returns {Array} Returns the array of results.
6983 * @example
6984 *
6985 * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
6986 * // => [[1, 5, 7], [1, 2, 3]]
6987 *
6988 * _.invoke([123, 456], String.prototype.split, '');
6989 * // => [['1', '2', '3'], ['4', '5', '6']]
6990 */
6991 var invoke = restParam(function(collection, methodName, args) {
6992 var index = -1,
6993 isFunc = typeof methodName == 'function',
6994 length = collection ? collection.length : 0,
6995 result = isLength(length) ? Array(length) : [];
6996
6997 baseEach(collection, function(value) {
6998 var func = isFunc ? methodName : (value != null && value[methodName]);
6999 result[++index] = func ? func.apply(value, args) : undefined;
7000 });
7001 return result;
7002 });
7003
7004 /**
7005 * Creates an array of values by running each element in `collection` through
7006 * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
7007 * arguments: (value, index|key, collection).
7008 *
7009 * If a property name is provided for `iteratee` the created `_.property`
7010 * style callback returns the property value of the given element.
7011 *
7012 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7013 * style callback returns `true` for elements that have a matching property
7014 * value, else `false`.
7015 *
7016 * If an object is provided for `iteratee` the created `_.matches` style
7017 * callback returns `true` for elements that have the properties of the given
7018 * object, else `false`.
7019 *
7020 * Many lodash methods are guarded to work as interatees for methods like
7021 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
7022 *
7023 * The guarded methods are:
7024 * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
7025 * `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`,
7026 * `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`,
7027 * `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words`
7028 *
7029 * @static
7030 * @memberOf _
7031 * @alias collect
7032 * @category Collection
7033 * @param {Array|Object|string} collection The collection to iterate over.
7034 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
7035 * per iteration.
7036 * create a `_.property` or `_.matches` style callback respectively.
7037 * @param {*} [thisArg] The `this` binding of `iteratee`.
7038 * @returns {Array} Returns the new mapped array.
7039 * @example
7040 *
7041 * function timesThree(n) {
7042 * return n * 3;
7043 * }
7044 *
7045 * _.map([1, 2], timesThree);
7046 * // => [3, 6]
7047 *
7048 * _.map({ 'a': 1, 'b': 2 }, timesThree);
7049 * // => [3, 6] (iteration order is not guaranteed)
7050 *
7051 * var users = [
7052 * { 'user': 'barney' },
7053 * { 'user': 'fred' }
7054 * ];
7055 *
7056 * // using the `_.property` callback shorthand
7057 * _.map(users, 'user');
7058 * // => ['barney', 'fred']
7059 */
7060 function map(collection, iteratee, thisArg) {
7061 var func = isArray(collection) ? arrayMap : baseMap;
7062 iteratee = getCallback(iteratee, thisArg, 3);
7063 return func(collection, iteratee);
7064 }
7065
7066 /**
7067 * Creates an array of elements split into two groups, the first of which
7068 * contains elements `predicate` returns truthy for, while the second of which
7069 * contains elements `predicate` returns falsey for. The predicate is bound
7070 * to `thisArg` and invoked with three arguments: (value, index|key, collection).
7071 *
7072 * If a property name is provided for `predicate` the created `_.property`
7073 * style callback returns the property value of the given element.
7074 *
7075 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7076 * style callback returns `true` for elements that have a matching property
7077 * value, else `false`.
7078 *
7079 * If an object is provided for `predicate` the created `_.matches` style
7080 * callback returns `true` for elements that have the properties of the given
7081 * object, else `false`.
7082 *
7083 * @static
7084 * @memberOf _
7085 * @category Collection
7086 * @param {Array|Object|string} collection The collection to iterate over.
7087 * @param {Function|Object|string} [predicate=_.identity] The function invoked
7088 * per iteration.
7089 * @param {*} [thisArg] The `this` binding of `predicate`.
7090 * @returns {Array} Returns the array of grouped elements.
7091 * @example
7092 *
7093 * _.partition([1, 2, 3], function(n) {
7094 * return n % 2;
7095 * });
7096 * // => [[1, 3], [2]]
7097 *
7098 * _.partition([1.2, 2.3, 3.4], function(n) {
7099 * return this.floor(n) % 2;
7100 * }, Math);
7101 * // => [[1.2, 3.4], [2.3]]
7102 *
7103 * var users = [
7104 * { 'user': 'barney', 'age': 36, 'active': false },
7105 * { 'user': 'fred', 'age': 40, 'active': true },
7106 * { 'user': 'pebbles', 'age': 1, 'active': false }
7107 * ];
7108 *
7109 * var mapper = function(array) {
7110 * return _.pluck(array, 'user');
7111 * };
7112 *
7113 * // using the `_.matches` callback shorthand
7114 * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
7115 * // => [['pebbles'], ['barney', 'fred']]
7116 *
7117 * // using the `_.matchesProperty` callback shorthand
7118 * _.map(_.partition(users, 'active', false), mapper);
7119 * // => [['barney', 'pebbles'], ['fred']]
7120 *
7121 * // using the `_.property` callback shorthand
7122 * _.map(_.partition(users, 'active'), mapper);
7123 * // => [['fred'], ['barney', 'pebbles']]
7124 */
7125 var partition = createAggregator(function(result, value, key) {
7126 result[key ? 0 : 1].push(value);
7127 }, function() { return [[], []]; });
7128
7129 /**
7130 * Gets the value of `key` from all elements in `collection`.
7131 *
7132 * @static
7133 * @memberOf _
7134 * @category Collection
7135 * @param {Array|Object|string} collection The collection to iterate over.
7136 * @param {string} key The key of the property to pluck.
7137 * @returns {Array} Returns the property values.
7138 * @example
7139 *
7140 * var users = [
7141 * { 'user': 'barney', 'age': 36 },
7142 * { 'user': 'fred', 'age': 40 }
7143 * ];
7144 *
7145 * _.pluck(users, 'user');
7146 * // => ['barney', 'fred']
7147 *
7148 * var userIndex = _.indexBy(users, 'user');
7149 * _.pluck(userIndex, 'age');
7150 * // => [36, 40] (iteration order is not guaranteed)
7151 */
7152 function pluck(collection, key) {
7153 return map(collection, baseProperty(key));
7154 }
7155
7156 /**
7157 * Reduces `collection` to a value which is the accumulated result of running
7158 * each element in `collection` through `iteratee`, where each successive
7159 * invocation is supplied the return value of the previous. If `accumulator`
7160 * is not provided the first element of `collection` is used as the initial
7161 * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
7162 * (accumulator, value, index|key, collection).
7163 *
7164 * Many lodash methods are guarded to work as interatees for methods like
7165 * `_.reduce`, `_.reduceRight`, and `_.transform`.
7166 *
7167 * The guarded methods are:
7168 * `assign`, `defaults`, `includes`, `merge`, `sortByAll`, and `sortByOrder`
7169 *
7170 * @static
7171 * @memberOf _
7172 * @alias foldl, inject
7173 * @category Collection
7174 * @param {Array|Object|string} collection The collection to iterate over.
7175 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7176 * @param {*} [accumulator] The initial value.
7177 * @param {*} [thisArg] The `this` binding of `iteratee`.
7178 * @returns {*} Returns the accumulated value.
7179 * @example
7180 *
7181 * _.reduce([1, 2], function(sum, n) {
7182 * return sum + n;
7183 * });
7184 * // => 3
7185 *
7186 * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
7187 * result[key] = n * 3;
7188 * return result;
7189 * }, {});
7190 * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
7191 */
7192 var reduce = createReduce(arrayReduce, baseEach);
7193
7194 /**
7195 * This method is like `_.reduce` except that it iterates over elements of
7196 * `collection` from right to left.
7197 *
7198 * @static
7199 * @memberOf _
7200 * @alias foldr
7201 * @category Collection
7202 * @param {Array|Object|string} collection The collection to iterate over.
7203 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
7204 * @param {*} [accumulator] The initial value.
7205 * @param {*} [thisArg] The `this` binding of `iteratee`.
7206 * @returns {*} Returns the accumulated value.
7207 * @example
7208 *
7209 * var array = [[0, 1], [2, 3], [4, 5]];
7210 *
7211 * _.reduceRight(array, function(flattened, other) {
7212 * return flattened.concat(other);
7213 * }, []);
7214 * // => [4, 5, 2, 3, 0, 1]
7215 */
7216 var reduceRight = createReduce(arrayReduceRight, baseEachRight);
7217
7218 /**
7219 * The opposite of `_.filter`; this method returns the elements of `collection`
7220 * that `predicate` does **not** return truthy for.
7221 *
7222 * If a property name is provided for `predicate` the created `_.property`
7223 * style callback returns the property value of the given element.
7224 *
7225 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7226 * style callback returns `true` for elements that have a matching property
7227 * value, else `false`.
7228 *
7229 * If an object is provided for `predicate` the created `_.matches` style
7230 * callback returns `true` for elements that have the properties of the given
7231 * object, else `false`.
7232 *
7233 * @static
7234 * @memberOf _
7235 * @category Collection
7236 * @param {Array|Object|string} collection The collection to iterate over.
7237 * @param {Function|Object|string} [predicate=_.identity] The function invoked
7238 * per iteration.
7239 * @param {*} [thisArg] The `this` binding of `predicate`.
7240 * @returns {Array} Returns the new filtered array.
7241 * @example
7242 *
7243 * _.reject([1, 2, 3, 4], function(n) {
7244 * return n % 2 == 0;
7245 * });
7246 * // => [1, 3]
7247 *
7248 * var users = [
7249 * { 'user': 'barney', 'age': 36, 'active': false },
7250 * { 'user': 'fred', 'age': 40, 'active': true }
7251 * ];
7252 *
7253 * // using the `_.matches` callback shorthand
7254 * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
7255 * // => ['barney']
7256 *
7257 * // using the `_.matchesProperty` callback shorthand
7258 * _.pluck(_.reject(users, 'active', false), 'user');
7259 * // => ['fred']
7260 *
7261 * // using the `_.property` callback shorthand
7262 * _.pluck(_.reject(users, 'active'), 'user');
7263 * // => ['barney']
7264 */
7265 function reject(collection, predicate, thisArg) {
7266 var func = isArray(collection) ? arrayFilter : baseFilter;
7267 predicate = getCallback(predicate, thisArg, 3);
7268 return func(collection, function(value, index, collection) {
7269 return !predicate(value, index, collection);
7270 });
7271 }
7272
7273 /**
7274 * Gets a random element or `n` random elements from a collection.
7275 *
7276 * @static
7277 * @memberOf _
7278 * @category Collection
7279 * @param {Array|Object|string} collection The collection to sample.
7280 * @param {number} [n] The number of elements to sample.
7281 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7282 * @returns {*} Returns the random sample(s).
7283 * @example
7284 *
7285 * _.sample([1, 2, 3, 4]);
7286 * // => 2
7287 *
7288 * _.sample([1, 2, 3, 4], 2);
7289 * // => [3, 1]
7290 */
7291 function sample(collection, n, guard) {
7292 if (guard ? isIterateeCall(collection, n, guard) : n == null) {
7293 collection = toIterable(collection);
7294 var length = collection.length;
7295 return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
7296 }
7297 var result = shuffle(collection);
7298 result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
7299 return result;
7300 }
7301
7302 /**
7303 * Creates an array of shuffled values, using a version of the
7304 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
7305 *
7306 * @static
7307 * @memberOf _
7308 * @category Collection
7309 * @param {Array|Object|string} collection The collection to shuffle.
7310 * @returns {Array} Returns the new shuffled array.
7311 * @example
7312 *
7313 * _.shuffle([1, 2, 3, 4]);
7314 * // => [4, 1, 3, 2]
7315 */
7316 function shuffle(collection) {
7317 collection = toIterable(collection);
7318
7319 var index = -1,
7320 length = collection.length,
7321 result = Array(length);
7322
7323 while (++index < length) {
7324 var rand = baseRandom(0, index);
7325 if (index != rand) {
7326 result[index] = result[rand];
7327 }
7328 result[rand] = collection[index];
7329 }
7330 return result;
7331 }
7332
7333 /**
7334 * Gets the size of `collection` by returning its length for array-like
7335 * values or the number of own enumerable properties for objects.
7336 *
7337 * @static
7338 * @memberOf _
7339 * @category Collection
7340 * @param {Array|Object|string} collection The collection to inspect.
7341 * @returns {number} Returns the size of `collection`.
7342 * @example
7343 *
7344 * _.size([1, 2, 3]);
7345 * // => 3
7346 *
7347 * _.size({ 'a': 1, 'b': 2 });
7348 * // => 2
7349 *
7350 * _.size('pebbles');
7351 * // => 7
7352 */
7353 function size(collection) {
7354 var length = collection ? collection.length : 0;
7355 return isLength(length) ? length : keys(collection).length;
7356 }
7357
7358 /**
7359 * Checks if `predicate` returns truthy for **any** element of `collection`.
7360 * The function returns as soon as it finds a passing value and does not iterate
7361 * over the entire collection. The predicate is bound to `thisArg` and invoked
7362 * with three arguments: (value, index|key, collection).
7363 *
7364 * If a property name is provided for `predicate` the created `_.property`
7365 * style callback returns the property value of the given element.
7366 *
7367 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7368 * style callback returns `true` for elements that have a matching property
7369 * value, else `false`.
7370 *
7371 * If an object is provided for `predicate` the created `_.matches` style
7372 * callback returns `true` for elements that have the properties of the given
7373 * object, else `false`.
7374 *
7375 * @static
7376 * @memberOf _
7377 * @alias any
7378 * @category Collection
7379 * @param {Array|Object|string} collection The collection to iterate over.
7380 * @param {Function|Object|string} [predicate=_.identity] The function invoked
7381 * per iteration.
7382 * @param {*} [thisArg] The `this` binding of `predicate`.
7383 * @returns {boolean} Returns `true` if any element passes the predicate check,
7384 * else `false`.
7385 * @example
7386 *
7387 * _.some([null, 0, 'yes', false], Boolean);
7388 * // => true
7389 *
7390 * var users = [
7391 * { 'user': 'barney', 'active': true },
7392 * { 'user': 'fred', 'active': false }
7393 * ];
7394 *
7395 * // using the `_.matches` callback shorthand
7396 * _.some(users, { 'user': 'barney', 'active': false });
7397 * // => false
7398 *
7399 * // using the `_.matchesProperty` callback shorthand
7400 * _.some(users, 'active', false);
7401 * // => true
7402 *
7403 * // using the `_.property` callback shorthand
7404 * _.some(users, 'active');
7405 * // => true
7406 */
7407 function some(collection, predicate, thisArg) {
7408 var func = isArray(collection) ? arraySome : baseSome;
7409 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
7410 predicate = null;
7411 }
7412 if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
7413 predicate = getCallback(predicate, thisArg, 3);
7414 }
7415 return func(collection, predicate);
7416 }
7417
7418 /**
7419 * Creates an array of elements, sorted in ascending order by the results of
7420 * running each element in a collection through `iteratee`. This method performs
7421 * a stable sort, that is, it preserves the original sort order of equal elements.
7422 * The `iteratee` is bound to `thisArg` and invoked with three arguments:
7423 * (value, index|key, collection).
7424 *
7425 * If a property name is provided for `iteratee` the created `_.property`
7426 * style callback returns the property value of the given element.
7427 *
7428 * If a value is also provided for `thisArg` the created `_.matchesProperty`
7429 * style callback returns `true` for elements that have a matching property
7430 * value, else `false`.
7431 *
7432 * If an object is provided for `iteratee` the created `_.matches` style
7433 * callback returns `true` for elements that have the properties of the given
7434 * object, else `false`.
7435 *
7436 * @static
7437 * @memberOf _
7438 * @category Collection
7439 * @param {Array|Object|string} collection The collection to iterate over.
7440 * @param {Array|Function|Object|string} [iteratee=_.identity] The function
7441 * invoked per iteration. If a property name or an object is provided it is
7442 * used to create a `_.property` or `_.matches` style callback respectively.
7443 * @param {*} [thisArg] The `this` binding of `iteratee`.
7444 * @returns {Array} Returns the new sorted array.
7445 * @example
7446 *
7447 * _.sortBy([1, 2, 3], function(n) {
7448 * return Math.sin(n);
7449 * });
7450 * // => [3, 1, 2]
7451 *
7452 * _.sortBy([1, 2, 3], function(n) {
7453 * return this.sin(n);
7454 * }, Math);
7455 * // => [3, 1, 2]
7456 *
7457 * var users = [
7458 * { 'user': 'fred' },
7459 * { 'user': 'pebbles' },
7460 * { 'user': 'barney' }
7461 * ];
7462 *
7463 * // using the `_.property` callback shorthand
7464 * _.pluck(_.sortBy(users, 'user'), 'user');
7465 * // => ['barney', 'fred', 'pebbles']
7466 */
7467 function sortBy(collection, iteratee, thisArg) {
7468 if (collection == null) {
7469 return [];
7470 }
7471 var index = -1,
7472 length = collection.length,
7473 result = isLength(length) ? Array(length) : [];
7474
7475 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
7476 iteratee = null;
7477 }
7478 iteratee = getCallback(iteratee, thisArg, 3);
7479 baseEach(collection, function(value, key, collection) {
7480 result[++index] = { 'criteria': iteratee(value, key, collection), 'index': index, 'value': value };
7481 });
7482 return baseSortBy(result, compareAscending);
7483 }
7484
7485 /**
7486 * This method is like `_.sortBy` except that it sorts by property names
7487 * instead of an iteratee function.
7488 *
7489 * @static
7490 * @memberOf _
7491 * @category Collection
7492 * @param {Array|Object|string} collection The collection to iterate over.
7493 * @param {...(string|string[])} props The property names to sort by,
7494 * specified as individual property names or arrays of property names.
7495 * @returns {Array} Returns the new sorted array.
7496 * @example
7497 *
7498 * var users = [
7499 * { 'user': 'barney', 'age': 36 },
7500 * { 'user': 'fred', 'age': 40 },
7501 * { 'user': 'barney', 'age': 26 },
7502 * { 'user': 'fred', 'age': 30 }
7503 * ];
7504 *
7505 * _.map(_.sortByAll(users, ['user', 'age']), _.values);
7506 * // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
7507 */
7508 function sortByAll() {
7509 var args = arguments,
7510 collection = args[0],
7511 guard = args[3],
7512 index = 0,
7513 length = args.length - 1;
7514
7515 if (collection == null) {
7516 return [];
7517 }
7518 var props = Array(length);
7519 while (index < length) {
7520 props[index] = args[++index];
7521 }
7522 if (guard && isIterateeCall(args[1], args[2], guard)) {
7523 props = args[1];
7524 }
7525 return baseSortByOrder(collection, baseFlatten(props), []);
7526 }
7527
7528 /**
7529 * This method is like `_.sortByAll` except that it allows specifying the
7530 * sort orders of the property names to sort by. A truthy value in `orders`
7531 * will sort the corresponding property name in ascending order while a
7532 * falsey value will sort it in descending order.
7533 *
7534 * @static
7535 * @memberOf _
7536 * @category Collection
7537 * @param {Array|Object|string} collection The collection to iterate over.
7538 * @param {string[]} props The property names to sort by.
7539 * @param {boolean[]} orders The sort orders of `props`.
7540 * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
7541 * @returns {Array} Returns the new sorted array.
7542 * @example
7543 *
7544 * var users = [
7545 * { 'user': 'barney', 'age': 26 },
7546 * { 'user': 'fred', 'age': 40 },
7547 * { 'user': 'barney', 'age': 36 },
7548 * { 'user': 'fred', 'age': 30 }
7549 * ];
7550 *
7551 * // sort by `user` in ascending order and by `age` in descending order
7552 * _.map(_.sortByOrder(users, ['user', 'age'], [true, false]), _.values);
7553 * // => [['barney', 36], ['barney', 26], ['fred', 40], ['fred', 30]]
7554 */
7555 function sortByOrder(collection, props, orders, guard) {
7556 if (collection == null) {
7557 return [];
7558 }
7559 if (guard && isIterateeCall(props, orders, guard)) {
7560 orders = null;
7561 }
7562 if (!isArray(props)) {
7563 props = props == null ? [] : [props];
7564 }
7565 if (!isArray(orders)) {
7566 orders = orders == null ? [] : [orders];
7567 }
7568 return baseSortByOrder(collection, props, orders);
7569 }
7570
7571 /**
7572 * Performs a deep comparison between each element in `collection` and the
7573 * source object, returning an array of all elements that have equivalent
7574 * property values.
7575 *
7576 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
7577 * numbers, `Object` objects, regexes, and strings. Objects are compared by
7578 * their own, not inherited, enumerable properties. For comparing a single
7579 * own or inherited property value see `_.matchesProperty`.
7580 *
7581 * @static
7582 * @memberOf _
7583 * @category Collection
7584 * @param {Array|Object|string} collection The collection to search.
7585 * @param {Object} source The object of property values to match.
7586 * @returns {Array} Returns the new filtered array.
7587 * @example
7588 *
7589 * var users = [
7590 * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
7591 * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
7592 * ];
7593 *
7594 * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
7595 * // => ['barney']
7596 *
7597 * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
7598 * // => ['fred']
7599 */
7600 function where(collection, source) {
7601 return filter(collection, baseMatches(source));
7602 }
7603
7604 /*------------------------------------------------------------------------*/
7605
7606 /**
7607 * Gets the number of milliseconds that have elapsed since the Unix epoch
7608 * (1 January 1970 00:00:00 UTC).
7609 *
7610 * @static
7611 * @memberOf _
7612 * @category Date
7613 * @example
7614 *
7615 * _.defer(function(stamp) {
7616 * console.log(_.now() - stamp);
7617 * }, _.now());
7618 * // => logs the number of milliseconds it took for the deferred function to be invoked
7619 */
7620 var now = nativeNow || function() {
7621 return new Date().getTime();
7622 };
7623
7624 /*------------------------------------------------------------------------*/
7625
7626 /**
7627 * The opposite of `_.before`; this method creates a function that invokes
7628 * `func` once it is called `n` or more times.
7629 *
7630 * @static
7631 * @memberOf _
7632 * @category Function
7633 * @param {number} n The number of calls before `func` is invoked.
7634 * @param {Function} func The function to restrict.
7635 * @returns {Function} Returns the new restricted function.
7636 * @example
7637 *
7638 * var saves = ['profile', 'settings'];
7639 *
7640 * var done = _.after(saves.length, function() {
7641 * console.log('done saving!');
7642 * });
7643 *
7644 * _.forEach(saves, function(type) {
7645 * asyncSave({ 'type': type, 'complete': done });
7646 * });
7647 * // => logs 'done saving!' after the two async saves have completed
7648 */
7649 function after(n, func) {
7650 if (typeof func != 'function') {
7651 if (typeof n == 'function') {
7652 var temp = n;
7653 n = func;
7654 func = temp;
7655 } else {
7656 throw new TypeError(FUNC_ERROR_TEXT);
7657 }
7658 }
7659 n = nativeIsFinite(n = +n) ? n : 0;
7660 return function() {
7661 if (--n < 1) {
7662 return func.apply(this, arguments);
7663 }
7664 };
7665 }
7666
7667 /**
7668 * Creates a function that accepts up to `n` arguments ignoring any
7669 * additional arguments.
7670 *
7671 * @static
7672 * @memberOf _
7673 * @category Function
7674 * @param {Function} func The function to cap arguments for.
7675 * @param {number} [n=func.length] The arity cap.
7676 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7677 * @returns {Function} Returns the new function.
7678 * @example
7679 *
7680 * _.map(['6', '8', '10'], _.ary(parseInt, 1));
7681 * // => [6, 8, 10]
7682 */
7683 function ary(func, n, guard) {
7684 if (guard && isIterateeCall(func, n, guard)) {
7685 n = null;
7686 }
7687 n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
7688 return createWrapper(func, ARY_FLAG, null, null, null, null, n);
7689 }
7690
7691 /**
7692 * Creates a function that invokes `func`, with the `this` binding and arguments
7693 * of the created function, while it is called less than `n` times. Subsequent
7694 * calls to the created function return the result of the last `func` invocation.
7695 *
7696 * @static
7697 * @memberOf _
7698 * @category Function
7699 * @param {number} n The number of calls at which `func` is no longer invoked.
7700 * @param {Function} func The function to restrict.
7701 * @returns {Function} Returns the new restricted function.
7702 * @example
7703 *
7704 * jQuery('#add').on('click', _.before(5, addContactToList));
7705 * // => allows adding up to 4 contacts to the list
7706 */
7707 function before(n, func) {
7708 var result;
7709 if (typeof func != 'function') {
7710 if (typeof n == 'function') {
7711 var temp = n;
7712 n = func;
7713 func = temp;
7714 } else {
7715 throw new TypeError(FUNC_ERROR_TEXT);
7716 }
7717 }
7718 return function() {
7719 if (--n > 0) {
7720 result = func.apply(this, arguments);
7721 } else {
7722 func = null;
7723 }
7724 return result;
7725 };
7726 }
7727
7728 /**
7729 * Creates a function that invokes `func` with the `this` binding of `thisArg`
7730 * and prepends any additional `_.bind` arguments to those provided to the
7731 * bound function.
7732 *
7733 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
7734 * may be used as a placeholder for partially applied arguments.
7735 *
7736 * **Note:** Unlike native `Function#bind` this method does not set the `length`
7737 * property of bound functions.
7738 *
7739 * @static
7740 * @memberOf _
7741 * @category Function
7742 * @param {Function} func The function to bind.
7743 * @param {*} thisArg The `this` binding of `func`.
7744 * @param {...*} [partials] The arguments to be partially applied.
7745 * @returns {Function} Returns the new bound function.
7746 * @example
7747 *
7748 * var greet = function(greeting, punctuation) {
7749 * return greeting + ' ' + this.user + punctuation;
7750 * };
7751 *
7752 * var object = { 'user': 'fred' };
7753 *
7754 * var bound = _.bind(greet, object, 'hi');
7755 * bound('!');
7756 * // => 'hi fred!'
7757 *
7758 * // using placeholders
7759 * var bound = _.bind(greet, object, _, '!');
7760 * bound('hi');
7761 * // => 'hi fred!'
7762 */
7763 var bind = restParam(function(func, thisArg, partials) {
7764 var bitmask = BIND_FLAG;
7765 if (partials.length) {
7766 var holders = replaceHolders(partials, bind.placeholder);
7767 bitmask |= PARTIAL_FLAG;
7768 }
7769 return createWrapper(func, bitmask, thisArg, partials, holders);
7770 });
7771
7772 /**
7773 * Binds methods of an object to the object itself, overwriting the existing
7774 * method. Method names may be specified as individual arguments or as arrays
7775 * of method names. If no method names are provided all enumerable function
7776 * properties, own and inherited, of `object` are bound.
7777 *
7778 * **Note:** This method does not set the `length` property of bound functions.
7779 *
7780 * @static
7781 * @memberOf _
7782 * @category Function
7783 * @param {Object} object The object to bind and assign the bound methods to.
7784 * @param {...(string|string[])} [methodNames] The object method names to bind,
7785 * specified as individual method names or arrays of method names.
7786 * @returns {Object} Returns `object`.
7787 * @example
7788 *
7789 * var view = {
7790 * 'label': 'docs',
7791 * 'onClick': function() {
7792 * console.log('clicked ' + this.label);
7793 * }
7794 * };
7795 *
7796 * _.bindAll(view);
7797 * jQuery('#docs').on('click', view.onClick);
7798 * // => logs 'clicked docs' when the element is clicked
7799 */
7800 var bindAll = restParam(function(object, methodNames) {
7801 methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
7802
7803 var index = -1,
7804 length = methodNames.length;
7805
7806 while (++index < length) {
7807 var key = methodNames[index];
7808 object[key] = createWrapper(object[key], BIND_FLAG, object);
7809 }
7810 return object;
7811 });
7812
7813 /**
7814 * Creates a function that invokes the method at `object[key]` and prepends
7815 * any additional `_.bindKey` arguments to those provided to the bound function.
7816 *
7817 * This method differs from `_.bind` by allowing bound functions to reference
7818 * methods that may be redefined or don't yet exist.
7819 * See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern)
7820 * for more details.
7821 *
7822 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
7823 * builds, may be used as a placeholder for partially applied arguments.
7824 *
7825 * @static
7826 * @memberOf _
7827 * @category Function
7828 * @param {Object} object The object the method belongs to.
7829 * @param {string} key The key of the method.
7830 * @param {...*} [partials] The arguments to be partially applied.
7831 * @returns {Function} Returns the new bound function.
7832 * @example
7833 *
7834 * var object = {
7835 * 'user': 'fred',
7836 * 'greet': function(greeting, punctuation) {
7837 * return greeting + ' ' + this.user + punctuation;
7838 * }
7839 * };
7840 *
7841 * var bound = _.bindKey(object, 'greet', 'hi');
7842 * bound('!');
7843 * // => 'hi fred!'
7844 *
7845 * object.greet = function(greeting, punctuation) {
7846 * return greeting + 'ya ' + this.user + punctuation;
7847 * };
7848 *
7849 * bound('!');
7850 * // => 'hiya fred!'
7851 *
7852 * // using placeholders
7853 * var bound = _.bindKey(object, 'greet', _, '!');
7854 * bound('hi');
7855 * // => 'hiya fred!'
7856 */
7857 var bindKey = restParam(function(object, key, partials) {
7858 var bitmask = BIND_FLAG | BIND_KEY_FLAG;
7859 if (partials.length) {
7860 var holders = replaceHolders(partials, bindKey.placeholder);
7861 bitmask |= PARTIAL_FLAG;
7862 }
7863 return createWrapper(key, bitmask, object, partials, holders);
7864 });
7865
7866 /**
7867 * Creates a function that accepts one or more arguments of `func` that when
7868 * called either invokes `func` returning its result, if all `func` arguments
7869 * have been provided, or returns a function that accepts one or more of the
7870 * remaining `func` arguments, and so on. The arity of `func` may be specified
7871 * if `func.length` is not sufficient.
7872 *
7873 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
7874 * may be used as a placeholder for provided arguments.
7875 *
7876 * **Note:** This method does not set the `length` property of curried functions.
7877 *
7878 * @static
7879 * @memberOf _
7880 * @category Function
7881 * @param {Function} func The function to curry.
7882 * @param {number} [arity=func.length] The arity of `func`.
7883 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7884 * @returns {Function} Returns the new curried function.
7885 * @example
7886 *
7887 * var abc = function(a, b, c) {
7888 * return [a, b, c];
7889 * };
7890 *
7891 * var curried = _.curry(abc);
7892 *
7893 * curried(1)(2)(3);
7894 * // => [1, 2, 3]
7895 *
7896 * curried(1, 2)(3);
7897 * // => [1, 2, 3]
7898 *
7899 * curried(1, 2, 3);
7900 * // => [1, 2, 3]
7901 *
7902 * // using placeholders
7903 * curried(1)(_, 3)(2);
7904 * // => [1, 2, 3]
7905 */
7906 var curry = createCurry(CURRY_FLAG);
7907
7908 /**
7909 * This method is like `_.curry` except that arguments are applied to `func`
7910 * in the manner of `_.partialRight` instead of `_.partial`.
7911 *
7912 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
7913 * builds, may be used as a placeholder for provided arguments.
7914 *
7915 * **Note:** This method does not set the `length` property of curried functions.
7916 *
7917 * @static
7918 * @memberOf _
7919 * @category Function
7920 * @param {Function} func The function to curry.
7921 * @param {number} [arity=func.length] The arity of `func`.
7922 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
7923 * @returns {Function} Returns the new curried function.
7924 * @example
7925 *
7926 * var abc = function(a, b, c) {
7927 * return [a, b, c];
7928 * };
7929 *
7930 * var curried = _.curryRight(abc);
7931 *
7932 * curried(3)(2)(1);
7933 * // => [1, 2, 3]
7934 *
7935 * curried(2, 3)(1);
7936 * // => [1, 2, 3]
7937 *
7938 * curried(1, 2, 3);
7939 * // => [1, 2, 3]
7940 *
7941 * // using placeholders
7942 * curried(3)(1, _)(2);
7943 * // => [1, 2, 3]
7944 */
7945 var curryRight = createCurry(CURRY_RIGHT_FLAG);
7946
7947 /**
7948 * Creates a function that delays invoking `func` until after `wait` milliseconds
7949 * have elapsed since the last time it was invoked. The created function comes
7950 * with a `cancel` method to cancel delayed invocations. Provide an options
7951 * object to indicate that `func` should be invoked on the leading and/or
7952 * trailing edge of the `wait` timeout. Subsequent calls to the debounced
7953 * function return the result of the last `func` invocation.
7954 *
7955 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
7956 * on the trailing edge of the timeout only if the the debounced function is
7957 * invoked more than once during the `wait` timeout.
7958 *
7959 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
7960 * for details over the differences between `_.debounce` and `_.throttle`.
7961 *
7962 * @static
7963 * @memberOf _
7964 * @category Function
7965 * @param {Function} func The function to debounce.
7966 * @param {number} [wait=0] The number of milliseconds to delay.
7967 * @param {Object} [options] The options object.
7968 * @param {boolean} [options.leading=false] Specify invoking on the leading
7969 * edge of the timeout.
7970 * @param {number} [options.maxWait] The maximum time `func` is allowed to be
7971 * delayed before it is invoked.
7972 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
7973 * edge of the timeout.
7974 * @returns {Function} Returns the new debounced function.
7975 * @example
7976 *
7977 * // avoid costly calculations while the window size is in flux
7978 * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
7979 *
7980 * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
7981 * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
7982 * 'leading': true,
7983 * 'trailing': false
7984 * }));
7985 *
7986 * // ensure `batchLog` is invoked once after 1 second of debounced calls
7987 * var source = new EventSource('/stream');
7988 * jQuery(source).on('message', _.debounce(batchLog, 250, {
7989 * 'maxWait': 1000
7990 * }));
7991 *
7992 * // cancel a debounced call
7993 * var todoChanges = _.debounce(batchLog, 1000);
7994 * Object.observe(models.todo, todoChanges);
7995 *
7996 * Object.observe(models, function(changes) {
7997 * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
7998 * todoChanges.cancel();
7999 * }
8000 * }, ['delete']);
8001 *
8002 * // ...at some point `models.todo` is changed
8003 * models.todo.completed = true;
8004 *
8005 * // ...before 1 second has passed `models.todo` is deleted
8006 * // which cancels the debounced `todoChanges` call
8007 * delete models.todo;
8008 */
8009 function debounce(func, wait, options) {
8010 var args,
8011 maxTimeoutId,
8012 result,
8013 stamp,
8014 thisArg,
8015 timeoutId,
8016 trailingCall,
8017 lastCalled = 0,
8018 maxWait = false,
8019 trailing = true;
8020
8021 if (typeof func != 'function') {
8022 throw new TypeError(FUNC_ERROR_TEXT);
8023 }
8024 wait = wait < 0 ? 0 : (+wait || 0);
8025 if (options === true) {
8026 var leading = true;
8027 trailing = false;
8028 } else if (isObject(options)) {
8029 leading = options.leading;
8030 maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
8031 trailing = 'trailing' in options ? options.trailing : trailing;
8032 }
8033
8034 function cancel() {
8035 if (timeoutId) {
8036 clearTimeout(timeoutId);
8037 }
8038 if (maxTimeoutId) {
8039 clearTimeout(maxTimeoutId);
8040 }
8041 maxTimeoutId = timeoutId = trailingCall = undefined;
8042 }
8043
8044 function delayed() {
8045 var remaining = wait - (now() - stamp);
8046 if (remaining <= 0 || remaining > wait) {
8047 if (maxTimeoutId) {
8048 clearTimeout(maxTimeoutId);
8049 }
8050 var isCalled = trailingCall;
8051 maxTimeoutId = timeoutId = trailingCall = undefined;
8052 if (isCalled) {
8053 lastCalled = now();
8054 result = func.apply(thisArg, args);
8055 if (!timeoutId && !maxTimeoutId) {
8056 args = thisArg = null;
8057 }
8058 }
8059 } else {
8060 timeoutId = setTimeout(delayed, remaining);
8061 }
8062 }
8063
8064 function maxDelayed() {
8065 if (timeoutId) {
8066 clearTimeout(timeoutId);
8067 }
8068 maxTimeoutId = timeoutId = trailingCall = undefined;
8069 if (trailing || (maxWait !== wait)) {
8070 lastCalled = now();
8071 result = func.apply(thisArg, args);
8072 if (!timeoutId && !maxTimeoutId) {
8073 args = thisArg = null;
8074 }
8075 }
8076 }
8077
8078 function debounced() {
8079 args = arguments;
8080 stamp = now();
8081 thisArg = this;
8082 trailingCall = trailing && (timeoutId || !leading);
8083
8084 if (maxWait === false) {
8085 var leadingCall = leading && !timeoutId;
8086 } else {
8087 if (!maxTimeoutId && !leading) {
8088 lastCalled = stamp;
8089 }
8090 var remaining = maxWait - (stamp - lastCalled),
8091 isCalled = remaining <= 0 || remaining > maxWait;
8092
8093 if (isCalled) {
8094 if (maxTimeoutId) {
8095 maxTimeoutId = clearTimeout(maxTimeoutId);
8096 }
8097 lastCalled = stamp;
8098 result = func.apply(thisArg, args);
8099 }
8100 else if (!maxTimeoutId) {
8101 maxTimeoutId = setTimeout(maxDelayed, remaining);
8102 }
8103 }
8104 if (isCalled && timeoutId) {
8105 timeoutId = clearTimeout(timeoutId);
8106 }
8107 else if (!timeoutId && wait !== maxWait) {
8108 timeoutId = setTimeout(delayed, wait);
8109 }
8110 if (leadingCall) {
8111 isCalled = true;
8112 result = func.apply(thisArg, args);
8113 }
8114 if (isCalled && !timeoutId && !maxTimeoutId) {
8115 args = thisArg = null;
8116 }
8117 return result;
8118 }
8119 debounced.cancel = cancel;
8120 return debounced;
8121 }
8122
8123 /**
8124 * Defers invoking the `func` until the current call stack has cleared. Any
8125 * additional arguments are provided to `func` when it is invoked.
8126 *
8127 * @static
8128 * @memberOf _
8129 * @category Function
8130 * @param {Function} func The function to defer.
8131 * @param {...*} [args] The arguments to invoke the function with.
8132 * @returns {number} Returns the timer id.
8133 * @example
8134 *
8135 * _.defer(function(text) {
8136 * console.log(text);
8137 * }, 'deferred');
8138 * // logs 'deferred' after one or more milliseconds
8139 */
8140 var defer = restParam(function(func, args) {
8141 return baseDelay(func, 1, args);
8142 });
8143
8144 /**
8145 * Invokes `func` after `wait` milliseconds. Any additional arguments are
8146 * provided to `func` when it is invoked.
8147 *
8148 * @static
8149 * @memberOf _
8150 * @category Function
8151 * @param {Function} func The function to delay.
8152 * @param {number} wait The number of milliseconds to delay invocation.
8153 * @param {...*} [args] The arguments to invoke the function with.
8154 * @returns {number} Returns the timer id.
8155 * @example
8156 *
8157 * _.delay(function(text) {
8158 * console.log(text);
8159 * }, 1000, 'later');
8160 * // => logs 'later' after one second
8161 */
8162 var delay = restParam(function(func, wait, args) {
8163 return baseDelay(func, wait, args);
8164 });
8165
8166 /**
8167 * Creates a function that returns the result of invoking the provided
8168 * functions with the `this` binding of the created function, where each
8169 * successive invocation is supplied the return value of the previous.
8170 *
8171 * @static
8172 * @memberOf _
8173 * @category Function
8174 * @param {...Function} [funcs] Functions to invoke.
8175 * @returns {Function} Returns the new function.
8176 * @example
8177 *
8178 * function square(n) {
8179 * return n * n;
8180 * }
8181 *
8182 * var addSquare = _.flow(_.add, square);
8183 * addSquare(1, 2);
8184 * // => 9
8185 */
8186 var flow = createFlow();
8187
8188 /**
8189 * This method is like `_.flow` except that it creates a function that
8190 * invokes the provided functions from right to left.
8191 *
8192 * @static
8193 * @memberOf _
8194 * @alias backflow, compose
8195 * @category Function
8196 * @param {...Function} [funcs] Functions to invoke.
8197 * @returns {Function} Returns the new function.
8198 * @example
8199 *
8200 * function square(n) {
8201 * return n * n;
8202 * }
8203 *
8204 * var addSquare = _.flowRight(square, _.add);
8205 * addSquare(1, 2);
8206 * // => 9
8207 */
8208 var flowRight = createFlow(true);
8209
8210 /**
8211 * Creates a function that memoizes the result of `func`. If `resolver` is
8212 * provided it determines the cache key for storing the result based on the
8213 * arguments provided to the memoized function. By default, the first argument
8214 * provided to the memoized function is coerced to a string and used as the
8215 * cache key. The `func` is invoked with the `this` binding of the memoized
8216 * function.
8217 *
8218 * **Note:** The cache is exposed as the `cache` property on the memoized
8219 * function. Its creation may be customized by replacing the `_.memoize.Cache`
8220 * constructor with one whose instances implement the [`Map`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
8221 * method interface of `get`, `has`, and `set`.
8222 *
8223 * @static
8224 * @memberOf _
8225 * @category Function
8226 * @param {Function} func The function to have its output memoized.
8227 * @param {Function} [resolver] The function to resolve the cache key.
8228 * @returns {Function} Returns the new memoizing function.
8229 * @example
8230 *
8231 * var upperCase = _.memoize(function(string) {
8232 * return string.toUpperCase();
8233 * });
8234 *
8235 * upperCase('fred');
8236 * // => 'FRED'
8237 *
8238 * // modifying the result cache
8239 * upperCase.cache.set('fred', 'BARNEY');
8240 * upperCase('fred');
8241 * // => 'BARNEY'
8242 *
8243 * // replacing `_.memoize.Cache`
8244 * var object = { 'user': 'fred' };
8245 * var other = { 'user': 'barney' };
8246 * var identity = _.memoize(_.identity);
8247 *
8248 * identity(object);
8249 * // => { 'user': 'fred' }
8250 * identity(other);
8251 * // => { 'user': 'fred' }
8252 *
8253 * _.memoize.Cache = WeakMap;
8254 * var identity = _.memoize(_.identity);
8255 *
8256 * identity(object);
8257 * // => { 'user': 'fred' }
8258 * identity(other);
8259 * // => { 'user': 'barney' }
8260 */
8261 function memoize(func, resolver) {
8262 if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
8263 throw new TypeError(FUNC_ERROR_TEXT);
8264 }
8265 var memoized = function() {
8266 var args = arguments,
8267 cache = memoized.cache,
8268 key = resolver ? resolver.apply(this, args) : args[0];
8269
8270 if (cache.has(key)) {
8271 return cache.get(key);
8272 }
8273 var result = func.apply(this, args);
8274 cache.set(key, result);
8275 return result;
8276 };
8277 memoized.cache = new memoize.Cache;
8278 return memoized;
8279 }
8280
8281 /**
8282 * Creates a function that negates the result of the predicate `func`. The
8283 * `func` predicate is invoked with the `this` binding and arguments of the
8284 * created function.
8285 *
8286 * @static
8287 * @memberOf _
8288 * @category Function
8289 * @param {Function} predicate The predicate to negate.
8290 * @returns {Function} Returns the new function.
8291 * @example
8292 *
8293 * function isEven(n) {
8294 * return n % 2 == 0;
8295 * }
8296 *
8297 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
8298 * // => [1, 3, 5]
8299 */
8300 function negate(predicate) {
8301 if (typeof predicate != 'function') {
8302 throw new TypeError(FUNC_ERROR_TEXT);
8303 }
8304 return function() {
8305 return !predicate.apply(this, arguments);
8306 };
8307 }
8308
8309 /**
8310 * Creates a function that is restricted to invoking `func` once. Repeat calls
8311 * to the function return the value of the first call. The `func` is invoked
8312 * with the `this` binding and arguments of the created function.
8313 *
8314 * @static
8315 * @memberOf _
8316 * @category Function
8317 * @param {Function} func The function to restrict.
8318 * @returns {Function} Returns the new restricted function.
8319 * @example
8320 *
8321 * var initialize = _.once(createApplication);
8322 * initialize();
8323 * initialize();
8324 * // `initialize` invokes `createApplication` once
8325 */
8326 function once(func) {
8327 return before(func, 2);
8328 }
8329
8330 /**
8331 * Creates a function that invokes `func` with `partial` arguments prepended
8332 * to those provided to the new function. This method is like `_.bind` except
8333 * it does **not** alter the `this` binding.
8334 *
8335 * The `_.partial.placeholder` value, which defaults to `_` in monolithic
8336 * builds, may be used as a placeholder for partially applied arguments.
8337 *
8338 * **Note:** This method does not set the `length` property of partially
8339 * applied functions.
8340 *
8341 * @static
8342 * @memberOf _
8343 * @category Function
8344 * @param {Function} func The function to partially apply arguments to.
8345 * @param {...*} [partials] The arguments to be partially applied.
8346 * @returns {Function} Returns the new partially applied function.
8347 * @example
8348 *
8349 * var greet = function(greeting, name) {
8350 * return greeting + ' ' + name;
8351 * };
8352 *
8353 * var sayHelloTo = _.partial(greet, 'hello');
8354 * sayHelloTo('fred');
8355 * // => 'hello fred'
8356 *
8357 * // using placeholders
8358 * var greetFred = _.partial(greet, _, 'fred');
8359 * greetFred('hi');
8360 * // => 'hi fred'
8361 */
8362 var partial = createPartial(PARTIAL_FLAG);
8363
8364 /**
8365 * This method is like `_.partial` except that partially applied arguments
8366 * are appended to those provided to the new function.
8367 *
8368 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
8369 * builds, may be used as a placeholder for partially applied arguments.
8370 *
8371 * **Note:** This method does not set the `length` property of partially
8372 * applied functions.
8373 *
8374 * @static
8375 * @memberOf _
8376 * @category Function
8377 * @param {Function} func The function to partially apply arguments to.
8378 * @param {...*} [partials] The arguments to be partially applied.
8379 * @returns {Function} Returns the new partially applied function.
8380 * @example
8381 *
8382 * var greet = function(greeting, name) {
8383 * return greeting + ' ' + name;
8384 * };
8385 *
8386 * var greetFred = _.partialRight(greet, 'fred');
8387 * greetFred('hi');
8388 * // => 'hi fred'
8389 *
8390 * // using placeholders
8391 * var sayHelloTo = _.partialRight(greet, 'hello', _);
8392 * sayHelloTo('fred');
8393 * // => 'hello fred'
8394 */
8395 var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
8396
8397 /**
8398 * Creates a function that invokes `func` with arguments arranged according
8399 * to the specified indexes where the argument value at the first index is
8400 * provided as the first argument, the argument value at the second index is
8401 * provided as the second argument, and so on.
8402 *
8403 * @static
8404 * @memberOf _
8405 * @category Function
8406 * @param {Function} func The function to rearrange arguments for.
8407 * @param {...(number|number[])} indexes The arranged argument indexes,
8408 * specified as individual indexes or arrays of indexes.
8409 * @returns {Function} Returns the new function.
8410 * @example
8411 *
8412 * var rearged = _.rearg(function(a, b, c) {
8413 * return [a, b, c];
8414 * }, 2, 0, 1);
8415 *
8416 * rearged('b', 'c', 'a')
8417 * // => ['a', 'b', 'c']
8418 *
8419 * var map = _.rearg(_.map, [1, 0]);
8420 * map(function(n) {
8421 * return n * 3;
8422 * }, [1, 2, 3]);
8423 * // => [3, 6, 9]
8424 */
8425 var rearg = restParam(function(func, indexes) {
8426 return createWrapper(func, REARG_FLAG, null, null, null, baseFlatten(indexes));
8427 });
8428
8429 /**
8430 * Creates a function that invokes `func` with the `this` binding of the
8431 * created function and arguments from `start` and beyond provided as an array.
8432 *
8433 * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
8434 *
8435 * @static
8436 * @memberOf _
8437 * @category Function
8438 * @param {Function} func The function to apply a rest parameter to.
8439 * @param {number} [start=func.length-1] The start position of the rest parameter.
8440 * @returns {Function} Returns the new function.
8441 * @example
8442 *
8443 * var say = _.restParam(function(what, names) {
8444 * return what + ' ' + _.initial(names).join(', ') +
8445 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
8446 * });
8447 *
8448 * say('hello', 'fred', 'barney', 'pebbles');
8449 * // => 'hello fred, barney, & pebbles'
8450 */
8451 function restParam(func, start) {
8452 if (typeof func != 'function') {
8453 throw new TypeError(FUNC_ERROR_TEXT);
8454 }
8455 start = nativeMax(typeof start == 'undefined' ? (func.length - 1) : (+start || 0), 0);
8456 return function() {
8457 var args = arguments,
8458 index = -1,
8459 length = nativeMax(args.length - start, 0),
8460 rest = Array(length);
8461
8462 while (++index < length) {
8463 rest[index] = args[start + index];
8464 }
8465 switch (start) {
8466 case 0: return func.call(this, rest);
8467 case 1: return func.call(this, args[0], rest);
8468 case 2: return func.call(this, args[0], args[1], rest);
8469 }
8470 var otherArgs = Array(start + 1);
8471 index = -1;
8472 while (++index < start) {
8473 otherArgs[index] = args[index];
8474 }
8475 otherArgs[start] = rest;
8476 return func.apply(this, otherArgs);
8477 };
8478 }
8479
8480 /**
8481 * Creates a function that invokes `func` with the `this` binding of the created
8482 * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
8483 *
8484 * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
8485 *
8486 * @static
8487 * @memberOf _
8488 * @category Function
8489 * @param {Function} func The function to spread arguments over.
8490 * @returns {Function} Returns the new function.
8491 * @example
8492 *
8493 * var say = _.spread(function(who, what) {
8494 * return who + ' says ' + what;
8495 * });
8496 *
8497 * say(['fred', 'hello']);
8498 * // => 'fred says hello'
8499 *
8500 * // with a Promise
8501 * var numbers = Promise.all([
8502 * Promise.resolve(40),
8503 * Promise.resolve(36)
8504 * ]);
8505 *
8506 * numbers.then(_.spread(function(x, y) {
8507 * return x + y;
8508 * }));
8509 * // => a Promise of 76
8510 */
8511 function spread(func) {
8512 if (typeof func != 'function') {
8513 throw new TypeError(FUNC_ERROR_TEXT);
8514 }
8515 return function(array) {
8516 return func.apply(this, array);
8517 };
8518 }
8519
8520 /**
8521 * Creates a function that only invokes `func` at most once per every `wait`
8522 * milliseconds. The created function comes with a `cancel` method to cancel
8523 * delayed invocations. Provide an options object to indicate that `func`
8524 * should be invoked on the leading and/or trailing edge of the `wait` timeout.
8525 * Subsequent calls to the throttled function return the result of the last
8526 * `func` call.
8527 *
8528 * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
8529 * on the trailing edge of the timeout only if the the throttled function is
8530 * invoked more than once during the `wait` timeout.
8531 *
8532 * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
8533 * for details over the differences between `_.throttle` and `_.debounce`.
8534 *
8535 * @static
8536 * @memberOf _
8537 * @category Function
8538 * @param {Function} func The function to throttle.
8539 * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
8540 * @param {Object} [options] The options object.
8541 * @param {boolean} [options.leading=true] Specify invoking on the leading
8542 * edge of the timeout.
8543 * @param {boolean} [options.trailing=true] Specify invoking on the trailing
8544 * edge of the timeout.
8545 * @returns {Function} Returns the new throttled function.
8546 * @example
8547 *
8548 * // avoid excessively updating the position while scrolling
8549 * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
8550 *
8551 * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
8552 * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
8553 * 'trailing': false
8554 * }));
8555 *
8556 * // cancel a trailing throttled call
8557 * jQuery(window).on('popstate', throttled.cancel);
8558 */
8559 function throttle(func, wait, options) {
8560 var leading = true,
8561 trailing = true;
8562
8563 if (typeof func != 'function') {
8564 throw new TypeError(FUNC_ERROR_TEXT);
8565 }
8566 if (options === false) {
8567 leading = false;
8568 } else if (isObject(options)) {
8569 leading = 'leading' in options ? !!options.leading : leading;
8570 trailing = 'trailing' in options ? !!options.trailing : trailing;
8571 }
8572 debounceOptions.leading = leading;
8573 debounceOptions.maxWait = +wait;
8574 debounceOptions.trailing = trailing;
8575 return debounce(func, wait, debounceOptions);
8576 }
8577
8578 /**
8579 * Creates a function that provides `value` to the wrapper function as its
8580 * first argument. Any additional arguments provided to the function are
8581 * appended to those provided to the wrapper function. The wrapper is invoked
8582 * with the `this` binding of the created function.
8583 *
8584 * @static
8585 * @memberOf _
8586 * @category Function
8587 * @param {*} value The value to wrap.
8588 * @param {Function} wrapper The wrapper function.
8589 * @returns {Function} Returns the new function.
8590 * @example
8591 *
8592 * var p = _.wrap(_.escape, function(func, text) {
8593 * return '<p>' + func(text) + '</p>';
8594 * });
8595 *
8596 * p('fred, barney, & pebbles');
8597 * // => '<p>fred, barney, &amp; pebbles</p>'
8598 */
8599 function wrap(value, wrapper) {
8600 wrapper = wrapper == null ? identity : wrapper;
8601 return createWrapper(wrapper, PARTIAL_FLAG, null, [value], []);
8602 }
8603
8604 /*------------------------------------------------------------------------*/
8605
8606 /**
8607 * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
8608 * otherwise they are assigned by reference. If `customizer` is provided it is
8609 * invoked to produce the cloned values. If `customizer` returns `undefined`
8610 * cloning is handled by the method instead. The `customizer` is bound to
8611 * `thisArg` and invoked with two argument; (value [, index|key, object]).
8612 *
8613 * **Note:** This method is loosely based on the
8614 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
8615 * The enumerable properties of `arguments` objects and objects created by
8616 * constructors other than `Object` are cloned to plain `Object` objects. An
8617 * empty object is returned for uncloneable values such as functions, DOM nodes,
8618 * Maps, Sets, and WeakMaps.
8619 *
8620 * @static
8621 * @memberOf _
8622 * @category Lang
8623 * @param {*} value The value to clone.
8624 * @param {boolean} [isDeep] Specify a deep clone.
8625 * @param {Function} [customizer] The function to customize cloning values.
8626 * @param {*} [thisArg] The `this` binding of `customizer`.
8627 * @returns {*} Returns the cloned value.
8628 * @example
8629 *
8630 * var users = [
8631 * { 'user': 'barney' },
8632 * { 'user': 'fred' }
8633 * ];
8634 *
8635 * var shallow = _.clone(users);
8636 * shallow[0] === users[0];
8637 * // => true
8638 *
8639 * var deep = _.clone(users, true);
8640 * deep[0] === users[0];
8641 * // => false
8642 *
8643 * // using a customizer callback
8644 * var el = _.clone(document.body, function(value) {
8645 * if (_.isElement(value)) {
8646 * return value.cloneNode(false);
8647 * }
8648 * });
8649 *
8650 * el === document.body
8651 * // => false
8652 * el.nodeName
8653 * // => BODY
8654 * el.childNodes.length;
8655 * // => 0
8656 */
8657 function clone(value, isDeep, customizer, thisArg) {
8658 if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
8659 isDeep = false;
8660 }
8661 else if (typeof isDeep == 'function') {
8662 thisArg = customizer;
8663 customizer = isDeep;
8664 isDeep = false;
8665 }
8666 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
8667 return baseClone(value, isDeep, customizer);
8668 }
8669
8670 /**
8671 * Creates a deep clone of `value`. If `customizer` is provided it is invoked
8672 * to produce the cloned values. If `customizer` returns `undefined` cloning
8673 * is handled by the method instead. The `customizer` is bound to `thisArg`
8674 * and invoked with two argument; (value [, index|key, object]).
8675 *
8676 * **Note:** This method is loosely based on the
8677 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
8678 * The enumerable properties of `arguments` objects and objects created by
8679 * constructors other than `Object` are cloned to plain `Object` objects. An
8680 * empty object is returned for uncloneable values such as functions, DOM nodes,
8681 * Maps, Sets, and WeakMaps.
8682 *
8683 * @static
8684 * @memberOf _
8685 * @category Lang
8686 * @param {*} value The value to deep clone.
8687 * @param {Function} [customizer] The function to customize cloning values.
8688 * @param {*} [thisArg] The `this` binding of `customizer`.
8689 * @returns {*} Returns the deep cloned value.
8690 * @example
8691 *
8692 * var users = [
8693 * { 'user': 'barney' },
8694 * { 'user': 'fred' }
8695 * ];
8696 *
8697 * var deep = _.cloneDeep(users);
8698 * deep[0] === users[0];
8699 * // => false
8700 *
8701 * // using a customizer callback
8702 * var el = _.cloneDeep(document.body, function(value) {
8703 * if (_.isElement(value)) {
8704 * return value.cloneNode(true);
8705 * }
8706 * });
8707 *
8708 * el === document.body
8709 * // => false
8710 * el.nodeName
8711 * // => BODY
8712 * el.childNodes.length;
8713 * // => 20
8714 */
8715 function cloneDeep(value, customizer, thisArg) {
8716 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
8717 return baseClone(value, true, customizer);
8718 }
8719
8720 /**
8721 * Checks if `value` is classified as an `arguments` object.
8722 *
8723 * @static
8724 * @memberOf _
8725 * @category Lang
8726 * @param {*} value The value to check.
8727 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8728 * @example
8729 *
8730 * _.isArguments(function() { return arguments; }());
8731 * // => true
8732 *
8733 * _.isArguments([1, 2, 3]);
8734 * // => false
8735 */
8736 function isArguments(value) {
8737 var length = isObjectLike(value) ? value.length : undefined;
8738 return isLength(length) && objToString.call(value) == argsTag;
8739 }
8740
8741 /**
8742 * Checks if `value` is classified as an `Array` object.
8743 *
8744 * @static
8745 * @memberOf _
8746 * @category Lang
8747 * @param {*} value The value to check.
8748 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8749 * @example
8750 *
8751 * _.isArray([1, 2, 3]);
8752 * // => true
8753 *
8754 * _.isArray(function() { return arguments; }());
8755 * // => false
8756 */
8757 var isArray = nativeIsArray || function(value) {
8758 return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
8759 };
8760
8761 /**
8762 * Checks if `value` is classified as a boolean primitive or object.
8763 *
8764 * @static
8765 * @memberOf _
8766 * @category Lang
8767 * @param {*} value The value to check.
8768 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8769 * @example
8770 *
8771 * _.isBoolean(false);
8772 * // => true
8773 *
8774 * _.isBoolean(null);
8775 * // => false
8776 */
8777 function isBoolean(value) {
8778 return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
8779 }
8780
8781 /**
8782 * Checks if `value` is classified as a `Date` object.
8783 *
8784 * @static
8785 * @memberOf _
8786 * @category Lang
8787 * @param {*} value The value to check.
8788 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8789 * @example
8790 *
8791 * _.isDate(new Date);
8792 * // => true
8793 *
8794 * _.isDate('Mon April 23 2012');
8795 * // => false
8796 */
8797 function isDate(value) {
8798 return isObjectLike(value) && objToString.call(value) == dateTag;
8799 }
8800
8801 /**
8802 * Checks if `value` is a DOM element.
8803 *
8804 * @static
8805 * @memberOf _
8806 * @category Lang
8807 * @param {*} value The value to check.
8808 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
8809 * @example
8810 *
8811 * _.isElement(document.body);
8812 * // => true
8813 *
8814 * _.isElement('<body>');
8815 * // => false
8816 */
8817 function isElement(value) {
8818 return !!value && value.nodeType === 1 && isObjectLike(value) &&
8819 (objToString.call(value).indexOf('Element') > -1);
8820 }
8821 // Fallback for environments without DOM support.
8822 if (!support.dom) {
8823 isElement = function(value) {
8824 return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
8825 };
8826 }
8827
8828 /**
8829 * Checks if `value` is empty. A value is considered empty unless it is an
8830 * `arguments` object, array, string, or jQuery-like collection with a length
8831 * greater than `0` or an object with own enumerable properties.
8832 *
8833 * @static
8834 * @memberOf _
8835 * @category Lang
8836 * @param {Array|Object|string} value The value to inspect.
8837 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
8838 * @example
8839 *
8840 * _.isEmpty(null);
8841 * // => true
8842 *
8843 * _.isEmpty(true);
8844 * // => true
8845 *
8846 * _.isEmpty(1);
8847 * // => true
8848 *
8849 * _.isEmpty([1, 2, 3]);
8850 * // => false
8851 *
8852 * _.isEmpty({ 'a': 1 });
8853 * // => false
8854 */
8855 function isEmpty(value) {
8856 if (value == null) {
8857 return true;
8858 }
8859 var length = value.length;
8860 if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) ||
8861 (isObjectLike(value) && isFunction(value.splice)))) {
8862 return !length;
8863 }
8864 return !keys(value).length;
8865 }
8866
8867 /**
8868 * Performs a deep comparison between two values to determine if they are
8869 * equivalent. If `customizer` is provided it is invoked to compare values.
8870 * If `customizer` returns `undefined` comparisons are handled by the method
8871 * instead. The `customizer` is bound to `thisArg` and invoked with three
8872 * arguments: (value, other [, index|key]).
8873 *
8874 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
8875 * numbers, `Object` objects, regexes, and strings. Objects are compared by
8876 * their own, not inherited, enumerable properties. Functions and DOM nodes
8877 * are **not** supported. Provide a customizer function to extend support
8878 * for comparing other values.
8879 *
8880 * @static
8881 * @memberOf _
8882 * @category Lang
8883 * @param {*} value The value to compare.
8884 * @param {*} other The other value to compare.
8885 * @param {Function} [customizer] The function to customize comparing values.
8886 * @param {*} [thisArg] The `this` binding of `customizer`.
8887 * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
8888 * @example
8889 *
8890 * var object = { 'user': 'fred' };
8891 * var other = { 'user': 'fred' };
8892 *
8893 * object == other;
8894 * // => false
8895 *
8896 * _.isEqual(object, other);
8897 * // => true
8898 *
8899 * // using a customizer callback
8900 * var array = ['hello', 'goodbye'];
8901 * var other = ['hi', 'goodbye'];
8902 *
8903 * _.isEqual(array, other, function(value, other) {
8904 * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
8905 * return true;
8906 * }
8907 * });
8908 * // => true
8909 */
8910 function isEqual(value, other, customizer, thisArg) {
8911 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
8912 if (!customizer && isStrictComparable(value) && isStrictComparable(other)) {
8913 return value === other;
8914 }
8915 var result = customizer ? customizer(value, other) : undefined;
8916 return typeof result == 'undefined' ? baseIsEqual(value, other, customizer) : !!result;
8917 }
8918
8919 /**
8920 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
8921 * `SyntaxError`, `TypeError`, or `URIError` object.
8922 *
8923 * @static
8924 * @memberOf _
8925 * @category Lang
8926 * @param {*} value The value to check.
8927 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
8928 * @example
8929 *
8930 * _.isError(new Error);
8931 * // => true
8932 *
8933 * _.isError(Error);
8934 * // => false
8935 */
8936 function isError(value) {
8937 return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
8938 }
8939
8940 /**
8941 * Checks if `value` is a finite primitive number.
8942 *
8943 * **Note:** This method is based on [`Number.isFinite`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite).
8944 *
8945 * @static
8946 * @memberOf _
8947 * @category Lang
8948 * @param {*} value The value to check.
8949 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
8950 * @example
8951 *
8952 * _.isFinite(10);
8953 * // => true
8954 *
8955 * _.isFinite('10');
8956 * // => false
8957 *
8958 * _.isFinite(true);
8959 * // => false
8960 *
8961 * _.isFinite(Object(10));
8962 * // => false
8963 *
8964 * _.isFinite(Infinity);
8965 * // => false
8966 */
8967 var isFinite = nativeNumIsFinite || function(value) {
8968 return typeof value == 'number' && nativeIsFinite(value);
8969 };
8970
8971 /**
8972 * Checks if `value` is classified as a `Function` object.
8973 *
8974 * @static
8975 * @memberOf _
8976 * @category Lang
8977 * @param {*} value The value to check.
8978 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
8979 * @example
8980 *
8981 * _.isFunction(_);
8982 * // => true
8983 *
8984 * _.isFunction(/abc/);
8985 * // => false
8986 */
8987 var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
8988 // The use of `Object#toString` avoids issues with the `typeof` operator
8989 // in older versions of Chrome and Safari which return 'function' for regexes
8990 // and Safari 8 equivalents which return 'object' for typed array constructors.
8991 return objToString.call(value) == funcTag;
8992 };
8993
8994 /**
8995 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
8996 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
8997 *
8998 * @static
8999 * @memberOf _
9000 * @category Lang
9001 * @param {*} value The value to check.
9002 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
9003 * @example
9004 *
9005 * _.isObject({});
9006 * // => true
9007 *
9008 * _.isObject([1, 2, 3]);
9009 * // => true
9010 *
9011 * _.isObject(1);
9012 * // => false
9013 */
9014 function isObject(value) {
9015 // Avoid a V8 JIT bug in Chrome 19-20.
9016 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
9017 var type = typeof value;
9018 return type == 'function' || (!!value && type == 'object');
9019 }
9020
9021 /**
9022 * Performs a deep comparison between `object` and `source` to determine if
9023 * `object` contains equivalent property values. If `customizer` is provided
9024 * it is invoked to compare values. If `customizer` returns `undefined`
9025 * comparisons are handled by the method instead. The `customizer` is bound
9026 * to `thisArg` and invoked with three arguments: (value, other, index|key).
9027 *
9028 * **Note:** This method supports comparing properties of arrays, booleans,
9029 * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
9030 * and DOM nodes are **not** supported. Provide a customizer function to extend
9031 * support for comparing other values.
9032 *
9033 * @static
9034 * @memberOf _
9035 * @category Lang
9036 * @param {Object} object The object to inspect.
9037 * @param {Object} source The object of property values to match.
9038 * @param {Function} [customizer] The function to customize comparing values.
9039 * @param {*} [thisArg] The `this` binding of `customizer`.
9040 * @returns {boolean} Returns `true` if `object` is a match, else `false`.
9041 * @example
9042 *
9043 * var object = { 'user': 'fred', 'age': 40 };
9044 *
9045 * _.isMatch(object, { 'age': 40 });
9046 * // => true
9047 *
9048 * _.isMatch(object, { 'age': 36 });
9049 * // => false
9050 *
9051 * // using a customizer callback
9052 * var object = { 'greeting': 'hello' };
9053 * var source = { 'greeting': 'hi' };
9054 *
9055 * _.isMatch(object, source, function(value, other) {
9056 * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
9057 * });
9058 * // => true
9059 */
9060 function isMatch(object, source, customizer, thisArg) {
9061 var props = keys(source),
9062 length = props.length;
9063
9064 if (!length) {
9065 return true;
9066 }
9067 if (object == null) {
9068 return false;
9069 }
9070 customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
9071 if (!customizer && length == 1) {
9072 var key = props[0],
9073 value = source[key];
9074
9075 if (isStrictComparable(value)) {
9076 return value === object[key] && (typeof value != 'undefined' || (key in toObject(object)));
9077 }
9078 }
9079 var values = Array(length),
9080 strictCompareFlags = Array(length);
9081
9082 while (length--) {
9083 value = values[length] = source[props[length]];
9084 strictCompareFlags[length] = isStrictComparable(value);
9085 }
9086 return baseIsMatch(toObject(object), props, values, strictCompareFlags, customizer);
9087 }
9088
9089 /**
9090 * Checks if `value` is `NaN`.
9091 *
9092 * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
9093 * which returns `true` for `undefined` and other non-numeric values.
9094 *
9095 * @static
9096 * @memberOf _
9097 * @category Lang
9098 * @param {*} value The value to check.
9099 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
9100 * @example
9101 *
9102 * _.isNaN(NaN);
9103 * // => true
9104 *
9105 * _.isNaN(new Number(NaN));
9106 * // => true
9107 *
9108 * isNaN(undefined);
9109 * // => true
9110 *
9111 * _.isNaN(undefined);
9112 * // => false
9113 */
9114 function isNaN(value) {
9115 // An `NaN` primitive is the only value that is not equal to itself.
9116 // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
9117 return isNumber(value) && value != +value;
9118 }
9119
9120 /**
9121 * Checks if `value` is a native function.
9122 *
9123 * @static
9124 * @memberOf _
9125 * @category Lang
9126 * @param {*} value The value to check.
9127 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
9128 * @example
9129 *
9130 * _.isNative(Array.prototype.push);
9131 * // => true
9132 *
9133 * _.isNative(_);
9134 * // => false
9135 */
9136 function isNative(value) {
9137 if (value == null) {
9138 return false;
9139 }
9140 if (objToString.call(value) == funcTag) {
9141 return reNative.test(fnToString.call(value));
9142 }
9143 return isObjectLike(value) && reHostCtor.test(value);
9144 }
9145
9146 /**
9147 * Checks if `value` is `null`.
9148 *
9149 * @static
9150 * @memberOf _
9151 * @category Lang
9152 * @param {*} value The value to check.
9153 * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
9154 * @example
9155 *
9156 * _.isNull(null);
9157 * // => true
9158 *
9159 * _.isNull(void 0);
9160 * // => false
9161 */
9162 function isNull(value) {
9163 return value === null;
9164 }
9165
9166 /**
9167 * Checks if `value` is classified as a `Number` primitive or object.
9168 *
9169 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
9170 * as numbers, use the `_.isFinite` method.
9171 *
9172 * @static
9173 * @memberOf _
9174 * @category Lang
9175 * @param {*} value The value to check.
9176 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9177 * @example
9178 *
9179 * _.isNumber(8.4);
9180 * // => true
9181 *
9182 * _.isNumber(NaN);
9183 * // => true
9184 *
9185 * _.isNumber('8.4');
9186 * // => false
9187 */
9188 function isNumber(value) {
9189 return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
9190 }
9191
9192 /**
9193 * Checks if `value` is a plain object, that is, an object created by the
9194 * `Object` constructor or one with a `[[Prototype]]` of `null`.
9195 *
9196 * **Note:** This method assumes objects created by the `Object` constructor
9197 * have no inherited enumerable properties.
9198 *
9199 * @static
9200 * @memberOf _
9201 * @category Lang
9202 * @param {*} value The value to check.
9203 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
9204 * @example
9205 *
9206 * function Foo() {
9207 * this.a = 1;
9208 * }
9209 *
9210 * _.isPlainObject(new Foo);
9211 * // => false
9212 *
9213 * _.isPlainObject([1, 2, 3]);
9214 * // => false
9215 *
9216 * _.isPlainObject({ 'x': 0, 'y': 0 });
9217 * // => true
9218 *
9219 * _.isPlainObject(Object.create(null));
9220 * // => true
9221 */
9222 var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
9223 if (!(value && objToString.call(value) == objectTag)) {
9224 return false;
9225 }
9226 var valueOf = value.valueOf,
9227 objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
9228
9229 return objProto
9230 ? (value == objProto || getPrototypeOf(value) == objProto)
9231 : shimIsPlainObject(value);
9232 };
9233
9234 /**
9235 * Checks if `value` is classified as a `RegExp` object.
9236 *
9237 * @static
9238 * @memberOf _
9239 * @category Lang
9240 * @param {*} value The value to check.
9241 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9242 * @example
9243 *
9244 * _.isRegExp(/abc/);
9245 * // => true
9246 *
9247 * _.isRegExp('/abc/');
9248 * // => false
9249 */
9250 function isRegExp(value) {
9251 return (isObjectLike(value) && objToString.call(value) == regexpTag) || false;
9252 }
9253
9254 /**
9255 * Checks if `value` is classified as a `String` primitive or object.
9256 *
9257 * @static
9258 * @memberOf _
9259 * @category Lang
9260 * @param {*} value The value to check.
9261 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9262 * @example
9263 *
9264 * _.isString('abc');
9265 * // => true
9266 *
9267 * _.isString(1);
9268 * // => false
9269 */
9270 function isString(value) {
9271 return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
9272 }
9273
9274 /**
9275 * Checks if `value` is classified as a typed array.
9276 *
9277 * @static
9278 * @memberOf _
9279 * @category Lang
9280 * @param {*} value The value to check.
9281 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
9282 * @example
9283 *
9284 * _.isTypedArray(new Uint8Array);
9285 * // => true
9286 *
9287 * _.isTypedArray([]);
9288 * // => false
9289 */
9290 function isTypedArray(value) {
9291 return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
9292 }
9293
9294 /**
9295 * Checks if `value` is `undefined`.
9296 *
9297 * @static
9298 * @memberOf _
9299 * @category Lang
9300 * @param {*} value The value to check.
9301 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
9302 * @example
9303 *
9304 * _.isUndefined(void 0);
9305 * // => true
9306 *
9307 * _.isUndefined(null);
9308 * // => false
9309 */
9310 function isUndefined(value) {
9311 return typeof value == 'undefined';
9312 }
9313
9314 /**
9315 * Converts `value` to an array.
9316 *
9317 * @static
9318 * @memberOf _
9319 * @category Lang
9320 * @param {*} value The value to convert.
9321 * @returns {Array} Returns the converted array.
9322 * @example
9323 *
9324 * (function() {
9325 * return _.toArray(arguments).slice(1);
9326 * }(1, 2, 3));
9327 * // => [2, 3]
9328 */
9329 function toArray(value) {
9330 var length = value ? value.length : 0;
9331 if (!isLength(length)) {
9332 return values(value);
9333 }
9334 if (!length) {
9335 return [];
9336 }
9337 return arrayCopy(value);
9338 }
9339
9340 /**
9341 * Converts `value` to a plain object flattening inherited enumerable
9342 * properties of `value` to own properties of the plain object.
9343 *
9344 * @static
9345 * @memberOf _
9346 * @category Lang
9347 * @param {*} value The value to convert.
9348 * @returns {Object} Returns the converted plain object.
9349 * @example
9350 *
9351 * function Foo() {
9352 * this.b = 2;
9353 * }
9354 *
9355 * Foo.prototype.c = 3;
9356 *
9357 * _.assign({ 'a': 1 }, new Foo);
9358 * // => { 'a': 1, 'b': 2 }
9359 *
9360 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
9361 * // => { 'a': 1, 'b': 2, 'c': 3 }
9362 */
9363 function toPlainObject(value) {
9364 return baseCopy(value, keysIn(value));
9365 }
9366
9367 /*------------------------------------------------------------------------*/
9368
9369 /**
9370 * Assigns own enumerable properties of source object(s) to the destination
9371 * object. Subsequent sources overwrite property assignments of previous sources.
9372 * If `customizer` is provided it is invoked to produce the assigned values.
9373 * The `customizer` is bound to `thisArg` and invoked with five arguments:
9374 * (objectValue, sourceValue, key, object, source).
9375 *
9376 * @static
9377 * @memberOf _
9378 * @alias extend
9379 * @category Object
9380 * @param {Object} object The destination object.
9381 * @param {...Object} [sources] The source objects.
9382 * @param {Function} [customizer] The function to customize assigning values.
9383 * @param {*} [thisArg] The `this` binding of `customizer`.
9384 * @returns {Object} Returns `object`.
9385 * @example
9386 *
9387 * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
9388 * // => { 'user': 'fred', 'age': 40 }
9389 *
9390 * // using a customizer callback
9391 * var defaults = _.partialRight(_.assign, function(value, other) {
9392 * return typeof value == 'undefined' ? other : value;
9393 * });
9394 *
9395 * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
9396 * // => { 'user': 'barney', 'age': 36 }
9397 */
9398 var assign = createAssigner(baseAssign);
9399
9400 /**
9401 * Creates an object that inherits from the given `prototype` object. If a
9402 * `properties` object is provided its own enumerable properties are assigned
9403 * to the created object.
9404 *
9405 * @static
9406 * @memberOf _
9407 * @category Object
9408 * @param {Object} prototype The object to inherit from.
9409 * @param {Object} [properties] The properties to assign to the object.
9410 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9411 * @returns {Object} Returns the new object.
9412 * @example
9413 *
9414 * function Shape() {
9415 * this.x = 0;
9416 * this.y = 0;
9417 * }
9418 *
9419 * function Circle() {
9420 * Shape.call(this);
9421 * }
9422 *
9423 * Circle.prototype = _.create(Shape.prototype, {
9424 * 'constructor': Circle
9425 * });
9426 *
9427 * var circle = new Circle;
9428 * circle instanceof Circle;
9429 * // => true
9430 *
9431 * circle instanceof Shape;
9432 * // => true
9433 */
9434 function create(prototype, properties, guard) {
9435 var result = baseCreate(prototype);
9436 if (guard && isIterateeCall(prototype, properties, guard)) {
9437 properties = null;
9438 }
9439 return properties ? baseCopy(properties, result, keys(properties)) : result;
9440 }
9441
9442 /**
9443 * Assigns own enumerable properties of source object(s) to the destination
9444 * object for all destination properties that resolve to `undefined`. Once a
9445 * property is set, additional values of the same property are ignored.
9446 *
9447 * @static
9448 * @memberOf _
9449 * @category Object
9450 * @param {Object} object The destination object.
9451 * @param {...Object} [sources] The source objects.
9452 * @returns {Object} Returns `object`.
9453 * @example
9454 *
9455 * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
9456 * // => { 'user': 'barney', 'age': 36 }
9457 */
9458 var defaults = restParam(function(args) {
9459 var object = args[0];
9460 if (object == null) {
9461 return object;
9462 }
9463 args.push(assignDefaults);
9464 return assign.apply(undefined, args);
9465 });
9466
9467 /**
9468 * This method is like `_.find` except that it returns the key of the first
9469 * element `predicate` returns truthy for instead of the element itself.
9470 *
9471 * If a property name is provided for `predicate` the created `_.property`
9472 * style callback returns the property value of the given element.
9473 *
9474 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9475 * style callback returns `true` for elements that have a matching property
9476 * value, else `false`.
9477 *
9478 * If an object is provided for `predicate` the created `_.matches` style
9479 * callback returns `true` for elements that have the properties of the given
9480 * object, else `false`.
9481 *
9482 * @static
9483 * @memberOf _
9484 * @category Object
9485 * @param {Object} object The object to search.
9486 * @param {Function|Object|string} [predicate=_.identity] The function invoked
9487 * per iteration.
9488 * @param {*} [thisArg] The `this` binding of `predicate`.
9489 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
9490 * @example
9491 *
9492 * var users = {
9493 * 'barney': { 'age': 36, 'active': true },
9494 * 'fred': { 'age': 40, 'active': false },
9495 * 'pebbles': { 'age': 1, 'active': true }
9496 * };
9497 *
9498 * _.findKey(users, function(chr) {
9499 * return chr.age < 40;
9500 * });
9501 * // => 'barney' (iteration order is not guaranteed)
9502 *
9503 * // using the `_.matches` callback shorthand
9504 * _.findKey(users, { 'age': 1, 'active': true });
9505 * // => 'pebbles'
9506 *
9507 * // using the `_.matchesProperty` callback shorthand
9508 * _.findKey(users, 'active', false);
9509 * // => 'fred'
9510 *
9511 * // using the `_.property` callback shorthand
9512 * _.findKey(users, 'active');
9513 * // => 'barney'
9514 */
9515 var findKey = createFindKey(baseForOwn);
9516
9517 /**
9518 * This method is like `_.findKey` except that it iterates over elements of
9519 * a collection in the opposite order.
9520 *
9521 * If a property name is provided for `predicate` the created `_.property`
9522 * style callback returns the property value of the given element.
9523 *
9524 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9525 * style callback returns `true` for elements that have a matching property
9526 * value, else `false`.
9527 *
9528 * If an object is provided for `predicate` the created `_.matches` style
9529 * callback returns `true` for elements that have the properties of the given
9530 * object, else `false`.
9531 *
9532 * @static
9533 * @memberOf _
9534 * @category Object
9535 * @param {Object} object The object to search.
9536 * @param {Function|Object|string} [predicate=_.identity] The function invoked
9537 * per iteration.
9538 * @param {*} [thisArg] The `this` binding of `predicate`.
9539 * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
9540 * @example
9541 *
9542 * var users = {
9543 * 'barney': { 'age': 36, 'active': true },
9544 * 'fred': { 'age': 40, 'active': false },
9545 * 'pebbles': { 'age': 1, 'active': true }
9546 * };
9547 *
9548 * _.findLastKey(users, function(chr) {
9549 * return chr.age < 40;
9550 * });
9551 * // => returns `pebbles` assuming `_.findKey` returns `barney`
9552 *
9553 * // using the `_.matches` callback shorthand
9554 * _.findLastKey(users, { 'age': 36, 'active': true });
9555 * // => 'barney'
9556 *
9557 * // using the `_.matchesProperty` callback shorthand
9558 * _.findLastKey(users, 'active', false);
9559 * // => 'fred'
9560 *
9561 * // using the `_.property` callback shorthand
9562 * _.findLastKey(users, 'active');
9563 * // => 'pebbles'
9564 */
9565 var findLastKey = createFindKey(baseForOwnRight);
9566
9567 /**
9568 * Iterates over own and inherited enumerable properties of an object invoking
9569 * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
9570 * with three arguments: (value, key, object). Iterator functions may exit
9571 * iteration early by explicitly returning `false`.
9572 *
9573 * @static
9574 * @memberOf _
9575 * @category Object
9576 * @param {Object} object The object to iterate over.
9577 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9578 * @param {*} [thisArg] The `this` binding of `iteratee`.
9579 * @returns {Object} Returns `object`.
9580 * @example
9581 *
9582 * function Foo() {
9583 * this.a = 1;
9584 * this.b = 2;
9585 * }
9586 *
9587 * Foo.prototype.c = 3;
9588 *
9589 * _.forIn(new Foo, function(value, key) {
9590 * console.log(key);
9591 * });
9592 * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
9593 */
9594 var forIn = createForIn(baseFor);
9595
9596 /**
9597 * This method is like `_.forIn` except that it iterates over properties of
9598 * `object` in the opposite order.
9599 *
9600 * @static
9601 * @memberOf _
9602 * @category Object
9603 * @param {Object} object The object to iterate over.
9604 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9605 * @param {*} [thisArg] The `this` binding of `iteratee`.
9606 * @returns {Object} Returns `object`.
9607 * @example
9608 *
9609 * function Foo() {
9610 * this.a = 1;
9611 * this.b = 2;
9612 * }
9613 *
9614 * Foo.prototype.c = 3;
9615 *
9616 * _.forInRight(new Foo, function(value, key) {
9617 * console.log(key);
9618 * });
9619 * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
9620 */
9621 var forInRight = createForIn(baseForRight);
9622
9623 /**
9624 * Iterates over own enumerable properties of an object invoking `iteratee`
9625 * for each property. The `iteratee` is bound to `thisArg` and invoked with
9626 * three arguments: (value, key, object). Iterator functions may exit iteration
9627 * early by explicitly returning `false`.
9628 *
9629 * @static
9630 * @memberOf _
9631 * @category Object
9632 * @param {Object} object The object to iterate over.
9633 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9634 * @param {*} [thisArg] The `this` binding of `iteratee`.
9635 * @returns {Object} Returns `object`.
9636 * @example
9637 *
9638 * function Foo() {
9639 * this.a = 1;
9640 * this.b = 2;
9641 * }
9642 *
9643 * Foo.prototype.c = 3;
9644 *
9645 * _.forOwn(new Foo, function(value, key) {
9646 * console.log(key);
9647 * });
9648 * // => logs 'a' and 'b' (iteration order is not guaranteed)
9649 */
9650 var forOwn = createForOwn(baseForOwn);
9651
9652 /**
9653 * This method is like `_.forOwn` except that it iterates over properties of
9654 * `object` in the opposite order.
9655 *
9656 * @static
9657 * @memberOf _
9658 * @category Object
9659 * @param {Object} object The object to iterate over.
9660 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
9661 * @param {*} [thisArg] The `this` binding of `iteratee`.
9662 * @returns {Object} Returns `object`.
9663 * @example
9664 *
9665 * function Foo() {
9666 * this.a = 1;
9667 * this.b = 2;
9668 * }
9669 *
9670 * Foo.prototype.c = 3;
9671 *
9672 * _.forOwnRight(new Foo, function(value, key) {
9673 * console.log(key);
9674 * });
9675 * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
9676 */
9677 var forOwnRight = createForOwn(baseForOwnRight);
9678
9679 /**
9680 * Creates an array of function property names from all enumerable properties,
9681 * own and inherited, of `object`.
9682 *
9683 * @static
9684 * @memberOf _
9685 * @alias methods
9686 * @category Object
9687 * @param {Object} object The object to inspect.
9688 * @returns {Array} Returns the new array of property names.
9689 * @example
9690 *
9691 * _.functions(_);
9692 * // => ['after', 'ary', 'assign', ...]
9693 */
9694 function functions(object) {
9695 return baseFunctions(object, keysIn(object));
9696 }
9697
9698 /**
9699 * Checks if `key` exists as a direct property of `object` instead of an
9700 * inherited property.
9701 *
9702 * @static
9703 * @memberOf _
9704 * @category Object
9705 * @param {Object} object The object to inspect.
9706 * @param {string} key The key to check.
9707 * @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
9708 * @example
9709 *
9710 * var object = { 'a': 1, 'b': 2, 'c': 3 };
9711 *
9712 * _.has(object, 'b');
9713 * // => true
9714 */
9715 function has(object, key) {
9716 return object ? hasOwnProperty.call(object, key) : false;
9717 }
9718
9719 /**
9720 * Creates an object composed of the inverted keys and values of `object`.
9721 * If `object` contains duplicate values, subsequent values overwrite property
9722 * assignments of previous values unless `multiValue` is `true`.
9723 *
9724 * @static
9725 * @memberOf _
9726 * @category Object
9727 * @param {Object} object The object to invert.
9728 * @param {boolean} [multiValue] Allow multiple values per key.
9729 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
9730 * @returns {Object} Returns the new inverted object.
9731 * @example
9732 *
9733 * var object = { 'a': 1, 'b': 2, 'c': 1 };
9734 *
9735 * _.invert(object);
9736 * // => { '1': 'c', '2': 'b' }
9737 *
9738 * // with `multiValue`
9739 * _.invert(object, true);
9740 * // => { '1': ['a', 'c'], '2': ['b'] }
9741 */
9742 function invert(object, multiValue, guard) {
9743 if (guard && isIterateeCall(object, multiValue, guard)) {
9744 multiValue = null;
9745 }
9746 var index = -1,
9747 props = keys(object),
9748 length = props.length,
9749 result = {};
9750
9751 while (++index < length) {
9752 var key = props[index],
9753 value = object[key];
9754
9755 if (multiValue) {
9756 if (hasOwnProperty.call(result, value)) {
9757 result[value].push(key);
9758 } else {
9759 result[value] = [key];
9760 }
9761 }
9762 else {
9763 result[value] = key;
9764 }
9765 }
9766 return result;
9767 }
9768
9769 /**
9770 * Creates an array of the own enumerable property names of `object`.
9771 *
9772 * **Note:** Non-object values are coerced to objects. See the
9773 * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.keys)
9774 * for more details.
9775 *
9776 * @static
9777 * @memberOf _
9778 * @category Object
9779 * @param {Object} object The object to inspect.
9780 * @returns {Array} Returns the array of property names.
9781 * @example
9782 *
9783 * function Foo() {
9784 * this.a = 1;
9785 * this.b = 2;
9786 * }
9787 *
9788 * Foo.prototype.c = 3;
9789 *
9790 * _.keys(new Foo);
9791 * // => ['a', 'b'] (iteration order is not guaranteed)
9792 *
9793 * _.keys('hi');
9794 * // => ['0', '1']
9795 */
9796 var keys = !nativeKeys ? shimKeys : function(object) {
9797 if (object) {
9798 var Ctor = object.constructor,
9799 length = object.length;
9800 }
9801 if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
9802 (typeof object != 'function' && (length && isLength(length)))) {
9803 return shimKeys(object);
9804 }
9805 return isObject(object) ? nativeKeys(object) : [];
9806 };
9807
9808 /**
9809 * Creates an array of the own and inherited enumerable property names of `object`.
9810 *
9811 * **Note:** Non-object values are coerced to objects.
9812 *
9813 * @static
9814 * @memberOf _
9815 * @category Object
9816 * @param {Object} object The object to inspect.
9817 * @returns {Array} Returns the array of property names.
9818 * @example
9819 *
9820 * function Foo() {
9821 * this.a = 1;
9822 * this.b = 2;
9823 * }
9824 *
9825 * Foo.prototype.c = 3;
9826 *
9827 * _.keysIn(new Foo);
9828 * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
9829 */
9830 function keysIn(object) {
9831 if (object == null) {
9832 return [];
9833 }
9834 if (!isObject(object)) {
9835 object = Object(object);
9836 }
9837 var length = object.length;
9838 length = (length && isLength(length) &&
9839 (isArray(object) || (support.nonEnumArgs && isArguments(object))) && length) || 0;
9840
9841 var Ctor = object.constructor,
9842 index = -1,
9843 isProto = typeof Ctor == 'function' && Ctor.prototype === object,
9844 result = Array(length),
9845 skipIndexes = length > 0;
9846
9847 while (++index < length) {
9848 result[index] = (index + '');
9849 }
9850 for (var key in object) {
9851 if (!(skipIndexes && isIndex(key, length)) &&
9852 !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
9853 result.push(key);
9854 }
9855 }
9856 return result;
9857 }
9858
9859 /**
9860 * Creates an object with the same keys as `object` and values generated by
9861 * running each own enumerable property of `object` through `iteratee`. The
9862 * iteratee function is bound to `thisArg` and invoked with three arguments:
9863 * (value, key, object).
9864 *
9865 * If a property name is provided for `iteratee` the created `_.property`
9866 * style callback returns the property value of the given element.
9867 *
9868 * If a value is also provided for `thisArg` the created `_.matchesProperty`
9869 * style callback returns `true` for elements that have a matching property
9870 * value, else `false`.
9871 *
9872 * If an object is provided for `iteratee` the created `_.matches` style
9873 * callback returns `true` for elements that have the properties of the given
9874 * object, else `false`.
9875 *
9876 * @static
9877 * @memberOf _
9878 * @category Object
9879 * @param {Object} object The object to iterate over.
9880 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
9881 * per iteration.
9882 * @param {*} [thisArg] The `this` binding of `iteratee`.
9883 * @returns {Object} Returns the new mapped object.
9884 * @example
9885 *
9886 * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
9887 * return n * 3;
9888 * });
9889 * // => { 'a': 3, 'b': 6 }
9890 *
9891 * var users = {
9892 * 'fred': { 'user': 'fred', 'age': 40 },
9893 * 'pebbles': { 'user': 'pebbles', 'age': 1 }
9894 * };
9895 *
9896 * // using the `_.property` callback shorthand
9897 * _.mapValues(users, 'age');
9898 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
9899 */
9900 function mapValues(object, iteratee, thisArg) {
9901 var result = {};
9902 iteratee = getCallback(iteratee, thisArg, 3);
9903
9904 baseForOwn(object, function(value, key, object) {
9905 result[key] = iteratee(value, key, object);
9906 });
9907 return result;
9908 }
9909
9910 /**
9911 * Recursively merges own enumerable properties of the source object(s), that
9912 * don't resolve to `undefined` into the destination object. Subsequent sources
9913 * overwrite property assignments of previous sources. If `customizer` is
9914 * provided it is invoked to produce the merged values of the destination and
9915 * source properties. If `customizer` returns `undefined` merging is handled
9916 * by the method instead. The `customizer` is bound to `thisArg` and invoked
9917 * with five arguments: (objectValue, sourceValue, key, object, source).
9918 *
9919 * @static
9920 * @memberOf _
9921 * @category Object
9922 * @param {Object} object The destination object.
9923 * @param {...Object} [sources] The source objects.
9924 * @param {Function} [customizer] The function to customize merging properties.
9925 * @param {*} [thisArg] The `this` binding of `customizer`.
9926 * @returns {Object} Returns `object`.
9927 * @example
9928 *
9929 * var users = {
9930 * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
9931 * };
9932 *
9933 * var ages = {
9934 * 'data': [{ 'age': 36 }, { 'age': 40 }]
9935 * };
9936 *
9937 * _.merge(users, ages);
9938 * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
9939 *
9940 * // using a customizer callback
9941 * var object = {
9942 * 'fruits': ['apple'],
9943 * 'vegetables': ['beet']
9944 * };
9945 *
9946 * var other = {
9947 * 'fruits': ['banana'],
9948 * 'vegetables': ['carrot']
9949 * };
9950 *
9951 * _.merge(object, other, function(a, b) {
9952 * if (_.isArray(a)) {
9953 * return a.concat(b);
9954 * }
9955 * });
9956 * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
9957 */
9958 var merge = createAssigner(baseMerge);
9959
9960 /**
9961 * The opposite of `_.pick`; this method creates an object composed of the
9962 * own and inherited enumerable properties of `object` that are not omitted.
9963 * Property names may be specified as individual arguments or as arrays of
9964 * property names. If `predicate` is provided it is invoked for each property
9965 * of `object` omitting the properties `predicate` returns truthy for. The
9966 * predicate is bound to `thisArg` and invoked with three arguments:
9967 * (value, key, object).
9968 *
9969 * @static
9970 * @memberOf _
9971 * @category Object
9972 * @param {Object} object The source object.
9973 * @param {Function|...(string|string[])} [predicate] The function invoked per
9974 * iteration or property names to omit, specified as individual property
9975 * names or arrays of property names.
9976 * @param {*} [thisArg] The `this` binding of `predicate`.
9977 * @returns {Object} Returns the new object.
9978 * @example
9979 *
9980 * var object = { 'user': 'fred', 'age': 40 };
9981 *
9982 * _.omit(object, 'age');
9983 * // => { 'user': 'fred' }
9984 *
9985 * _.omit(object, _.isNumber);
9986 * // => { 'user': 'fred' }
9987 */
9988 var omit = restParam(function(object, props) {
9989 if (object == null) {
9990 return {};
9991 }
9992 if (typeof props[0] != 'function') {
9993 var props = arrayMap(baseFlatten(props), String);
9994 return pickByArray(object, baseDifference(keysIn(object), props));
9995 }
9996 var predicate = bindCallback(props[0], props[1], 3);
9997 return pickByCallback(object, function(value, key, object) {
9998 return !predicate(value, key, object);
9999 });
10000 });
10001
10002 /**
10003 * Creates a two dimensional array of the key-value pairs for `object`,
10004 * e.g. `[[key1, value1], [key2, value2]]`.
10005 *
10006 * @static
10007 * @memberOf _
10008 * @category Object
10009 * @param {Object} object The object to inspect.
10010 * @returns {Array} Returns the new array of key-value pairs.
10011 * @example
10012 *
10013 * _.pairs({ 'barney': 36, 'fred': 40 });
10014 * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
10015 */
10016 function pairs(object) {
10017 var index = -1,
10018 props = keys(object),
10019 length = props.length,
10020 result = Array(length);
10021
10022 while (++index < length) {
10023 var key = props[index];
10024 result[index] = [key, object[key]];
10025 }
10026 return result;
10027 }
10028
10029 /**
10030 * Creates an object composed of the picked `object` properties. Property
10031 * names may be specified as individual arguments or as arrays of property
10032 * names. If `predicate` is provided it is invoked for each property of `object`
10033 * picking the properties `predicate` returns truthy for. The predicate is
10034 * bound to `thisArg` and invoked with three arguments: (value, key, object).
10035 *
10036 * @static
10037 * @memberOf _
10038 * @category Object
10039 * @param {Object} object The source object.
10040 * @param {Function|...(string|string[])} [predicate] The function invoked per
10041 * iteration or property names to pick, specified as individual property
10042 * names or arrays of property names.
10043 * @param {*} [thisArg] The `this` binding of `predicate`.
10044 * @returns {Object} Returns the new object.
10045 * @example
10046 *
10047 * var object = { 'user': 'fred', 'age': 40 };
10048 *
10049 * _.pick(object, 'user');
10050 * // => { 'user': 'fred' }
10051 *
10052 * _.pick(object, _.isString);
10053 * // => { 'user': 'fred' }
10054 */
10055 var pick = restParam(function(object, props) {
10056 if (object == null) {
10057 return {};
10058 }
10059 return typeof props[0] == 'function'
10060 ? pickByCallback(object, bindCallback(props[0], props[1], 3))
10061 : pickByArray(object, baseFlatten(props));
10062 });
10063
10064 /**
10065 * Resolves the value of property `key` on `object`. If the value of `key` is
10066 * a function it is invoked with the `this` binding of `object` and its result
10067 * is returned, else the property value is returned. If the property value is
10068 * `undefined` the `defaultValue` is used in its place.
10069 *
10070 * @static
10071 * @memberOf _
10072 * @category Object
10073 * @param {Object} object The object to query.
10074 * @param {string} key The key of the property to resolve.
10075 * @param {*} [defaultValue] The value returned if the property value
10076 * resolves to `undefined`.
10077 * @returns {*} Returns the resolved value.
10078 * @example
10079 *
10080 * var object = { 'user': 'fred', 'age': _.constant(40) };
10081 *
10082 * _.result(object, 'user');
10083 * // => 'fred'
10084 *
10085 * _.result(object, 'age');
10086 * // => 40
10087 *
10088 * _.result(object, 'status', 'busy');
10089 * // => 'busy'
10090 *
10091 * _.result(object, 'status', _.constant('busy'));
10092 * // => 'busy'
10093 */
10094 function result(object, key, defaultValue) {
10095 var value = object == null ? undefined : object[key];
10096 if (typeof value == 'undefined') {
10097 value = defaultValue;
10098 }
10099 return isFunction(value) ? value.call(object) : value;
10100 }
10101
10102 /**
10103 * An alternative to `_.reduce`; this method transforms `object` to a new
10104 * `accumulator` object which is the result of running each of its own enumerable
10105 * properties through `iteratee`, with each invocation potentially mutating
10106 * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
10107 * with four arguments: (accumulator, value, key, object). Iterator functions
10108 * may exit iteration early by explicitly returning `false`.
10109 *
10110 * @static
10111 * @memberOf _
10112 * @category Object
10113 * @param {Array|Object} object The object to iterate over.
10114 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
10115 * @param {*} [accumulator] The custom accumulator value.
10116 * @param {*} [thisArg] The `this` binding of `iteratee`.
10117 * @returns {*} Returns the accumulated value.
10118 * @example
10119 *
10120 * _.transform([2, 3, 4], function(result, n) {
10121 * result.push(n *= n);
10122 * return n % 2 == 0;
10123 * });
10124 * // => [4, 9]
10125 *
10126 * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
10127 * result[key] = n * 3;
10128 * });
10129 * // => { 'a': 3, 'b': 6 }
10130 */
10131 function transform(object, iteratee, accumulator, thisArg) {
10132 var isArr = isArray(object) || isTypedArray(object);
10133 iteratee = getCallback(iteratee, thisArg, 4);
10134
10135 if (accumulator == null) {
10136 if (isArr || isObject(object)) {
10137 var Ctor = object.constructor;
10138 if (isArr) {
10139 accumulator = isArray(object) ? new Ctor : [];
10140 } else {
10141 accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype);
10142 }
10143 } else {
10144 accumulator = {};
10145 }
10146 }
10147 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
10148 return iteratee(accumulator, value, index, object);
10149 });
10150 return accumulator;
10151 }
10152
10153 /**
10154 * Creates an array of the own enumerable property values of `object`.
10155 *
10156 * **Note:** Non-object values are coerced to objects.
10157 *
10158 * @static
10159 * @memberOf _
10160 * @category Object
10161 * @param {Object} object The object to query.
10162 * @returns {Array} Returns the array of property values.
10163 * @example
10164 *
10165 * function Foo() {
10166 * this.a = 1;
10167 * this.b = 2;
10168 * }
10169 *
10170 * Foo.prototype.c = 3;
10171 *
10172 * _.values(new Foo);
10173 * // => [1, 2] (iteration order is not guaranteed)
10174 *
10175 * _.values('hi');
10176 * // => ['h', 'i']
10177 */
10178 function values(object) {
10179 return baseValues(object, keys(object));
10180 }
10181
10182 /**
10183 * Creates an array of the own and inherited enumerable property values
10184 * of `object`.
10185 *
10186 * **Note:** Non-object values are coerced to objects.
10187 *
10188 * @static
10189 * @memberOf _
10190 * @category Object
10191 * @param {Object} object The object to query.
10192 * @returns {Array} Returns the array of property values.
10193 * @example
10194 *
10195 * function Foo() {
10196 * this.a = 1;
10197 * this.b = 2;
10198 * }
10199 *
10200 * Foo.prototype.c = 3;
10201 *
10202 * _.valuesIn(new Foo);
10203 * // => [1, 2, 3] (iteration order is not guaranteed)
10204 */
10205 function valuesIn(object) {
10206 return baseValues(object, keysIn(object));
10207 }
10208
10209 /*------------------------------------------------------------------------*/
10210
10211 /**
10212 * Checks if `n` is between `start` and up to but not including, `end`. If
10213 * `end` is not specified it is set to `start` with `start` then set to `0`.
10214 *
10215 * @static
10216 * @memberOf _
10217 * @category Number
10218 * @param {number} n The number to check.
10219 * @param {number} [start=0] The start of the range.
10220 * @param {number} end The end of the range.
10221 * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
10222 * @example
10223 *
10224 * _.inRange(3, 2, 4);
10225 * // => true
10226 *
10227 * _.inRange(4, 8);
10228 * // => true
10229 *
10230 * _.inRange(4, 2);
10231 * // => false
10232 *
10233 * _.inRange(2, 2);
10234 * // => false
10235 *
10236 * _.inRange(1.2, 2);
10237 * // => true
10238 *
10239 * _.inRange(5.2, 4);
10240 * // => false
10241 */
10242 function inRange(value, start, end) {
10243 start = +start || 0;
10244 if (typeof end === 'undefined') {
10245 end = start;
10246 start = 0;
10247 } else {
10248 end = +end || 0;
10249 }
10250 return value >= start && value < end;
10251 }
10252
10253 /**
10254 * Produces a random number between `min` and `max` (inclusive). If only one
10255 * argument is provided a number between `0` and the given number is returned.
10256 * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
10257 * number is returned instead of an integer.
10258 *
10259 * @static
10260 * @memberOf _
10261 * @category Number
10262 * @param {number} [min=0] The minimum possible value.
10263 * @param {number} [max=1] The maximum possible value.
10264 * @param {boolean} [floating] Specify returning a floating-point number.
10265 * @returns {number} Returns the random number.
10266 * @example
10267 *
10268 * _.random(0, 5);
10269 * // => an integer between 0 and 5
10270 *
10271 * _.random(5);
10272 * // => also an integer between 0 and 5
10273 *
10274 * _.random(5, true);
10275 * // => a floating-point number between 0 and 5
10276 *
10277 * _.random(1.2, 5.2);
10278 * // => a floating-point number between 1.2 and 5.2
10279 */
10280 function random(min, max, floating) {
10281 if (floating && isIterateeCall(min, max, floating)) {
10282 max = floating = null;
10283 }
10284 var noMin = min == null,
10285 noMax = max == null;
10286
10287 if (floating == null) {
10288 if (noMax && typeof min == 'boolean') {
10289 floating = min;
10290 min = 1;
10291 }
10292 else if (typeof max == 'boolean') {
10293 floating = max;
10294 noMax = true;
10295 }
10296 }
10297 if (noMin && noMax) {
10298 max = 1;
10299 noMax = false;
10300 }
10301 min = +min || 0;
10302 if (noMax) {
10303 max = min;
10304 min = 0;
10305 } else {
10306 max = +max || 0;
10307 }
10308 if (floating || min % 1 || max % 1) {
10309 var rand = nativeRandom();
10310 return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
10311 }
10312 return baseRandom(min, max);
10313 }
10314
10315 /*------------------------------------------------------------------------*/
10316
10317 /**
10318 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
10319 *
10320 * @static
10321 * @memberOf _
10322 * @category String
10323 * @param {string} [string=''] The string to convert.
10324 * @returns {string} Returns the camel cased string.
10325 * @example
10326 *
10327 * _.camelCase('Foo Bar');
10328 * // => 'fooBar'
10329 *
10330 * _.camelCase('--foo-bar');
10331 * // => 'fooBar'
10332 *
10333 * _.camelCase('__foo_bar__');
10334 * // => 'fooBar'
10335 */
10336 var camelCase = createCompounder(function(result, word, index) {
10337 word = word.toLowerCase();
10338 return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
10339 });
10340
10341 /**
10342 * Capitalizes the first character of `string`.
10343 *
10344 * @static
10345 * @memberOf _
10346 * @category String
10347 * @param {string} [string=''] The string to capitalize.
10348 * @returns {string} Returns the capitalized string.
10349 * @example
10350 *
10351 * _.capitalize('fred');
10352 * // => 'Fred'
10353 */
10354 function capitalize(string) {
10355 string = baseToString(string);
10356 return string && (string.charAt(0).toUpperCase() + string.slice(1));
10357 }
10358
10359 /**
10360 * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
10361 * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
10362 *
10363 * @static
10364 * @memberOf _
10365 * @category String
10366 * @param {string} [string=''] The string to deburr.
10367 * @returns {string} Returns the deburred string.
10368 * @example
10369 *
10370 * _.deburr('déjà vu');
10371 * // => 'deja vu'
10372 */
10373 function deburr(string) {
10374 string = baseToString(string);
10375 return string && string.replace(reLatin1, deburrLetter).replace(reComboMarks, '');
10376 }
10377
10378 /**
10379 * Checks if `string` ends with the given target string.
10380 *
10381 * @static
10382 * @memberOf _
10383 * @category String
10384 * @param {string} [string=''] The string to search.
10385 * @param {string} [target] The string to search for.
10386 * @param {number} [position=string.length] The position to search from.
10387 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
10388 * @example
10389 *
10390 * _.endsWith('abc', 'c');
10391 * // => true
10392 *
10393 * _.endsWith('abc', 'b');
10394 * // => false
10395 *
10396 * _.endsWith('abc', 'b', 2);
10397 * // => true
10398 */
10399 function endsWith(string, target, position) {
10400 string = baseToString(string);
10401 target = (target + '');
10402
10403 var length = string.length;
10404 position = typeof position == 'undefined'
10405 ? length
10406 : nativeMin(position < 0 ? 0 : (+position || 0), length);
10407
10408 position -= target.length;
10409 return position >= 0 && string.indexOf(target, position) == position;
10410 }
10411
10412 /**
10413 * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
10414 * their corresponding HTML entities.
10415 *
10416 * **Note:** No other characters are escaped. To escape additional characters
10417 * use a third-party library like [_he_](https://mths.be/he).
10418 *
10419 * Though the ">" character is escaped for symmetry, characters like
10420 * ">" and "/" don't require escaping in HTML and have no special meaning
10421 * unless they're part of a tag or unquoted attribute value.
10422 * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
10423 * (under "semi-related fun fact") for more details.
10424 *
10425 * Backticks are escaped because in Internet Explorer < 9, they can break out
10426 * of attribute values or HTML comments. See [#102](https://html5sec.org/#102),
10427 * [#108](https://html5sec.org/#108), and [#133](https://html5sec.org/#133) of
10428 * the [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
10429 *
10430 * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
10431 * to reduce XSS vectors.
10432 *
10433 * @static
10434 * @memberOf _
10435 * @category String
10436 * @param {string} [string=''] The string to escape.
10437 * @returns {string} Returns the escaped string.
10438 * @example
10439 *
10440 * _.escape('fred, barney, & pebbles');
10441 * // => 'fred, barney, &amp; pebbles'
10442 */
10443 function escape(string) {
10444 // Reset `lastIndex` because in IE < 9 `String#replace` does not.
10445 string = baseToString(string);
10446 return (string && reHasUnescapedHtml.test(string))
10447 ? string.replace(reUnescapedHtml, escapeHtmlChar)
10448 : string;
10449 }
10450
10451 /**
10452 * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
10453 * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
10454 *
10455 * @static
10456 * @memberOf _
10457 * @category String
10458 * @param {string} [string=''] The string to escape.
10459 * @returns {string} Returns the escaped string.
10460 * @example
10461 *
10462 * _.escapeRegExp('[lodash](https://lodash.com/)');
10463 * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
10464 */
10465 function escapeRegExp(string) {
10466 string = baseToString(string);
10467 return (string && reHasRegExpChars.test(string))
10468 ? string.replace(reRegExpChars, '\\$&')
10469 : string;
10470 }
10471
10472 /**
10473 * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
10474 *
10475 * @static
10476 * @memberOf _
10477 * @category String
10478 * @param {string} [string=''] The string to convert.
10479 * @returns {string} Returns the kebab cased string.
10480 * @example
10481 *
10482 * _.kebabCase('Foo Bar');
10483 * // => 'foo-bar'
10484 *
10485 * _.kebabCase('fooBar');
10486 * // => 'foo-bar'
10487 *
10488 * _.kebabCase('__foo_bar__');
10489 * // => 'foo-bar'
10490 */
10491 var kebabCase = createCompounder(function(result, word, index) {
10492 return result + (index ? '-' : '') + word.toLowerCase();
10493 });
10494
10495 /**
10496 * Pads `string` on the left and right sides if it is shorter than `length`.
10497 * Padding characters are truncated if they can't be evenly divided by `length`.
10498 *
10499 * @static
10500 * @memberOf _
10501 * @category String
10502 * @param {string} [string=''] The string to pad.
10503 * @param {number} [length=0] The padding length.
10504 * @param {string} [chars=' '] The string used as padding.
10505 * @returns {string} Returns the padded string.
10506 * @example
10507 *
10508 * _.pad('abc', 8);
10509 * // => ' abc '
10510 *
10511 * _.pad('abc', 8, '_-');
10512 * // => '_-abc_-_'
10513 *
10514 * _.pad('abc', 3);
10515 * // => 'abc'
10516 */
10517 function pad(string, length, chars) {
10518 string = baseToString(string);
10519 length = +length;
10520
10521 var strLength = string.length;
10522 if (strLength >= length || !nativeIsFinite(length)) {
10523 return string;
10524 }
10525 var mid = (length - strLength) / 2,
10526 leftLength = floor(mid),
10527 rightLength = ceil(mid);
10528
10529 chars = createPadding('', rightLength, chars);
10530 return chars.slice(0, leftLength) + string + chars;
10531 }
10532
10533 /**
10534 * Pads `string` on the left side if it is shorter than `length`. Padding
10535 * characters are truncated if they exceed `length`.
10536 *
10537 * @static
10538 * @memberOf _
10539 * @category String
10540 * @param {string} [string=''] The string to pad.
10541 * @param {number} [length=0] The padding length.
10542 * @param {string} [chars=' '] The string used as padding.
10543 * @returns {string} Returns the padded string.
10544 * @example
10545 *
10546 * _.padLeft('abc', 6);
10547 * // => ' abc'
10548 *
10549 * _.padLeft('abc', 6, '_-');
10550 * // => '_-_abc'
10551 *
10552 * _.padLeft('abc', 3);
10553 * // => 'abc'
10554 */
10555 var padLeft = createPadDir();
10556
10557 /**
10558 * Pads `string` on the right side if it is shorter than `length`. Padding
10559 * characters are truncated if they exceed `length`.
10560 *
10561 * @static
10562 * @memberOf _
10563 * @category String
10564 * @param {string} [string=''] The string to pad.
10565 * @param {number} [length=0] The padding length.
10566 * @param {string} [chars=' '] The string used as padding.
10567 * @returns {string} Returns the padded string.
10568 * @example
10569 *
10570 * _.padRight('abc', 6);
10571 * // => 'abc '
10572 *
10573 * _.padRight('abc', 6, '_-');
10574 * // => 'abc_-_'
10575 *
10576 * _.padRight('abc', 3);
10577 * // => 'abc'
10578 */
10579 var padRight = createPadDir(true);
10580
10581 /**
10582 * Converts `string` to an integer of the specified radix. If `radix` is
10583 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
10584 * in which case a `radix` of `16` is used.
10585 *
10586 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
10587 * of `parseInt`.
10588 *
10589 * @static
10590 * @memberOf _
10591 * @category String
10592 * @param {string} string The string to convert.
10593 * @param {number} [radix] The radix to interpret `value` by.
10594 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10595 * @returns {number} Returns the converted integer.
10596 * @example
10597 *
10598 * _.parseInt('08');
10599 * // => 8
10600 *
10601 * _.map(['6', '08', '10'], _.parseInt);
10602 * // => [6, 8, 10]
10603 */
10604 function parseInt(string, radix, guard) {
10605 if (guard && isIterateeCall(string, radix, guard)) {
10606 radix = 0;
10607 }
10608 return nativeParseInt(string, radix);
10609 }
10610 // Fallback for environments with pre-ES5 implementations.
10611 if (nativeParseInt(whitespace + '08') != 8) {
10612 parseInt = function(string, radix, guard) {
10613 // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
10614 // Chrome fails to trim leading <BOM> whitespace characters.
10615 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
10616 if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
10617 radix = 0;
10618 } else if (radix) {
10619 radix = +radix;
10620 }
10621 string = trim(string);
10622 return nativeParseInt(string, radix || (reHexPrefix.test(string) ? 16 : 10));
10623 };
10624 }
10625
10626 /**
10627 * Repeats the given string `n` times.
10628 *
10629 * @static
10630 * @memberOf _
10631 * @category String
10632 * @param {string} [string=''] The string to repeat.
10633 * @param {number} [n=0] The number of times to repeat the string.
10634 * @returns {string} Returns the repeated string.
10635 * @example
10636 *
10637 * _.repeat('*', 3);
10638 * // => '***'
10639 *
10640 * _.repeat('abc', 2);
10641 * // => 'abcabc'
10642 *
10643 * _.repeat('abc', 0);
10644 * // => ''
10645 */
10646 function repeat(string, n) {
10647 var result = '';
10648 string = baseToString(string);
10649 n = +n;
10650 if (n < 1 || !string || !nativeIsFinite(n)) {
10651 return result;
10652 }
10653 // Leverage the exponentiation by squaring algorithm for a faster repeat.
10654 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
10655 do {
10656 if (n % 2) {
10657 result += string;
10658 }
10659 n = floor(n / 2);
10660 string += string;
10661 } while (n);
10662
10663 return result;
10664 }
10665
10666 /**
10667 * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
10668 *
10669 * @static
10670 * @memberOf _
10671 * @category String
10672 * @param {string} [string=''] The string to convert.
10673 * @returns {string} Returns the snake cased string.
10674 * @example
10675 *
10676 * _.snakeCase('Foo Bar');
10677 * // => 'foo_bar'
10678 *
10679 * _.snakeCase('fooBar');
10680 * // => 'foo_bar'
10681 *
10682 * _.snakeCase('--foo-bar');
10683 * // => 'foo_bar'
10684 */
10685 var snakeCase = createCompounder(function(result, word, index) {
10686 return result + (index ? '_' : '') + word.toLowerCase();
10687 });
10688
10689 /**
10690 * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
10691 *
10692 * @static
10693 * @memberOf _
10694 * @category String
10695 * @param {string} [string=''] The string to convert.
10696 * @returns {string} Returns the start cased string.
10697 * @example
10698 *
10699 * _.startCase('--foo-bar');
10700 * // => 'Foo Bar'
10701 *
10702 * _.startCase('fooBar');
10703 * // => 'Foo Bar'
10704 *
10705 * _.startCase('__foo_bar__');
10706 * // => 'Foo Bar'
10707 */
10708 var startCase = createCompounder(function(result, word, index) {
10709 return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
10710 });
10711
10712 /**
10713 * Checks if `string` starts with the given target string.
10714 *
10715 * @static
10716 * @memberOf _
10717 * @category String
10718 * @param {string} [string=''] The string to search.
10719 * @param {string} [target] The string to search for.
10720 * @param {number} [position=0] The position to search from.
10721 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
10722 * @example
10723 *
10724 * _.startsWith('abc', 'a');
10725 * // => true
10726 *
10727 * _.startsWith('abc', 'b');
10728 * // => false
10729 *
10730 * _.startsWith('abc', 'b', 1);
10731 * // => true
10732 */
10733 function startsWith(string, target, position) {
10734 string = baseToString(string);
10735 position = position == null
10736 ? 0
10737 : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
10738
10739 return string.lastIndexOf(target, position) == position;
10740 }
10741
10742 /**
10743 * Creates a compiled template function that can interpolate data properties
10744 * in "interpolate" delimiters, HTML-escape interpolated data properties in
10745 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
10746 * properties may be accessed as free variables in the template. If a setting
10747 * object is provided it takes precedence over `_.templateSettings` values.
10748 *
10749 * **Note:** In the development build `_.template` utilizes
10750 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
10751 * for easier debugging.
10752 *
10753 * For more information on precompiling templates see
10754 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
10755 *
10756 * For more information on Chrome extension sandboxes see
10757 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
10758 *
10759 * @static
10760 * @memberOf _
10761 * @category String
10762 * @param {string} [string=''] The template string.
10763 * @param {Object} [options] The options object.
10764 * @param {RegExp} [options.escape] The HTML "escape" delimiter.
10765 * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
10766 * @param {Object} [options.imports] An object to import into the template as free variables.
10767 * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
10768 * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
10769 * @param {string} [options.variable] The data object variable name.
10770 * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
10771 * @returns {Function} Returns the compiled template function.
10772 * @example
10773 *
10774 * // using the "interpolate" delimiter to create a compiled template
10775 * var compiled = _.template('hello <%= user %>!');
10776 * compiled({ 'user': 'fred' });
10777 * // => 'hello fred!'
10778 *
10779 * // using the HTML "escape" delimiter to escape data property values
10780 * var compiled = _.template('<b><%- value %></b>');
10781 * compiled({ 'value': '<script>' });
10782 * // => '<b>&lt;script&gt;</b>'
10783 *
10784 * // using the "evaluate" delimiter to execute JavaScript and generate HTML
10785 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
10786 * compiled({ 'users': ['fred', 'barney'] });
10787 * // => '<li>fred</li><li>barney</li>'
10788 *
10789 * // using the internal `print` function in "evaluate" delimiters
10790 * var compiled = _.template('<% print("hello " + user); %>!');
10791 * compiled({ 'user': 'barney' });
10792 * // => 'hello barney!'
10793 *
10794 * // using the ES delimiter as an alternative to the default "interpolate" delimiter
10795 * var compiled = _.template('hello ${ user }!');
10796 * compiled({ 'user': 'pebbles' });
10797 * // => 'hello pebbles!'
10798 *
10799 * // using custom template delimiters
10800 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
10801 * var compiled = _.template('hello {{ user }}!');
10802 * compiled({ 'user': 'mustache' });
10803 * // => 'hello mustache!'
10804 *
10805 * // using backslashes to treat delimiters as plain text
10806 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
10807 * compiled({ 'value': 'ignored' });
10808 * // => '<%- value %>'
10809 *
10810 * // using the `imports` option to import `jQuery` as `jq`
10811 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
10812 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
10813 * compiled({ 'users': ['fred', 'barney'] });
10814 * // => '<li>fred</li><li>barney</li>'
10815 *
10816 * // using the `sourceURL` option to specify a custom sourceURL for the template
10817 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
10818 * compiled(data);
10819 * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
10820 *
10821 * // using the `variable` option to ensure a with-statement isn't used in the compiled template
10822 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
10823 * compiled.source;
10824 * // => function(data) {
10825 * // var __t, __p = '';
10826 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
10827 * // return __p;
10828 * // }
10829 *
10830 * // using the `source` property to inline compiled templates for meaningful
10831 * // line numbers in error messages and a stack trace
10832 * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
10833 * var JST = {\
10834 * "main": ' + _.template(mainText).source + '\
10835 * };\
10836 * ');
10837 */
10838 function template(string, options, otherOptions) {
10839 // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
10840 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
10841 var settings = lodash.templateSettings;
10842
10843 if (otherOptions && isIterateeCall(string, options, otherOptions)) {
10844 options = otherOptions = null;
10845 }
10846 string = baseToString(string);
10847 options = baseAssign(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
10848
10849 var imports = baseAssign(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
10850 importsKeys = keys(imports),
10851 importsValues = baseValues(imports, importsKeys);
10852
10853 var isEscaping,
10854 isEvaluating,
10855 index = 0,
10856 interpolate = options.interpolate || reNoMatch,
10857 source = "__p += '";
10858
10859 // Compile the regexp to match each delimiter.
10860 var reDelimiters = RegExp(
10861 (options.escape || reNoMatch).source + '|' +
10862 interpolate.source + '|' +
10863 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
10864 (options.evaluate || reNoMatch).source + '|$'
10865 , 'g');
10866
10867 // Use a sourceURL for easier debugging.
10868 var sourceURL = '//# sourceURL=' +
10869 ('sourceURL' in options
10870 ? options.sourceURL
10871 : ('lodash.templateSources[' + (++templateCounter) + ']')
10872 ) + '\n';
10873
10874 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
10875 interpolateValue || (interpolateValue = esTemplateValue);
10876
10877 // Escape characters that can't be included in string literals.
10878 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
10879
10880 // Replace delimiters with snippets.
10881 if (escapeValue) {
10882 isEscaping = true;
10883 source += "' +\n__e(" + escapeValue + ") +\n'";
10884 }
10885 if (evaluateValue) {
10886 isEvaluating = true;
10887 source += "';\n" + evaluateValue + ";\n__p += '";
10888 }
10889 if (interpolateValue) {
10890 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
10891 }
10892 index = offset + match.length;
10893
10894 // The JS engine embedded in Adobe products requires returning the `match`
10895 // string in order to produce the correct `offset` value.
10896 return match;
10897 });
10898
10899 source += "';\n";
10900
10901 // If `variable` is not specified wrap a with-statement around the generated
10902 // code to add the data object to the top of the scope chain.
10903 var variable = options.variable;
10904 if (!variable) {
10905 source = 'with (obj) {\n' + source + '\n}\n';
10906 }
10907 // Cleanup code by stripping empty strings.
10908 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
10909 .replace(reEmptyStringMiddle, '$1')
10910 .replace(reEmptyStringTrailing, '$1;');
10911
10912 // Frame code as the function body.
10913 source = 'function(' + (variable || 'obj') + ') {\n' +
10914 (variable
10915 ? ''
10916 : 'obj || (obj = {});\n'
10917 ) +
10918 "var __t, __p = ''" +
10919 (isEscaping
10920 ? ', __e = _.escape'
10921 : ''
10922 ) +
10923 (isEvaluating
10924 ? ', __j = Array.prototype.join;\n' +
10925 "function print() { __p += __j.call(arguments, '') }\n"
10926 : ';\n'
10927 ) +
10928 source +
10929 'return __p\n}';
10930
10931 var result = attempt(function() {
10932 return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
10933 });
10934
10935 // Provide the compiled function's source by its `toString` method or
10936 // the `source` property as a convenience for inlining compiled templates.
10937 result.source = source;
10938 if (isError(result)) {
10939 throw result;
10940 }
10941 return result;
10942 }
10943
10944 /**
10945 * Removes leading and trailing whitespace or specified characters from `string`.
10946 *
10947 * @static
10948 * @memberOf _
10949 * @category String
10950 * @param {string} [string=''] The string to trim.
10951 * @param {string} [chars=whitespace] The characters to trim.
10952 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10953 * @returns {string} Returns the trimmed string.
10954 * @example
10955 *
10956 * _.trim(' abc ');
10957 * // => 'abc'
10958 *
10959 * _.trim('-_-abc-_-', '_-');
10960 * // => 'abc'
10961 *
10962 * _.map([' foo ', ' bar '], _.trim);
10963 * // => ['foo', 'bar']
10964 */
10965 function trim(string, chars, guard) {
10966 var value = string;
10967 string = baseToString(string);
10968 if (!string) {
10969 return string;
10970 }
10971 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
10972 return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
10973 }
10974 chars = (chars + '');
10975 return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
10976 }
10977
10978 /**
10979 * Removes leading whitespace or specified characters from `string`.
10980 *
10981 * @static
10982 * @memberOf _
10983 * @category String
10984 * @param {string} [string=''] The string to trim.
10985 * @param {string} [chars=whitespace] The characters to trim.
10986 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
10987 * @returns {string} Returns the trimmed string.
10988 * @example
10989 *
10990 * _.trimLeft(' abc ');
10991 * // => 'abc '
10992 *
10993 * _.trimLeft('-_-abc-_-', '_-');
10994 * // => 'abc-_-'
10995 */
10996 function trimLeft(string, chars, guard) {
10997 var value = string;
10998 string = baseToString(string);
10999 if (!string) {
11000 return string;
11001 }
11002 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
11003 return string.slice(trimmedLeftIndex(string));
11004 }
11005 return string.slice(charsLeftIndex(string, (chars + '')));
11006 }
11007
11008 /**
11009 * Removes trailing whitespace or specified characters from `string`.
11010 *
11011 * @static
11012 * @memberOf _
11013 * @category String
11014 * @param {string} [string=''] The string to trim.
11015 * @param {string} [chars=whitespace] The characters to trim.
11016 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11017 * @returns {string} Returns the trimmed string.
11018 * @example
11019 *
11020 * _.trimRight(' abc ');
11021 * // => ' abc'
11022 *
11023 * _.trimRight('-_-abc-_-', '_-');
11024 * // => '-_-abc'
11025 */
11026 function trimRight(string, chars, guard) {
11027 var value = string;
11028 string = baseToString(string);
11029 if (!string) {
11030 return string;
11031 }
11032 if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
11033 return string.slice(0, trimmedRightIndex(string) + 1);
11034 }
11035 return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
11036 }
11037
11038 /**
11039 * Truncates `string` if it is longer than the given maximum string length.
11040 * The last characters of the truncated string are replaced with the omission
11041 * string which defaults to "...".
11042 *
11043 * @static
11044 * @memberOf _
11045 * @category String
11046 * @param {string} [string=''] The string to truncate.
11047 * @param {Object|number} [options] The options object or maximum string length.
11048 * @param {number} [options.length=30] The maximum string length.
11049 * @param {string} [options.omission='...'] The string to indicate text is omitted.
11050 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
11051 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11052 * @returns {string} Returns the truncated string.
11053 * @example
11054 *
11055 * _.trunc('hi-diddly-ho there, neighborino');
11056 * // => 'hi-diddly-ho there, neighbo...'
11057 *
11058 * _.trunc('hi-diddly-ho there, neighborino', 24);
11059 * // => 'hi-diddly-ho there, n...'
11060 *
11061 * _.trunc('hi-diddly-ho there, neighborino', {
11062 * 'length': 24,
11063 * 'separator': ' '
11064 * });
11065 * // => 'hi-diddly-ho there,...'
11066 *
11067 * _.trunc('hi-diddly-ho there, neighborino', {
11068 * 'length': 24,
11069 * 'separator': /,? +/
11070 * });
11071 * // => 'hi-diddly-ho there...'
11072 *
11073 * _.trunc('hi-diddly-ho there, neighborino', {
11074 * 'omission': ' [...]'
11075 * });
11076 * // => 'hi-diddly-ho there, neig [...]'
11077 */
11078 function trunc(string, options, guard) {
11079 if (guard && isIterateeCall(string, options, guard)) {
11080 options = null;
11081 }
11082 var length = DEFAULT_TRUNC_LENGTH,
11083 omission = DEFAULT_TRUNC_OMISSION;
11084
11085 if (options != null) {
11086 if (isObject(options)) {
11087 var separator = 'separator' in options ? options.separator : separator;
11088 length = 'length' in options ? (+options.length || 0) : length;
11089 omission = 'omission' in options ? baseToString(options.omission) : omission;
11090 } else {
11091 length = +options || 0;
11092 }
11093 }
11094 string = baseToString(string);
11095 if (length >= string.length) {
11096 return string;
11097 }
11098 var end = length - omission.length;
11099 if (end < 1) {
11100 return omission;
11101 }
11102 var result = string.slice(0, end);
11103 if (separator == null) {
11104 return result + omission;
11105 }
11106 if (isRegExp(separator)) {
11107 if (string.slice(end).search(separator)) {
11108 var match,
11109 newEnd,
11110 substring = string.slice(0, end);
11111
11112 if (!separator.global) {
11113 separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
11114 }
11115 separator.lastIndex = 0;
11116 while ((match = separator.exec(substring))) {
11117 newEnd = match.index;
11118 }
11119 result = result.slice(0, newEnd == null ? end : newEnd);
11120 }
11121 } else if (string.indexOf(separator, end) != end) {
11122 var index = result.lastIndexOf(separator);
11123 if (index > -1) {
11124 result = result.slice(0, index);
11125 }
11126 }
11127 return result + omission;
11128 }
11129
11130 /**
11131 * The inverse of `_.escape`; this method converts the HTML entities
11132 * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
11133 * corresponding characters.
11134 *
11135 * **Note:** No other HTML entities are unescaped. To unescape additional HTML
11136 * entities use a third-party library like [_he_](https://mths.be/he).
11137 *
11138 * @static
11139 * @memberOf _
11140 * @category String
11141 * @param {string} [string=''] The string to unescape.
11142 * @returns {string} Returns the unescaped string.
11143 * @example
11144 *
11145 * _.unescape('fred, barney, &amp; pebbles');
11146 * // => 'fred, barney, & pebbles'
11147 */
11148 function unescape(string) {
11149 string = baseToString(string);
11150 return (string && reHasEscapedHtml.test(string))
11151 ? string.replace(reEscapedHtml, unescapeHtmlChar)
11152 : string;
11153 }
11154
11155 /**
11156 * Splits `string` into an array of its words.
11157 *
11158 * @static
11159 * @memberOf _
11160 * @category String
11161 * @param {string} [string=''] The string to inspect.
11162 * @param {RegExp|string} [pattern] The pattern to match words.
11163 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11164 * @returns {Array} Returns the words of `string`.
11165 * @example
11166 *
11167 * _.words('fred, barney, & pebbles');
11168 * // => ['fred', 'barney', 'pebbles']
11169 *
11170 * _.words('fred, barney, & pebbles', /[^, ]+/g);
11171 * // => ['fred', 'barney', '&', 'pebbles']
11172 */
11173 function words(string, pattern, guard) {
11174 if (guard && isIterateeCall(string, pattern, guard)) {
11175 pattern = null;
11176 }
11177 string = baseToString(string);
11178 return string.match(pattern || reWords) || [];
11179 }
11180
11181 /*------------------------------------------------------------------------*/
11182
11183 /**
11184 * Attempts to invoke `func`, returning either the result or the caught error
11185 * object. Any additional arguments are provided to `func` when it is invoked.
11186 *
11187 * @static
11188 * @memberOf _
11189 * @category Utility
11190 * @param {Function} func The function to attempt.
11191 * @returns {*} Returns the `func` result or error object.
11192 * @example
11193 *
11194 * // avoid throwing errors for invalid selectors
11195 * var elements = _.attempt(function(selector) {
11196 * return document.querySelectorAll(selector);
11197 * }, '>_>');
11198 *
11199 * if (_.isError(elements)) {
11200 * elements = [];
11201 * }
11202 */
11203 var attempt = restParam(function(func, args) {
11204 try {
11205 return func.apply(undefined, args);
11206 } catch(e) {
11207 return isError(e) ? e : new Error(e);
11208 }
11209 });
11210
11211 /**
11212 * Creates a function that invokes `func` with the `this` binding of `thisArg`
11213 * and arguments of the created function. If `func` is a property name the
11214 * created callback returns the property value for a given element. If `func`
11215 * is an object the created callback returns `true` for elements that contain
11216 * the equivalent object properties, otherwise it returns `false`.
11217 *
11218 * @static
11219 * @memberOf _
11220 * @alias iteratee
11221 * @category Utility
11222 * @param {*} [func=_.identity] The value to convert to a callback.
11223 * @param {*} [thisArg] The `this` binding of `func`.
11224 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
11225 * @returns {Function} Returns the callback.
11226 * @example
11227 *
11228 * var users = [
11229 * { 'user': 'barney', 'age': 36 },
11230 * { 'user': 'fred', 'age': 40 }
11231 * ];
11232 *
11233 * // wrap to create custom callback shorthands
11234 * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
11235 * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
11236 * if (!match) {
11237 * return callback(func, thisArg);
11238 * }
11239 * return function(object) {
11240 * return match[2] == 'gt'
11241 * ? object[match[1]] > match[3]
11242 * : object[match[1]] < match[3];
11243 * };
11244 * });
11245 *
11246 * _.filter(users, 'age__gt36');
11247 * // => [{ 'user': 'fred', 'age': 40 }]
11248 */
11249 function callback(func, thisArg, guard) {
11250 if (guard && isIterateeCall(func, thisArg, guard)) {
11251 thisArg = null;
11252 }
11253 return isObjectLike(func)
11254 ? matches(func)
11255 : baseCallback(func, thisArg);
11256 }
11257
11258 /**
11259 * Creates a function that returns `value`.
11260 *
11261 * @static
11262 * @memberOf _
11263 * @category Utility
11264 * @param {*} value The value to return from the new function.
11265 * @returns {Function} Returns the new function.
11266 * @example
11267 *
11268 * var object = { 'user': 'fred' };
11269 * var getter = _.constant(object);
11270 *
11271 * getter() === object;
11272 * // => true
11273 */
11274 function constant(value) {
11275 return function() {
11276 return value;
11277 };
11278 }
11279
11280 /**
11281 * This method returns the first argument provided to it.
11282 *
11283 * @static
11284 * @memberOf _
11285 * @category Utility
11286 * @param {*} value Any value.
11287 * @returns {*} Returns `value`.
11288 * @example
11289 *
11290 * var object = { 'user': 'fred' };
11291 *
11292 * _.identity(object) === object;
11293 * // => true
11294 */
11295 function identity(value) {
11296 return value;
11297 }
11298
11299 /**
11300 * Creates a function which performs a deep comparison between a given object
11301 * and `source`, returning `true` if the given object has equivalent property
11302 * values, else `false`.
11303 *
11304 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
11305 * numbers, `Object` objects, regexes, and strings. Objects are compared by
11306 * their own, not inherited, enumerable properties. For comparing a single
11307 * own or inherited property value see `_.matchesProperty`.
11308 *
11309 * @static
11310 * @memberOf _
11311 * @category Utility
11312 * @param {Object} source The object of property values to match.
11313 * @returns {Function} Returns the new function.
11314 * @example
11315 *
11316 * var users = [
11317 * { 'user': 'barney', 'age': 36, 'active': true },
11318 * { 'user': 'fred', 'age': 40, 'active': false }
11319 * ];
11320 *
11321 * _.filter(users, _.matches({ 'age': 40, 'active': false }));
11322 * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
11323 */
11324 function matches(source) {
11325 return baseMatches(baseClone(source, true));
11326 }
11327
11328 /**
11329 * Creates a function which compares the property value of `key` on a given
11330 * object to `value`.
11331 *
11332 * **Note:** This method supports comparing arrays, booleans, `Date` objects,
11333 * numbers, `Object` objects, regexes, and strings. Objects are compared by
11334 * their own, not inherited, enumerable properties.
11335 *
11336 * @static
11337 * @memberOf _
11338 * @category Utility
11339 * @param {string} key The key of the property to get.
11340 * @param {*} value The value to compare.
11341 * @returns {Function} Returns the new function.
11342 * @example
11343 *
11344 * var users = [
11345 * { 'user': 'barney' },
11346 * { 'user': 'fred' }
11347 * ];
11348 *
11349 * _.find(users, _.matchesProperty('user', 'fred'));
11350 * // => { 'user': 'fred' }
11351 */
11352 function matchesProperty(key, value) {
11353 return baseMatchesProperty(key + '', baseClone(value, true));
11354 }
11355
11356 /**
11357 * Adds all own enumerable function properties of a source object to the
11358 * destination object. If `object` is a function then methods are added to
11359 * its prototype as well.
11360 *
11361 * **Note:** Use `_.runInContext` to create a pristine `lodash` function
11362 * for mixins to avoid conflicts caused by modifying the original.
11363 *
11364 * @static
11365 * @memberOf _
11366 * @category Utility
11367 * @param {Function|Object} [object=this] object The destination object.
11368 * @param {Object} source The object of functions to add.
11369 * @param {Object} [options] The options object.
11370 * @param {boolean} [options.chain=true] Specify whether the functions added
11371 * are chainable.
11372 * @returns {Function|Object} Returns `object`.
11373 * @example
11374 *
11375 * function vowels(string) {
11376 * return _.filter(string, function(v) {
11377 * return /[aeiou]/i.test(v);
11378 * });
11379 * }
11380 *
11381 * // use `_.runInContext` to avoid conflicts (esp. in Node.js)
11382 * var _ = require('lodash').runInContext();
11383 *
11384 * _.mixin({ 'vowels': vowels });
11385 * _.vowels('fred');
11386 * // => ['e']
11387 *
11388 * _('fred').vowels().value();
11389 * // => ['e']
11390 *
11391 * _.mixin({ 'vowels': vowels }, { 'chain': false });
11392 * _('fred').vowels();
11393 * // => ['e']
11394 */
11395 function mixin(object, source, options) {
11396 if (options == null) {
11397 var isObj = isObject(source),
11398 props = isObj && keys(source),
11399 methodNames = props && props.length && baseFunctions(source, props);
11400
11401 if (!(methodNames ? methodNames.length : isObj)) {
11402 methodNames = false;
11403 options = source;
11404 source = object;
11405 object = this;
11406 }
11407 }
11408 if (!methodNames) {
11409 methodNames = baseFunctions(source, keys(source));
11410 }
11411 var chain = true,
11412 index = -1,
11413 isFunc = isFunction(object),
11414 length = methodNames.length;
11415
11416 if (options === false) {
11417 chain = false;
11418 } else if (isObject(options) && 'chain' in options) {
11419 chain = options.chain;
11420 }
11421 while (++index < length) {
11422 var methodName = methodNames[index],
11423 func = source[methodName];
11424
11425 object[methodName] = func;
11426 if (isFunc) {
11427 object.prototype[methodName] = (function(func) {
11428 return function() {
11429 var chainAll = this.__chain__;
11430 if (chain || chainAll) {
11431 var result = object(this.__wrapped__),
11432 actions = result.__actions__ = arrayCopy(this.__actions__);
11433
11434 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
11435 result.__chain__ = chainAll;
11436 return result;
11437 }
11438 var args = [this.value()];
11439 push.apply(args, arguments);
11440 return func.apply(object, args);
11441 };
11442 }(func));
11443 }
11444 }
11445 return object;
11446 }
11447
11448 /**
11449 * Reverts the `_` variable to its previous value and returns a reference to
11450 * the `lodash` function.
11451 *
11452 * @static
11453 * @memberOf _
11454 * @category Utility
11455 * @returns {Function} Returns the `lodash` function.
11456 * @example
11457 *
11458 * var lodash = _.noConflict();
11459 */
11460 function noConflict() {
11461 context._ = oldDash;
11462 return this;
11463 }
11464
11465 /**
11466 * A no-operation function which returns `undefined` regardless of the
11467 * arguments it receives.
11468 *
11469 * @static
11470 * @memberOf _
11471 * @category Utility
11472 * @example
11473 *
11474 * var object = { 'user': 'fred' };
11475 *
11476 * _.noop(object) === undefined;
11477 * // => true
11478 */
11479 function noop() {
11480 // No operation performed.
11481 }
11482
11483 /**
11484 * Creates a function which returns the property value of `key` on a given object.
11485 *
11486 * @static
11487 * @memberOf _
11488 * @category Utility
11489 * @param {string} key The key of the property to get.
11490 * @returns {Function} Returns the new function.
11491 * @example
11492 *
11493 * var users = [
11494 * { 'user': 'fred' },
11495 * { 'user': 'barney' }
11496 * ];
11497 *
11498 * var getName = _.property('user');
11499 *
11500 * _.map(users, getName);
11501 * // => ['fred', 'barney']
11502 *
11503 * _.pluck(_.sortBy(users, getName), 'user');
11504 * // => ['barney', 'fred']
11505 */
11506 function property(key) {
11507 return baseProperty(key + '');
11508 }
11509
11510 /**
11511 * The opposite of `_.property`; this method creates a function which returns
11512 * the property value of a given key on `object`.
11513 *
11514 * @static
11515 * @memberOf _
11516 * @category Utility
11517 * @param {Object} object The object to inspect.
11518 * @returns {Function} Returns the new function.
11519 * @example
11520 *
11521 * var object = { 'a': 3, 'b': 1, 'c': 2 };
11522 *
11523 * _.map(['a', 'c'], _.propertyOf(object));
11524 * // => [3, 2]
11525 *
11526 * _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
11527 * // => ['b', 'c', 'a']
11528 */
11529 function propertyOf(object) {
11530 return function(key) {
11531 return object == null ? undefined : object[key];
11532 };
11533 }
11534
11535 /**
11536 * Creates an array of numbers (positive and/or negative) progressing from
11537 * `start` up to, but not including, `end`. If `end` is not specified it is
11538 * set to `start` with `start` then set to `0`. If `start` is less than `end`
11539 * a zero-length range is created unless a negative `step` is specified.
11540 *
11541 * @static
11542 * @memberOf _
11543 * @category Utility
11544 * @param {number} [start=0] The start of the range.
11545 * @param {number} end The end of the range.
11546 * @param {number} [step=1] The value to increment or decrement by.
11547 * @returns {Array} Returns the new array of numbers.
11548 * @example
11549 *
11550 * _.range(4);
11551 * // => [0, 1, 2, 3]
11552 *
11553 * _.range(1, 5);
11554 * // => [1, 2, 3, 4]
11555 *
11556 * _.range(0, 20, 5);
11557 * // => [0, 5, 10, 15]
11558 *
11559 * _.range(0, -4, -1);
11560 * // => [0, -1, -2, -3]
11561 *
11562 * _.range(1, 4, 0);
11563 * // => [1, 1, 1]
11564 *
11565 * _.range(0);
11566 * // => []
11567 */
11568 function range(start, end, step) {
11569 if (step && isIterateeCall(start, end, step)) {
11570 end = step = null;
11571 }
11572 start = +start || 0;
11573 step = step == null ? 1 : (+step || 0);
11574
11575 if (end == null) {
11576 end = start;
11577 start = 0;
11578 } else {
11579 end = +end || 0;
11580 }
11581 // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
11582 // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
11583 var index = -1,
11584 length = nativeMax(ceil((end - start) / (step || 1)), 0),
11585 result = Array(length);
11586
11587 while (++index < length) {
11588 result[index] = start;
11589 start += step;
11590 }
11591 return result;
11592 }
11593
11594 /**
11595 * Invokes the iteratee function `n` times, returning an array of the results
11596 * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
11597 * one argument; (index).
11598 *
11599 * @static
11600 * @memberOf _
11601 * @category Utility
11602 * @param {number} n The number of times to invoke `iteratee`.
11603 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
11604 * @param {*} [thisArg] The `this` binding of `iteratee`.
11605 * @returns {Array} Returns the array of results.
11606 * @example
11607 *
11608 * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
11609 * // => [3, 6, 4]
11610 *
11611 * _.times(3, function(n) {
11612 * mage.castSpell(n);
11613 * });
11614 * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively
11615 *
11616 * _.times(3, function(n) {
11617 * this.cast(n);
11618 * }, mage);
11619 * // => also invokes `mage.castSpell(n)` three times
11620 */
11621 function times(n, iteratee, thisArg) {
11622 n = +n;
11623
11624 // Exit early to avoid a JSC JIT bug in Safari 8
11625 // where `Array(0)` is treated as `Array(1)`.
11626 if (n < 1 || !nativeIsFinite(n)) {
11627 return [];
11628 }
11629 var index = -1,
11630 result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
11631
11632 iteratee = bindCallback(iteratee, thisArg, 1);
11633 while (++index < n) {
11634 if (index < MAX_ARRAY_LENGTH) {
11635 result[index] = iteratee(index);
11636 } else {
11637 iteratee(index);
11638 }
11639 }
11640 return result;
11641 }
11642
11643 /**
11644 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
11645 *
11646 * @static
11647 * @memberOf _
11648 * @category Utility
11649 * @param {string} [prefix] The value to prefix the ID with.
11650 * @returns {string} Returns the unique ID.
11651 * @example
11652 *
11653 * _.uniqueId('contact_');
11654 * // => 'contact_104'
11655 *
11656 * _.uniqueId();
11657 * // => '105'
11658 */
11659 function uniqueId(prefix) {
11660 var id = ++idCounter;
11661 return baseToString(prefix) + id;
11662 }
11663
11664 /*------------------------------------------------------------------------*/
11665
11666 /**
11667 * Adds two numbers.
11668 *
11669 * @static
11670 * @memberOf _
11671 * @category Math
11672 * @param {number} augend The first number to add.
11673 * @param {number} addend The second number to add.
11674 * @returns {number} Returns the sum.
11675 * @example
11676 *
11677 * _.add(6, 4);
11678 * // => 10
11679 */
11680 function add(augend, addend) {
11681 return augend + addend;
11682 }
11683
11684 /**
11685 * Gets the maximum value of `collection`. If `collection` is empty or falsey
11686 * `-Infinity` is returned. If an iteratee function is provided it is invoked
11687 * for each value in `collection` to generate the criterion by which the value
11688 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
11689 * arguments: (value, index, collection).
11690 *
11691 * If a property name is provided for `iteratee` the created `_.property`
11692 * style callback returns the property value of the given element.
11693 *
11694 * If a value is also provided for `thisArg` the created `_.matchesProperty`
11695 * style callback returns `true` for elements that have a matching property
11696 * value, else `false`.
11697 *
11698 * If an object is provided for `iteratee` the created `_.matches` style
11699 * callback returns `true` for elements that have the properties of the given
11700 * object, else `false`.
11701 *
11702 * @static
11703 * @memberOf _
11704 * @category Math
11705 * @param {Array|Object|string} collection The collection to iterate over.
11706 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11707 * @param {*} [thisArg] The `this` binding of `iteratee`.
11708 * @returns {*} Returns the maximum value.
11709 * @example
11710 *
11711 * _.max([4, 2, 8, 6]);
11712 * // => 8
11713 *
11714 * _.max([]);
11715 * // => -Infinity
11716 *
11717 * var users = [
11718 * { 'user': 'barney', 'age': 36 },
11719 * { 'user': 'fred', 'age': 40 }
11720 * ];
11721 *
11722 * _.max(users, function(chr) {
11723 * return chr.age;
11724 * });
11725 * // => { 'user': 'fred', 'age': 40 }
11726 *
11727 * // using the `_.property` callback shorthand
11728 * _.max(users, 'age');
11729 * // => { 'user': 'fred', 'age': 40 }
11730 */
11731 var max = createExtremum(arrayMax);
11732
11733 /**
11734 * Gets the minimum value of `collection`. If `collection` is empty or falsey
11735 * `Infinity` is returned. If an iteratee function is provided it is invoked
11736 * for each value in `collection` to generate the criterion by which the value
11737 * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
11738 * arguments: (value, index, collection).
11739 *
11740 * If a property name is provided for `iteratee` the created `_.property`
11741 * style callback returns the property value of the given element.
11742 *
11743 * If a value is also provided for `thisArg` the created `_.matchesProperty`
11744 * style callback returns `true` for elements that have a matching property
11745 * value, else `false`.
11746 *
11747 * If an object is provided for `iteratee` the created `_.matches` style
11748 * callback returns `true` for elements that have the properties of the given
11749 * object, else `false`.
11750 *
11751 * @static
11752 * @memberOf _
11753 * @category Math
11754 * @param {Array|Object|string} collection The collection to iterate over.
11755 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11756 * @param {*} [thisArg] The `this` binding of `iteratee`.
11757 * @returns {*} Returns the minimum value.
11758 * @example
11759 *
11760 * _.min([4, 2, 8, 6]);
11761 * // => 2
11762 *
11763 * _.min([]);
11764 * // => Infinity
11765 *
11766 * var users = [
11767 * { 'user': 'barney', 'age': 36 },
11768 * { 'user': 'fred', 'age': 40 }
11769 * ];
11770 *
11771 * _.min(users, function(chr) {
11772 * return chr.age;
11773 * });
11774 * // => { 'user': 'barney', 'age': 36 }
11775 *
11776 * // using the `_.property` callback shorthand
11777 * _.min(users, 'age');
11778 * // => { 'user': 'barney', 'age': 36 }
11779 */
11780 var min = createExtremum(arrayMin, true);
11781
11782 /**
11783 * Gets the sum of the values in `collection`.
11784 *
11785 * @static
11786 * @memberOf _
11787 * @category Math
11788 * @param {Array|Object|string} collection The collection to iterate over.
11789 * @param {Function|Object|string} [iteratee] The function invoked per iteration.
11790 * @param {*} [thisArg] The `this` binding of `iteratee`.
11791 * @returns {number} Returns the sum.
11792 * @example
11793 *
11794 * _.sum([4, 6]);
11795 * // => 10
11796 *
11797 * _.sum({ 'a': 4, 'b': 6 });
11798 * // => 10
11799 *
11800 * var objects = [
11801 * { 'n': 4 },
11802 * { 'n': 6 }
11803 * ];
11804 *
11805 * _.sum(objects, function(object) {
11806 * return object.n;
11807 * });
11808 * // => 10
11809 *
11810 * // using the `_.property` callback shorthand
11811 * _.sum(objects, 'n');
11812 * // => 10
11813 */
11814 function sum(collection, iteratee, thisArg) {
11815 if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
11816 iteratee = null;
11817 }
11818 var func = getCallback(),
11819 noIteratee = iteratee == null;
11820
11821 if (!(func === baseCallback && noIteratee)) {
11822 noIteratee = false;
11823 iteratee = func(iteratee, thisArg, 3);
11824 }
11825 return noIteratee
11826 ? arraySum(isArray(collection) ? collection : toIterable(collection))
11827 : baseSum(collection, iteratee);
11828 }
11829
11830 /*------------------------------------------------------------------------*/
11831
11832 // Ensure wrappers are instances of `baseLodash`.
11833 lodash.prototype = baseLodash.prototype;
11834
11835 LodashWrapper.prototype = baseCreate(baseLodash.prototype);
11836 LodashWrapper.prototype.constructor = LodashWrapper;
11837
11838 LazyWrapper.prototype = baseCreate(baseLodash.prototype);
11839 LazyWrapper.prototype.constructor = LazyWrapper;
11840
11841 // Add functions to the `Map` cache.
11842 MapCache.prototype['delete'] = mapDelete;
11843 MapCache.prototype.get = mapGet;
11844 MapCache.prototype.has = mapHas;
11845 MapCache.prototype.set = mapSet;
11846
11847 // Add functions to the `Set` cache.
11848 SetCache.prototype.push = cachePush;
11849
11850 // Assign cache to `_.memoize`.
11851 memoize.Cache = MapCache;
11852
11853 // Add functions that return wrapped values when chaining.
11854 lodash.after = after;
11855 lodash.ary = ary;
11856 lodash.assign = assign;
11857 lodash.at = at;
11858 lodash.before = before;
11859 lodash.bind = bind;
11860 lodash.bindAll = bindAll;
11861 lodash.bindKey = bindKey;
11862 lodash.callback = callback;
11863 lodash.chain = chain;
11864 lodash.chunk = chunk;
11865 lodash.compact = compact;
11866 lodash.constant = constant;
11867 lodash.countBy = countBy;
11868 lodash.create = create;
11869 lodash.curry = curry;
11870 lodash.curryRight = curryRight;
11871 lodash.debounce = debounce;
11872 lodash.defaults = defaults;
11873 lodash.defer = defer;
11874 lodash.delay = delay;
11875 lodash.difference = difference;
11876 lodash.drop = drop;
11877 lodash.dropRight = dropRight;
11878 lodash.dropRightWhile = dropRightWhile;
11879 lodash.dropWhile = dropWhile;
11880 lodash.fill = fill;
11881 lodash.filter = filter;
11882 lodash.flatten = flatten;
11883 lodash.flattenDeep = flattenDeep;
11884 lodash.flow = flow;
11885 lodash.flowRight = flowRight;
11886 lodash.forEach = forEach;
11887 lodash.forEachRight = forEachRight;
11888 lodash.forIn = forIn;
11889 lodash.forInRight = forInRight;
11890 lodash.forOwn = forOwn;
11891 lodash.forOwnRight = forOwnRight;
11892 lodash.functions = functions;
11893 lodash.groupBy = groupBy;
11894 lodash.indexBy = indexBy;
11895 lodash.initial = initial;
11896 lodash.intersection = intersection;
11897 lodash.invert = invert;
11898 lodash.invoke = invoke;
11899 lodash.keys = keys;
11900 lodash.keysIn = keysIn;
11901 lodash.map = map;
11902 lodash.mapValues = mapValues;
11903 lodash.matches = matches;
11904 lodash.matchesProperty = matchesProperty;
11905 lodash.memoize = memoize;
11906 lodash.merge = merge;
11907 lodash.mixin = mixin;
11908 lodash.negate = negate;
11909 lodash.omit = omit;
11910 lodash.once = once;
11911 lodash.pairs = pairs;
11912 lodash.partial = partial;
11913 lodash.partialRight = partialRight;
11914 lodash.partition = partition;
11915 lodash.pick = pick;
11916 lodash.pluck = pluck;
11917 lodash.property = property;
11918 lodash.propertyOf = propertyOf;
11919 lodash.pull = pull;
11920 lodash.pullAt = pullAt;
11921 lodash.range = range;
11922 lodash.rearg = rearg;
11923 lodash.reject = reject;
11924 lodash.remove = remove;
11925 lodash.rest = rest;
11926 lodash.restParam = restParam;
11927 lodash.shuffle = shuffle;
11928 lodash.slice = slice;
11929 lodash.sortBy = sortBy;
11930 lodash.sortByAll = sortByAll;
11931 lodash.sortByOrder = sortByOrder;
11932 lodash.spread = spread;
11933 lodash.take = take;
11934 lodash.takeRight = takeRight;
11935 lodash.takeRightWhile = takeRightWhile;
11936 lodash.takeWhile = takeWhile;
11937 lodash.tap = tap;
11938 lodash.throttle = throttle;
11939 lodash.thru = thru;
11940 lodash.times = times;
11941 lodash.toArray = toArray;
11942 lodash.toPlainObject = toPlainObject;
11943 lodash.transform = transform;
11944 lodash.union = union;
11945 lodash.uniq = uniq;
11946 lodash.unzip = unzip;
11947 lodash.values = values;
11948 lodash.valuesIn = valuesIn;
11949 lodash.where = where;
11950 lodash.without = without;
11951 lodash.wrap = wrap;
11952 lodash.xor = xor;
11953 lodash.zip = zip;
11954 lodash.zipObject = zipObject;
11955
11956 // Add aliases.
11957 lodash.backflow = flowRight;
11958 lodash.collect = map;
11959 lodash.compose = flowRight;
11960 lodash.each = forEach;
11961 lodash.eachRight = forEachRight;
11962 lodash.extend = assign;
11963 lodash.iteratee = callback;
11964 lodash.methods = functions;
11965 lodash.object = zipObject;
11966 lodash.select = filter;
11967 lodash.tail = rest;
11968 lodash.unique = uniq;
11969
11970 // Add functions to `lodash.prototype`.
11971 mixin(lodash, lodash);
11972
11973 /*------------------------------------------------------------------------*/
11974
11975 // Add functions that return unwrapped values when chaining.
11976 lodash.add = add;
11977 lodash.attempt = attempt;
11978 lodash.camelCase = camelCase;
11979 lodash.capitalize = capitalize;
11980 lodash.clone = clone;
11981 lodash.cloneDeep = cloneDeep;
11982 lodash.deburr = deburr;
11983 lodash.endsWith = endsWith;
11984 lodash.escape = escape;
11985 lodash.escapeRegExp = escapeRegExp;
11986 lodash.every = every;
11987 lodash.find = find;
11988 lodash.findIndex = findIndex;
11989 lodash.findKey = findKey;
11990 lodash.findLast = findLast;
11991 lodash.findLastIndex = findLastIndex;
11992 lodash.findLastKey = findLastKey;
11993 lodash.findWhere = findWhere;
11994 lodash.first = first;
11995 lodash.has = has;
11996 lodash.identity = identity;
11997 lodash.includes = includes;
11998 lodash.indexOf = indexOf;
11999 lodash.inRange = inRange;
12000 lodash.isArguments = isArguments;
12001 lodash.isArray = isArray;
12002 lodash.isBoolean = isBoolean;
12003 lodash.isDate = isDate;
12004 lodash.isElement = isElement;
12005 lodash.isEmpty = isEmpty;
12006 lodash.isEqual = isEqual;
12007 lodash.isError = isError;
12008 lodash.isFinite = isFinite;
12009 lodash.isFunction = isFunction;
12010 lodash.isMatch = isMatch;
12011 lodash.isNaN = isNaN;
12012 lodash.isNative = isNative;
12013 lodash.isNull = isNull;
12014 lodash.isNumber = isNumber;
12015 lodash.isObject = isObject;
12016 lodash.isPlainObject = isPlainObject;
12017 lodash.isRegExp = isRegExp;
12018 lodash.isString = isString;
12019 lodash.isTypedArray = isTypedArray;
12020 lodash.isUndefined = isUndefined;
12021 lodash.kebabCase = kebabCase;
12022 lodash.last = last;
12023 lodash.lastIndexOf = lastIndexOf;
12024 lodash.max = max;
12025 lodash.min = min;
12026 lodash.noConflict = noConflict;
12027 lodash.noop = noop;
12028 lodash.now = now;
12029 lodash.pad = pad;
12030 lodash.padLeft = padLeft;
12031 lodash.padRight = padRight;
12032 lodash.parseInt = parseInt;
12033 lodash.random = random;
12034 lodash.reduce = reduce;
12035 lodash.reduceRight = reduceRight;
12036 lodash.repeat = repeat;
12037 lodash.result = result;
12038 lodash.runInContext = runInContext;
12039 lodash.size = size;
12040 lodash.snakeCase = snakeCase;
12041 lodash.some = some;
12042 lodash.sortedIndex = sortedIndex;
12043 lodash.sortedLastIndex = sortedLastIndex;
12044 lodash.startCase = startCase;
12045 lodash.startsWith = startsWith;
12046 lodash.sum = sum;
12047 lodash.template = template;
12048 lodash.trim = trim;
12049 lodash.trimLeft = trimLeft;
12050 lodash.trimRight = trimRight;
12051 lodash.trunc = trunc;
12052 lodash.unescape = unescape;
12053 lodash.uniqueId = uniqueId;
12054 lodash.words = words;
12055
12056 // Add aliases.
12057 lodash.all = every;
12058 lodash.any = some;
12059 lodash.contains = includes;
12060 lodash.detect = find;
12061 lodash.foldl = reduce;
12062 lodash.foldr = reduceRight;
12063 lodash.head = first;
12064 lodash.include = includes;
12065 lodash.inject = reduce;
12066
12067 mixin(lodash, (function() {
12068 var source = {};
12069 baseForOwn(lodash, function(func, methodName) {
12070 if (!lodash.prototype[methodName]) {
12071 source[methodName] = func;
12072 }
12073 });
12074 return source;
12075 }()), false);
12076
12077 /*------------------------------------------------------------------------*/
12078
12079 // Add functions capable of returning wrapped and unwrapped values when chaining.
12080 lodash.sample = sample;
12081
12082 lodash.prototype.sample = function(n) {
12083 if (!this.__chain__ && n == null) {
12084 return sample(this.value());
12085 }
12086 return this.thru(function(value) {
12087 return sample(value, n);
12088 });
12089 };
12090
12091 /*------------------------------------------------------------------------*/
12092
12093 /**
12094 * The semantic version number.
12095 *
12096 * @static
12097 * @memberOf _
12098 * @type string
12099 */
12100 lodash.VERSION = VERSION;
12101
12102 // Assign default placeholders.
12103 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
12104 lodash[methodName].placeholder = lodash;
12105 });
12106
12107 // Add `LazyWrapper` methods that accept an `iteratee` value.
12108 arrayEach(['dropWhile', 'filter', 'map', 'takeWhile'], function(methodName, type) {
12109 var isFilter = type != LAZY_MAP_FLAG,
12110 isDropWhile = type == LAZY_DROP_WHILE_FLAG;
12111
12112 LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
12113 var filtered = this.__filtered__,
12114 result = (filtered && isDropWhile) ? new LazyWrapper(this) : this.clone(),
12115 iteratees = result.__iteratees__ || (result.__iteratees__ = []);
12116
12117 iteratees.push({
12118 'done': false,
12119 'count': 0,
12120 'index': 0,
12121 'iteratee': getCallback(iteratee, thisArg, 1),
12122 'limit': -1,
12123 'type': type
12124 });
12125
12126 result.__filtered__ = filtered || isFilter;
12127 return result;
12128 };
12129 });
12130
12131 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
12132 arrayEach(['drop', 'take'], function(methodName, index) {
12133 var whileName = methodName + 'While';
12134
12135 LazyWrapper.prototype[methodName] = function(n) {
12136 var filtered = this.__filtered__,
12137 result = (filtered && !index) ? this.dropWhile() : this.clone();
12138
12139 n = n == null ? 1 : nativeMax(floor(n) || 0, 0);
12140 if (filtered) {
12141 if (index) {
12142 result.__takeCount__ = nativeMin(result.__takeCount__, n);
12143 } else {
12144 last(result.__iteratees__).limit = n;
12145 }
12146 } else {
12147 var views = result.__views__ || (result.__views__ = []);
12148 views.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
12149 }
12150 return result;
12151 };
12152
12153 LazyWrapper.prototype[methodName + 'Right'] = function(n) {
12154 return this.reverse()[methodName](n).reverse();
12155 };
12156
12157 LazyWrapper.prototype[methodName + 'RightWhile'] = function(predicate, thisArg) {
12158 return this.reverse()[whileName](predicate, thisArg).reverse();
12159 };
12160 });
12161
12162 // Add `LazyWrapper` methods for `_.first` and `_.last`.
12163 arrayEach(['first', 'last'], function(methodName, index) {
12164 var takeName = 'take' + (index ? 'Right' : '');
12165
12166 LazyWrapper.prototype[methodName] = function() {
12167 return this[takeName](1).value()[0];
12168 };
12169 });
12170
12171 // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
12172 arrayEach(['initial', 'rest'], function(methodName, index) {
12173 var dropName = 'drop' + (index ? '' : 'Right');
12174
12175 LazyWrapper.prototype[methodName] = function() {
12176 return this[dropName](1);
12177 };
12178 });
12179
12180 // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
12181 arrayEach(['pluck', 'where'], function(methodName, index) {
12182 var operationName = index ? 'filter' : 'map',
12183 createCallback = index ? baseMatches : baseProperty;
12184
12185 LazyWrapper.prototype[methodName] = function(value) {
12186 return this[operationName](createCallback(value));
12187 };
12188 });
12189
12190 LazyWrapper.prototype.compact = function() {
12191 return this.filter(identity);
12192 };
12193
12194 LazyWrapper.prototype.reject = function(predicate, thisArg) {
12195 predicate = getCallback(predicate, thisArg, 1);
12196 return this.filter(function(value) {
12197 return !predicate(value);
12198 });
12199 };
12200
12201 LazyWrapper.prototype.slice = function(start, end) {
12202 start = start == null ? 0 : (+start || 0);
12203 var result = start < 0 ? this.takeRight(-start) : this.drop(start);
12204
12205 if (typeof end != 'undefined') {
12206 end = (+end || 0);
12207 result = end < 0 ? result.dropRight(-end) : result.take(end - start);
12208 }
12209 return result;
12210 };
12211
12212 LazyWrapper.prototype.toArray = function() {
12213 return this.drop(0);
12214 };
12215
12216 // Add `LazyWrapper` methods to `lodash.prototype`.
12217 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
12218 var lodashFunc = lodash[methodName];
12219 if (!lodashFunc) {
12220 return;
12221 }
12222 var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
12223 retUnwrapped = /^(?:first|last)$/.test(methodName);
12224
12225 lodash.prototype[methodName] = function() {
12226 var args = arguments,
12227 length = args.length,
12228 chainAll = this.__chain__,
12229 value = this.__wrapped__,
12230 isHybrid = !!this.__actions__.length,
12231 isLazy = value instanceof LazyWrapper,
12232 iteratee = args[0],
12233 useLazy = isLazy || isArray(value);
12234
12235 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
12236 // avoid lazy use if the iteratee has a `length` other than `1`
12237 isLazy = useLazy = false;
12238 }
12239 var onlyLazy = isLazy && !isHybrid;
12240 if (retUnwrapped && !chainAll) {
12241 return onlyLazy
12242 ? func.call(value)
12243 : lodashFunc.call(lodash, this.value());
12244 }
12245 var interceptor = function(value) {
12246 var otherArgs = [value];
12247 push.apply(otherArgs, args);
12248 return lodashFunc.apply(lodash, otherArgs);
12249 };
12250 if (useLazy) {
12251 var wrapper = onlyLazy ? value : new LazyWrapper(this),
12252 result = func.apply(wrapper, args);
12253
12254 if (!retUnwrapped && (isHybrid || result.__actions__)) {
12255 var actions = result.__actions__ || (result.__actions__ = []);
12256 actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
12257 }
12258 return new LodashWrapper(result, chainAll);
12259 }
12260 return this.thru(interceptor);
12261 };
12262 });
12263
12264 // Add `Array` and `String` methods to `lodash.prototype`.
12265 arrayEach(['concat', 'join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
12266 var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
12267 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
12268 retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
12269
12270 lodash.prototype[methodName] = function() {
12271 var args = arguments;
12272 if (retUnwrapped && !this.__chain__) {
12273 return func.apply(this.value(), args);
12274 }
12275 return this[chainName](function(value) {
12276 return func.apply(value, args);
12277 });
12278 };
12279 });
12280
12281 // Map minified function names to their real names.
12282 baseForOwn(LazyWrapper.prototype, function(func, methodName) {
12283 var lodashFunc = lodash[methodName];
12284 if (lodashFunc) {
12285 var key = lodashFunc.name,
12286 names = realNames[key] || (realNames[key] = []);
12287
12288 names.push({ 'name': methodName, 'func': lodashFunc });
12289 }
12290 });
12291
12292 realNames[createHybridWrapper(null, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': null }];
12293
12294 // Add functions to the lazy wrapper.
12295 LazyWrapper.prototype.clone = lazyClone;
12296 LazyWrapper.prototype.reverse = lazyReverse;
12297 LazyWrapper.prototype.value = lazyValue;
12298
12299 // Add chaining functions to the `lodash` wrapper.
12300 lodash.prototype.chain = wrapperChain;
12301 lodash.prototype.commit = wrapperCommit;
12302 lodash.prototype.plant = wrapperPlant;
12303 lodash.prototype.reverse = wrapperReverse;
12304 lodash.prototype.toString = wrapperToString;
12305 lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
12306
12307 // Add function aliases to the `lodash` wrapper.
12308 lodash.prototype.collect = lodash.prototype.map;
12309 lodash.prototype.head = lodash.prototype.first;
12310 lodash.prototype.select = lodash.prototype.filter;
12311 lodash.prototype.tail = lodash.prototype.rest;
12312
12313 return lodash;
12314 }
12315
12316 /*--------------------------------------------------------------------------*/
12317
12318 // Export lodash.
12319 var _ = runInContext();
12320
12321 // Some AMD build optimizers like r.js check for condition patterns like the following:
12322 if (true) {
12323 // Expose lodash to the global object when an AMD loader is present to avoid
12324 // errors in cases where lodash is loaded by a script tag and not intended
12325 // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
12326 // more details.
12327 root._ = _;
12328
12329 // Define as an anonymous module so, through path mapping, it can be
12330 // referenced as the "underscore" module.
12331 !(__WEBPACK_AMD_DEFINE_RESULT__ = function() {
12332 return _;
12333 }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
12334 }
12335 // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
12336 else if (freeExports && freeModule) {
12337 // Export for Node.js or RingoJS.
12338 if (moduleExports) {
12339 (freeModule.exports = _)._ = _;
12340 }
12341 // Export for Narwhal or Rhino -require.
12342 else {
12343 freeExports._ = _;
12344 }
12345 }
12346 else {
12347 // Export for a browser or Rhino.
12348 root._ = _;
12349 }
12350 }.call(this));
12351
12352 /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(11)(module), (function() { return this; }())))
12353
12354/***/ },
12355/* 9 */
12356/***/ function(module, exports, __webpack_require__) {
12357
12358 /* WEBPACK VAR INJECTION */(function(global) {(function checkMoreTypes(check) {
12359 'use strict';
12360
12361 /**
12362 Custom assertions and predicates for https://github.com/philbooth/check-types.js
12363 Created by Kensho https://github.com/kensho
12364 Copyright @ 2014 Kensho https://www.kensho.com/
12365 License: MIT
12366
12367 @module check
12368 */
12369
12370 if (!check) {
12371 if (false) {
12372 throw new Error('Cannot find check-types library, has it been loaded?');
12373 }
12374 check = __webpack_require__(12);
12375 }
12376
12377 /**
12378 Checks if argument is defined or not
12379
12380 This method now is part of the check-types.js
12381 @method defined
12382 */
12383 function defined(value) {
12384 return typeof value !== 'undefined';
12385 }
12386
12387 /**
12388 same as ===
12389
12390 @method same
12391 */
12392 function same(a, b) {
12393 return a === b;
12394 }
12395
12396 /**
12397 Returns true if the index is valid for give string / array
12398
12399 @method index
12400 */
12401 function index(list, k) {
12402 return defined(list) &&
12403 has(list, 'length') &&
12404 k >= 0 &&
12405 k < list.length;
12406 }
12407
12408 /**
12409 Returns true if both objects are the same type and have same length property
12410
12411 @method sameLength
12412 */
12413 function sameLength(a, b) {
12414 return typeof a === typeof b &&
12415 a && b &&
12416 a.length === b.length;
12417 }
12418
12419 /**
12420 Returns true if all items in an array are the same reference
12421
12422 @method allSame
12423 */
12424 function allSame(arr) {
12425 if (!check.array(arr)) {
12426 return false;
12427 }
12428 if (!arr.length) {
12429 return true;
12430 }
12431 var first = arr[0];
12432 return arr.every(function (item) {
12433 return item === first;
12434 });
12435 }
12436
12437 /**
12438 Returns true if given item is in the array
12439
12440 @method oneOf
12441 */
12442 function oneOf(arr, x) {
12443 check.verify.array(arr, 'expected an array');
12444 return arr.indexOf(x) !== -1;
12445 }
12446
12447 /**
12448 Returns true for urls of the format `git@....git`
12449
12450 @method git
12451 */
12452 function git(url) {
12453 return check.unemptyString(url) &&
12454 /^git@/.test(url);
12455 }
12456
12457 /**
12458 Checks if given value is 0 or 1
12459
12460 @method bit
12461 */
12462 function bit(value) {
12463 return value === 0 || value === 1;
12464 }
12465
12466 /**
12467 Checks if given value is true of false
12468
12469 @method bool
12470 */
12471 function bool(value) {
12472 return typeof value === 'boolean';
12473 }
12474
12475 /**
12476 Checks if given object has a property
12477 @method has
12478 */
12479 function has(o, property) {
12480 return Boolean(o && property &&
12481 typeof property === 'string' &&
12482 typeof o[property] !== 'undefined');
12483 }
12484
12485 /**
12486 Checks if given string is already in lower case
12487 @method lowerCase
12488 */
12489 function lowerCase(str) {
12490 return check.string(str) &&
12491 str.toLowerCase() === str;
12492 }
12493
12494 /**
12495 Returns true if the argument is an array with at least one value
12496 @method unemptyArray
12497 */
12498 function unemptyArray(a) {
12499 return check.array(a) && a.length > 0;
12500 }
12501
12502 /**
12503 Returns true if each item in the array passes the predicate
12504 @method arrayOf
12505 @param rule Predicate function
12506 @param a Array to check
12507 */
12508 function arrayOf(rule, a) {
12509 return check.array(a) && a.every(rule);
12510 }
12511
12512 /**
12513 Returns items from array that do not passes the predicate
12514 @method badItems
12515 @param rule Predicate function
12516 @param a Array with items
12517 */
12518 function badItems(rule, a) {
12519 check.verify.array(a, 'expected array to find bad items');
12520 return a.filter(notModifier(rule));
12521 }
12522
12523 /**
12524 Returns true if given array only has strings
12525 @method arrayOfStrings
12526 @param a Array to check
12527 @param checkLowerCase Checks if all strings are lowercase
12528 */
12529 function arrayOfStrings(a, checkLowerCase) {
12530 var v = check.array(a) && a.every(check.string);
12531 if (v && check.bool(checkLowerCase) && checkLowerCase) {
12532 return a.every(check.lowerCase);
12533 }
12534 return v;
12535 }
12536
12537 /**
12538 Returns true if given argument is array of arrays of strings
12539 @method arrayOfArraysOfStrings
12540 @param a Array to check
12541 @param checkLowerCase Checks if all strings are lowercase
12542 */
12543 function arrayOfArraysOfStrings(a, checkLowerCase) {
12544 return check.array(a) && a.every(function (arr) {
12545 return check.arrayOfStrings(arr, checkLowerCase);
12546 });
12547 }
12548
12549 /**
12550 Checks if object passes all rules in predicates.
12551
12552 check.all({ foo: 'foo' }, { foo: check.string }, 'wrong object');
12553
12554 This is a composition of check.every(check.map ...) calls
12555 https://github.com/philbooth/check-types.js#batch-operations
12556
12557 @method all
12558 @param {object} object object to check
12559 @param {object} predicates rules to check. Usually one per property.
12560 @public
12561 @returns true or false
12562 */
12563 function all(obj, predicates) {
12564 check.verify.object(obj, 'missing object to check');
12565 check.verify.object(predicates, 'missing predicates object');
12566 Object.keys(predicates).forEach(function (property) {
12567 check.verify.fn(predicates[property], 'not a predicate function for ' + property);
12568 });
12569 return check.every(check.map(obj, predicates));
12570 }
12571
12572 /**
12573 Checks given object against predicates object
12574 @method schema
12575 */
12576 function schema(predicates, obj) {
12577 return all(obj, predicates);
12578 }
12579
12580 /** Checks if given function raises an error
12581
12582 @method raises
12583 */
12584 function raises(fn, errorValidator) {
12585 check.verify.fn(fn, 'expected function that raises');
12586 try {
12587 fn();
12588 } catch (err) {
12589 if (typeof errorValidator === 'undefined') {
12590 return true;
12591 }
12592 if (typeof errorValidator === 'function') {
12593 return errorValidator(err);
12594 }
12595 return false;
12596 }
12597 // error has not been raised
12598 return false;
12599 }
12600
12601 /**
12602 Returns true if given value is ''
12603 @method emptyString
12604 */
12605 function emptyString(a) {
12606 return a === '';
12607 }
12608
12609 /**
12610 Returns true if given value is [], {} or ''
12611 @method empty
12612 */
12613 function empty(a) {
12614 var hasLength = typeof a === 'string' ||
12615 Array.isArray(a);
12616 if (hasLength) {
12617 return !a.length;
12618 }
12619 if (a instanceof Object) {
12620 return !Object.keys(a).length;
12621 }
12622 return false;
12623 }
12624
12625 /**
12626 Returns true if given value has .length and it is not zero, or has properties
12627 @method unempty
12628 */
12629 function unempty(a) {
12630 var hasLength = typeof a === 'string' ||
12631 Array.isArray(a);
12632 if (hasLength) {
12633 return a.length;
12634 }
12635 if (a instanceof Object) {
12636 return Object.keys(a).length;
12637 }
12638 return true;
12639 }
12640
12641 /**
12642 Returns true if 0 <= value <= 1
12643 @method unit
12644 */
12645 function unit(value) {
12646 return check.number(value) &&
12647 value >= 0.0 && value <= 1.0;
12648 }
12649
12650 var rgb = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
12651 /**
12652 Returns true if value is hex RGB between '#000000' and '#FFFFFF'
12653 @method hexRgb
12654 */
12655 function hexRgb(value) {
12656 return check.string(value) &&
12657 rgb.test(value);
12658 }
12659
12660 // typical git SHA commit id is 40 digit hex string, like
12661 // 3b819803cdf2225ca1338beb17e0c506fdeedefc
12662 var shaReg = /^[0-9a-f]{40}$/;
12663
12664 /**
12665 Returns true if the given string is 40 digit SHA commit id
12666 @method commitId
12667 */
12668 function commitId(id) {
12669 return check.string(id) &&
12670 id.length === 40 &&
12671 shaReg.test(id);
12672 }
12673
12674 // when using git log --oneline short ids are displayed, first 7 characters
12675 var shortShaReg = /^[0-9a-f]{7}$/;
12676
12677 /**
12678 Returns true if the given string is short 7 character SHA id part
12679 @method shortCommitId
12680 */
12681 function shortCommitId(id) {
12682 return check.string(id) &&
12683 id.length === 7 &&
12684 shortShaReg.test(id);
12685 }
12686
12687 //
12688 // helper methods
12689 //
12690
12691 if (!check.defend) {
12692 var checkPredicates = function checksPredicates(fn, predicates, args) {
12693 check.verify.fn(fn, 'expected a function');
12694 check.verify.array(predicates, 'expected list of predicates');
12695 check.verify.defined(args, 'missing args');
12696
12697 var k = 0, // iterates over predicates
12698 j = 0, // iterates over arguments
12699 n = predicates.length;
12700
12701 for (k = 0; k < n; k += 1) {
12702 var predicate = predicates[k];
12703 if (!check.fn(predicate)) {
12704 continue;
12705 }
12706
12707 if (!predicate.call(null, args[j])) {
12708 var msg = 'Argument ' + (j + 1) + ': ' + args[j] + ' does not pass predicate';
12709 if (check.unemptyString(predicates[k + 1])) {
12710 msg += ': ' + predicates[k + 1];
12711 }
12712 throw new Error(msg);
12713 }
12714
12715 j += 1;
12716 }
12717 return fn.apply(null, args);
12718 };
12719
12720 check.defend = function defend(fn) {
12721 var predicates = Array.prototype.slice.call(arguments, 1);
12722 return function () {
12723 return checkPredicates(fn, predicates, arguments);
12724 };
12725 };
12726 }
12727
12728 /**
12729 * Public modifier `not`.
12730 *
12731 * Negates `predicate`.
12732 * copied from check-types.js
12733 */
12734 function notModifier(predicate) {
12735 return function () {
12736 return !predicate.apply(null, arguments);
12737 };
12738 }
12739
12740 if (!check.mixin) {
12741 /** Adds new predicate to all objects
12742 @method mixin */
12743 check.mixin = function mixin(fn, name) {
12744 check.verify.fn(fn, 'expected predicate function');
12745 if (!check.unemptyString(name)) {
12746 name = fn.name;
12747 }
12748 check.verify.unemptyString(name, 'predicate function missing name\n' + fn.toString());
12749
12750 function registerPredicate(obj, name, fn) {
12751 check.verify.object(obj, 'missing object');
12752 check.verify.unemptyString(name, 'missing name');
12753 check.verify.fn(fn, 'missing function');
12754
12755 if (!obj[name]) {
12756 obj[name] = fn;
12757 }
12758 }
12759
12760 /**
12761 * Public modifier `maybe`.
12762 *
12763 * Returns `true` if `predicate` is `null` or `undefined`,
12764 * otherwise propagates the return value from `predicate`.
12765 * copied from check-types.js
12766 */
12767 function maybeModifier(predicate) {
12768 return function () {
12769 if (!check.defined(arguments[0]) || check.nulled(arguments[0])) {
12770 return true;
12771 }
12772 return predicate.apply(null, arguments);
12773 };
12774 }
12775
12776 /**
12777 * Public modifier `verify`.
12778 *
12779 * Throws if `predicate` returns `false`.
12780 * copied from check-types.js
12781 */
12782 function verifyModifier(predicate, defaultMessage) {
12783 return function () {
12784 var message;
12785 if (predicate.apply(null, arguments) === false) {
12786 message = arguments[arguments.length - 1];
12787 throw new Error(check.unemptyString(message) ? message : defaultMessage);
12788 }
12789 };
12790 }
12791
12792 registerPredicate(check, name, fn);
12793 registerPredicate(check.maybe, name, maybeModifier(fn));
12794 registerPredicate(check.not, name, notModifier(fn));
12795 registerPredicate(check.verify, name, verifyModifier(fn, name + ' failed'));
12796 };
12797 }
12798
12799 if (!check.then) {
12800 /**
12801 Executes given function only if condition is truthy.
12802 @method then
12803 */
12804 check.then = function then(condition, fn) {
12805 return function () {
12806 var ok = typeof condition === 'function' ?
12807 condition.apply(null, arguments) : condition;
12808 if (ok) {
12809 return fn.apply(null, arguments);
12810 }
12811 };
12812 };
12813 }
12814
12815 var promiseSchema = {
12816 then: check.fn
12817 };
12818
12819 // work around reserved keywords checks
12820 promiseSchema['catch'] = check.fn;
12821 promiseSchema['finally'] = check.fn;
12822
12823 var hasPromiseApi = schema.bind(null, promiseSchema);
12824
12825 /**
12826 Returns true if argument implements promise api (.then, .catch, .finally)
12827 @method promise
12828 */
12829 function isPromise(p) {
12830 return typeof p === 'object' &&
12831 hasPromiseApi(p);
12832 }
12833
12834 // new predicates to be added to check object. Use object to preserve names
12835 var predicates = {
12836 defined: defined,
12837 same: same,
12838 allSame: allSame,
12839 bit: bit,
12840 bool: bool,
12841 has: has,
12842 lowerCase: lowerCase,
12843 unemptyArray: unemptyArray,
12844 arrayOfStrings: arrayOfStrings,
12845 arrayOfArraysOfStrings: arrayOfArraysOfStrings,
12846 all: all,
12847 schema: schema,
12848 raises: raises,
12849 empty: empty,
12850 emptyString: emptyString,
12851 unempty: unempty,
12852 unit: unit,
12853 hexRgb: hexRgb,
12854 sameLength: sameLength,
12855 commitId: commitId,
12856 shortCommitId: shortCommitId,
12857 index: index,
12858 git: git,
12859 arrayOf: arrayOf,
12860 badItems: badItems,
12861 oneOf: oneOf,
12862 promise: isPromise
12863 };
12864
12865 Object.keys(predicates).forEach(function (name) {
12866 check.mixin(predicates[name], name);
12867 });
12868
12869 if (true) {
12870 module.exports = check;
12871 }
12872 }(typeof window === 'object' ? window.check : global.check));
12873
12874 /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
12875
12876/***/ },
12877/* 10 */
12878/***/ function(module, exports, __webpack_require__) {
12879
12880 // Ramda v0.14.0
12881 // https://github.com/ramda/ramda
12882 // (c) 2013-2015 Scott Sauyet, Michael Hurley, and David Chambers
12883 // Ramda may be freely distributed under the MIT license.
12884
12885 ;(function() {
12886
12887 'use strict';
12888
12889 /**
12890 * A special placeholder value used to specify "gaps" within curried functions,
12891 * allowing partial application of any combination of arguments,
12892 * regardless of their positions.
12893 *
12894 * If `g` is a curried ternary function and `_` is `R.__`, the following are equivalent:
12895 *
12896 * - `g(1, 2, 3)`
12897 * - `g(_, 2, 3)(1)`
12898 * - `g(_, _, 3)(1)(2)`
12899 * - `g(_, _, 3)(1, 2)`
12900 * - `g(_, 2, _)(1, 3)`
12901 * - `g(_, 2)(1)(3)`
12902 * - `g(_, 2)(1, 3)`
12903 * - `g(_, 2)(_, 3)(1)`
12904 *
12905 * @constant
12906 * @memberOf R
12907 * @category Function
12908 * @example
12909 *
12910 * var greet = R.replace('{name}', R.__, 'Hello, {name}!');
12911 * greet('Alice'); //=> 'Hello, Alice!'
12912 */
12913 var __ = { ramda: 'placeholder' };
12914
12915 var _add = function _add(a, b) {
12916 return a + b;
12917 };
12918
12919 var _all = function _all(fn, list) {
12920 var idx = -1;
12921 while (++idx < list.length) {
12922 if (!fn(list[idx])) {
12923 return false;
12924 }
12925 }
12926 return true;
12927 };
12928
12929 var _any = function _any(fn, list) {
12930 var idx = -1;
12931 while (++idx < list.length) {
12932 if (fn(list[idx])) {
12933 return true;
12934 }
12935 }
12936 return false;
12937 };
12938
12939 var _assoc = function _assoc(prop, val, obj) {
12940 var result = {};
12941 for (var p in obj) {
12942 result[p] = obj[p];
12943 }
12944 result[prop] = val;
12945 return result;
12946 };
12947
12948 var _cloneRegExp = function _cloneRegExp(pattern) {
12949 return new RegExp(pattern.source, (pattern.global ? 'g' : '') + (pattern.ignoreCase ? 'i' : '') + (pattern.multiline ? 'm' : '') + (pattern.sticky ? 'y' : '') + (pattern.unicode ? 'u' : ''));
12950 };
12951
12952 var _complement = function _complement(f) {
12953 return function () {
12954 return !f.apply(this, arguments);
12955 };
12956 };
12957
12958 /**
12959 * Basic, right-associative composition function. Accepts two functions and returns the
12960 * composite function; this composite function represents the operation `var h = f(g(x))`,
12961 * where `f` is the first argument, `g` is the second argument, and `x` is whatever
12962 * argument(s) are passed to `h`.
12963 *
12964 * This function's main use is to build the more general `compose` function, which accepts
12965 * any number of functions.
12966 *
12967 * @private
12968 * @category Function
12969 * @param {Function} f A function.
12970 * @param {Function} g A function.
12971 * @return {Function} A new function that is the equivalent of `f(g(x))`.
12972 * @example
12973 *
12974 * var double = function(x) { return x * 2; };
12975 * var square = function(x) { return x * x; };
12976 * var squareThenDouble = _compose(double, square);
12977 *
12978 * squareThenDouble(5); //≅ double(square(5)) => 50
12979 */
12980 var _compose = function _compose(f, g) {
12981 return function () {
12982 return f.call(this, g.apply(this, arguments));
12983 };
12984 };
12985
12986 /**
12987 * Private `concat` function to merge two array-like objects.
12988 *
12989 * @private
12990 * @param {Array|Arguments} [set1=[]] An array-like object.
12991 * @param {Array|Arguments} [set2=[]] An array-like object.
12992 * @return {Array} A new, merged array.
12993 * @example
12994 *
12995 * _concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
12996 */
12997 var _concat = function _concat(set1, set2) {
12998 set1 = set1 || [];
12999 set2 = set2 || [];
13000 var idx;
13001 var len1 = set1.length;
13002 var len2 = set2.length;
13003 var result = [];
13004 idx = -1;
13005 while (++idx < len1) {
13006 result[result.length] = set1[idx];
13007 }
13008 idx = -1;
13009 while (++idx < len2) {
13010 result[result.length] = set2[idx];
13011 }
13012 return result;
13013 };
13014
13015 var _containsWith = function _containsWith(pred, x, list) {
13016 var idx = -1, len = list.length;
13017 while (++idx < len) {
13018 if (pred(x, list[idx])) {
13019 return true;
13020 }
13021 }
13022 return false;
13023 };
13024
13025 var _createMapEntry = function _createMapEntry(key, val) {
13026 var obj = {};
13027 obj[key] = val;
13028 return obj;
13029 };
13030
13031 /**
13032 * Create a function which takes a comparator function and a list
13033 * and determines the winning value by a compatator. Used internally
13034 * by `R.maxBy` and `R.minBy`
13035 *
13036 * @private
13037 * @param {Function} compatator a function to compare two items
13038 * @category Math
13039 * @return {Function}
13040 */
13041 var _createMaxMinBy = function _createMaxMinBy(comparator) {
13042 return function (valueComputer, list) {
13043 if (!(list && list.length > 0)) {
13044 return;
13045 }
13046 var idx = 0;
13047 var winner = list[idx];
13048 var computedWinner = valueComputer(winner);
13049 var computedCurrent;
13050 while (++idx < list.length) {
13051 computedCurrent = valueComputer(list[idx]);
13052 if (comparator(computedCurrent, computedWinner)) {
13053 computedWinner = computedCurrent;
13054 winner = list[idx];
13055 }
13056 }
13057 return winner;
13058 };
13059 };
13060
13061 /**
13062 * Optimized internal two-arity curry function.
13063 *
13064 * @private
13065 * @category Function
13066 * @param {Function} fn The function to curry.
13067 * @return {Function} The curried function.
13068 */
13069 var _curry1 = function _curry1(fn) {
13070 return function f1(a) {
13071 if (arguments.length === 0) {
13072 return f1;
13073 } else if (a === __) {
13074 return f1;
13075 } else {
13076 return fn(a);
13077 }
13078 };
13079 };
13080
13081 /**
13082 * Optimized internal two-arity curry function.
13083 *
13084 * @private
13085 * @category Function
13086 * @param {Function} fn The function to curry.
13087 * @return {Function} The curried function.
13088 */
13089 var _curry2 = function _curry2(fn) {
13090 return function f2(a, b) {
13091 var n = arguments.length;
13092 if (n === 0) {
13093 return f2;
13094 } else if (n === 1 && a === __) {
13095 return f2;
13096 } else if (n === 1) {
13097 return _curry1(function (b) {
13098 return fn(a, b);
13099 });
13100 } else if (n === 2 && a === __ && b === __) {
13101 return f2;
13102 } else if (n === 2 && a === __) {
13103 return _curry1(function (a) {
13104 return fn(a, b);
13105 });
13106 } else if (n === 2 && b === __) {
13107 return _curry1(function (b) {
13108 return fn(a, b);
13109 });
13110 } else {
13111 return fn(a, b);
13112 }
13113 };
13114 };
13115
13116 /**
13117 * Optimized internal three-arity curry function.
13118 *
13119 * @private
13120 * @category Function
13121 * @param {Function} fn The function to curry.
13122 * @return {Function} The curried function.
13123 */
13124 var _curry3 = function _curry3(fn) {
13125 return function f3(a, b, c) {
13126 var n = arguments.length;
13127 if (n === 0) {
13128 return f3;
13129 } else if (n === 1 && a === __) {
13130 return f3;
13131 } else if (n === 1) {
13132 return _curry2(function (b, c) {
13133 return fn(a, b, c);
13134 });
13135 } else if (n === 2 && a === __ && b === __) {
13136 return f3;
13137 } else if (n === 2 && a === __) {
13138 return _curry2(function (a, c) {
13139 return fn(a, b, c);
13140 });
13141 } else if (n === 2 && b === __) {
13142 return _curry2(function (b, c) {
13143 return fn(a, b, c);
13144 });
13145 } else if (n === 2) {
13146 return _curry1(function (c) {
13147 return fn(a, b, c);
13148 });
13149 } else if (n === 3 && a === __ && b === __ && c === __) {
13150 return f3;
13151 } else if (n === 3 && a === __ && b === __) {
13152 return _curry2(function (a, b) {
13153 return fn(a, b, c);
13154 });
13155 } else if (n === 3 && a === __ && c === __) {
13156 return _curry2(function (a, c) {
13157 return fn(a, b, c);
13158 });
13159 } else if (n === 3 && b === __ && c === __) {
13160 return _curry2(function (b, c) {
13161 return fn(a, b, c);
13162 });
13163 } else if (n === 3 && a === __) {
13164 return _curry1(function (a) {
13165 return fn(a, b, c);
13166 });
13167 } else if (n === 3 && b === __) {
13168 return _curry1(function (b) {
13169 return fn(a, b, c);
13170 });
13171 } else if (n === 3 && c === __) {
13172 return _curry1(function (c) {
13173 return fn(a, b, c);
13174 });
13175 } else {
13176 return fn(a, b, c);
13177 }
13178 };
13179 };
13180
13181 var _dissoc = function _dissoc(prop, obj) {
13182 var result = {};
13183 for (var p in obj) {
13184 if (p !== prop) {
13185 result[p] = obj[p];
13186 }
13187 }
13188 return result;
13189 };
13190
13191 var _eq = function _eq(a, b) {
13192 if (a === 0) {
13193 return 1 / a === 1 / b;
13194 } else {
13195 return a === b || a !== a && b !== b;
13196 }
13197 };
13198
13199 var _filter = function _filter(fn, list) {
13200 var idx = -1, len = list.length, result = [];
13201 while (++idx < len) {
13202 if (fn(list[idx])) {
13203 result[result.length] = list[idx];
13204 }
13205 }
13206 return result;
13207 };
13208
13209 var _filterIndexed = function _filterIndexed(fn, list) {
13210 var idx = -1, len = list.length, result = [];
13211 while (++idx < len) {
13212 if (fn(list[idx], idx, list)) {
13213 result[result.length] = list[idx];
13214 }
13215 }
13216 return result;
13217 };
13218
13219 // i can't bear not to return *something*
13220 var _forEach = function _forEach(fn, list) {
13221 var idx = -1, len = list.length;
13222 while (++idx < len) {
13223 fn(list[idx]);
13224 }
13225 // i can't bear not to return *something*
13226 return list;
13227 };
13228
13229 /**
13230 * @private
13231 * @param {Function} fn The strategy for extracting function names from an object
13232 * @return {Function} A function that takes an object and returns an array of function names.
13233 */
13234 var _functionsWith = function _functionsWith(fn) {
13235 return function (obj) {
13236 return _filter(function (key) {
13237 return typeof obj[key] === 'function';
13238 }, fn(obj));
13239 };
13240 };
13241
13242 var _gt = function _gt(a, b) {
13243 return a > b;
13244 };
13245
13246 var _has = function _has(prop, obj) {
13247 return Object.prototype.hasOwnProperty.call(obj, prop);
13248 };
13249
13250 var _identity = function _identity(x) {
13251 return x;
13252 };
13253
13254 var _indexOf = function _indexOf(list, item, from) {
13255 var idx = 0, len = list.length;
13256 if (typeof from == 'number') {
13257 idx = from < 0 ? Math.max(0, len + from) : from;
13258 }
13259 while (idx < len) {
13260 if (_eq(list[idx], item)) {
13261 return idx;
13262 }
13263 ++idx;
13264 }
13265 return -1;
13266 };
13267
13268 /**
13269 * Tests whether or not an object is an array.
13270 *
13271 * @private
13272 * @param {*} val The object to test.
13273 * @return {Boolean} `true` if `val` is an array, `false` otherwise.
13274 * @example
13275 *
13276 * _isArray([]); //=> true
13277 * _isArray(null); //=> false
13278 * _isArray({}); //=> false
13279 */
13280 var _isArray = Array.isArray || function _isArray(val) {
13281 return val != null && val.length >= 0 && Object.prototype.toString.call(val) === '[object Array]';
13282 };
13283
13284 /**
13285 * Determine if the passed argument is an integer.
13286 *
13287 * @private
13288 * @param {*} n
13289 * @category Type
13290 * @return {Boolean}
13291 */
13292 var _isInteger = Number.isInteger || function _isInteger(n) {
13293 return n << 0 === n;
13294 };
13295
13296 /**
13297 * Tests if a value is a thenable (promise).
13298 */
13299 var _isThenable = function _isThenable(value) {
13300 return value != null && value === Object(value) && typeof value.then === 'function';
13301 };
13302
13303 var _isTransformer = function _isTransformer(obj) {
13304 return typeof obj['@@transducer/step'] === 'function';
13305 };
13306
13307 var _lastIndexOf = function _lastIndexOf(list, item, from) {
13308 var idx = list.length;
13309 if (typeof from == 'number') {
13310 idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1);
13311 }
13312 while (--idx >= 0) {
13313 if (_eq(list[idx], item)) {
13314 return idx;
13315 }
13316 }
13317 return -1;
13318 };
13319
13320 var _lt = function _lt(a, b) {
13321 return a < b;
13322 };
13323
13324 var _map = function _map(fn, list) {
13325 var idx = -1, len = list.length, result = [];
13326 while (++idx < len) {
13327 result[idx] = fn(list[idx]);
13328 }
13329 return result;
13330 };
13331
13332 var _multiply = function _multiply(a, b) {
13333 return a * b;
13334 };
13335
13336 var _nth = function _nth(n, list) {
13337 return n < 0 ? list[list.length + n] : list[n];
13338 };
13339
13340 /**
13341 * internal path function
13342 * Takes an array, paths, indicating the deep set of keys
13343 * to find.
13344 *
13345 * @private
13346 * @memberOf R
13347 * @category Object
13348 * @param {Array} paths An array of strings to map to object properties
13349 * @param {Object} obj The object to find the path in
13350 * @return {Array} The value at the end of the path or `undefined`.
13351 * @example
13352 *
13353 * _path(['a', 'b'], {a: {b: 2}}); //=> 2
13354 */
13355 var _path = function _path(paths, obj) {
13356 if (obj == null) {
13357 return;
13358 } else {
13359 var val = obj;
13360 for (var idx = 0, len = paths.length; idx < len && val != null; idx += 1) {
13361 val = val[paths[idx]];
13362 }
13363 return val;
13364 }
13365 };
13366
13367 var _prepend = function _prepend(el, list) {
13368 return _concat([el], list);
13369 };
13370
13371 var _quote = function _quote(s) {
13372 return '"' + s.replace(/"/g, '\\"') + '"';
13373 };
13374
13375 var _reduced = function (x) {
13376 return x && x['@@transducer/reduced'] ? x : {
13377 '@@transducer/value': x,
13378 '@@transducer/reduced': true
13379 };
13380 };
13381
13382 /**
13383 * An optimized, private array `slice` implementation.
13384 *
13385 * @private
13386 * @param {Arguments|Array} args The array or arguments object to consider.
13387 * @param {Number} [from=0] The array index to slice from, inclusive.
13388 * @param {Number} [to=args.length] The array index to slice to, exclusive.
13389 * @return {Array} A new, sliced array.
13390 * @example
13391 *
13392 * _slice([1, 2, 3, 4, 5], 1, 3); //=> [2, 3]
13393 *
13394 * var firstThreeArgs = function(a, b, c, d) {
13395 * return _slice(arguments, 0, 3);
13396 * };
13397 * firstThreeArgs(1, 2, 3, 4); //=> [1, 2, 3]
13398 */
13399 var _slice = function _slice(args, from, to) {
13400 switch (arguments.length) {
13401 case 1:
13402 return _slice(args, 0, args.length);
13403 case 2:
13404 return _slice(args, from, args.length);
13405 default:
13406 var list = [];
13407 var idx = -1;
13408 var len = Math.max(0, Math.min(args.length, to) - from);
13409 while (++idx < len) {
13410 list[idx] = args[from + idx];
13411 }
13412 return list;
13413 }
13414 };
13415
13416 /**
13417 * Polyfill from <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString>.
13418 */
13419 var _toISOString = function () {
13420 var pad = function pad(n) {
13421 return (n < 10 ? '0' : '') + n;
13422 };
13423 return typeof Date.prototype.toISOString === 'function' ? function _toISOString(d) {
13424 return d.toISOString();
13425 } : function _toISOString(d) {
13426 return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) + '-' + pad(d.getUTCDate()) + 'T' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()) + '.' + (d.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + 'Z';
13427 };
13428 }();
13429
13430 var _xdropRepeatsWith = function () {
13431 function XDropRepeatsWith(pred, xf) {
13432 this.xf = xf;
13433 this.pred = pred;
13434 this.lastValue = undefined;
13435 this.seenFirstValue = false;
13436 }
13437 XDropRepeatsWith.prototype['@@transducer/init'] = function () {
13438 return this.xf['@@transducer/init']();
13439 };
13440 XDropRepeatsWith.prototype['@@transducer/result'] = function (result) {
13441 return this.xf['@@transducer/result'](result);
13442 };
13443 XDropRepeatsWith.prototype['@@transducer/step'] = function (result, input) {
13444 var sameAsLast = false;
13445 if (!this.seenFirstValue) {
13446 this.seenFirstValue = true;
13447 } else if (this.pred(this.lastValue, input)) {
13448 sameAsLast = true;
13449 }
13450 this.lastValue = input;
13451 return sameAsLast ? result : this.xf['@@transducer/step'](result, input);
13452 };
13453 return _curry2(function _xdropRepeatsWith(pred, xf) {
13454 return new XDropRepeatsWith(pred, xf);
13455 });
13456 }();
13457
13458 var _xfBase = {
13459 init: function () {
13460 return this.xf['@@transducer/init']();
13461 },
13462 result: function (result) {
13463 return this.xf['@@transducer/result'](result);
13464 }
13465 };
13466
13467 var _xfilter = function () {
13468 function XFilter(f, xf) {
13469 this.xf = xf;
13470 this.f = f;
13471 }
13472 XFilter.prototype['@@transducer/init'] = _xfBase.init;
13473 XFilter.prototype['@@transducer/result'] = _xfBase.result;
13474 XFilter.prototype['@@transducer/step'] = function (result, input) {
13475 return this.f(input) ? this.xf['@@transducer/step'](result, input) : result;
13476 };
13477 return _curry2(function _xfilter(f, xf) {
13478 return new XFilter(f, xf);
13479 });
13480 }();
13481
13482 var _xfind = function () {
13483 function XFind(f, xf) {
13484 this.xf = xf;
13485 this.f = f;
13486 this.found = false;
13487 }
13488 XFind.prototype['@@transducer/init'] = _xfBase.init;
13489 XFind.prototype['@@transducer/result'] = function (result) {
13490 if (!this.found) {
13491 result = this.xf['@@transducer/step'](result, void 0);
13492 }
13493 return this.xf['@@transducer/result'](result);
13494 };
13495 XFind.prototype['@@transducer/step'] = function (result, input) {
13496 if (this.f(input)) {
13497 this.found = true;
13498 result = _reduced(this.xf['@@transducer/step'](result, input));
13499 }
13500 return result;
13501 };
13502 return _curry2(function _xfind(f, xf) {
13503 return new XFind(f, xf);
13504 });
13505 }();
13506
13507 var _xfindIndex = function () {
13508 function XFindIndex(f, xf) {
13509 this.xf = xf;
13510 this.f = f;
13511 this.idx = -1;
13512 this.found = false;
13513 }
13514 XFindIndex.prototype['@@transducer/init'] = _xfBase.init;
13515 XFindIndex.prototype['@@transducer/result'] = function (result) {
13516 if (!this.found) {
13517 result = this.xf['@@transducer/step'](result, -1);
13518 }
13519 return this.xf['@@transducer/result'](result);
13520 };
13521 XFindIndex.prototype['@@transducer/step'] = function (result, input) {
13522 this.idx += 1;
13523 if (this.f(input)) {
13524 this.found = true;
13525 result = _reduced(this.xf['@@transducer/step'](result, this.idx));
13526 }
13527 return result;
13528 };
13529 return _curry2(function _xfindIndex(f, xf) {
13530 return new XFindIndex(f, xf);
13531 });
13532 }();
13533
13534 var _xfindLast = function () {
13535 function XFindLast(f, xf) {
13536 this.xf = xf;
13537 this.f = f;
13538 }
13539 XFindLast.prototype['@@transducer/init'] = _xfBase.init;
13540 XFindLast.prototype['@@transducer/result'] = function (result) {
13541 return this.xf['@@transducer/result'](this.xf['@@transducer/step'](result, this.last));
13542 };
13543 XFindLast.prototype['@@transducer/step'] = function (result, input) {
13544 if (this.f(input)) {
13545 this.last = input;
13546 }
13547 return result;
13548 };
13549 return _curry2(function _xfindLast(f, xf) {
13550 return new XFindLast(f, xf);
13551 });
13552 }();
13553
13554 var _xfindLastIndex = function () {
13555 function XFindLastIndex(f, xf) {
13556 this.xf = xf;
13557 this.f = f;
13558 this.idx = -1;
13559 this.lastIdx = -1;
13560 }
13561 XFindLastIndex.prototype['@@transducer/init'] = _xfBase.init;
13562 XFindLastIndex.prototype['@@transducer/result'] = function (result) {
13563 return this.xf['@@transducer/result'](this.xf['@@transducer/step'](result, this.lastIdx));
13564 };
13565 XFindLastIndex.prototype['@@transducer/step'] = function (result, input) {
13566 this.idx += 1;
13567 if (this.f(input)) {
13568 this.lastIdx = this.idx;
13569 }
13570 return result;
13571 };
13572 return _curry2(function _xfindLastIndex(f, xf) {
13573 return new XFindLastIndex(f, xf);
13574 });
13575 }();
13576
13577 var _xmap = function () {
13578 function XMap(f, xf) {
13579 this.xf = xf;
13580 this.f = f;
13581 }
13582 XMap.prototype['@@transducer/init'] = _xfBase.init;
13583 XMap.prototype['@@transducer/result'] = _xfBase.result;
13584 XMap.prototype['@@transducer/step'] = function (result, input) {
13585 return this.xf['@@transducer/step'](result, this.f(input));
13586 };
13587 return _curry2(function _xmap(f, xf) {
13588 return new XMap(f, xf);
13589 });
13590 }();
13591
13592 var _xtake = function () {
13593 function XTake(n, xf) {
13594 this.xf = xf;
13595 this.n = n;
13596 }
13597 XTake.prototype['@@transducer/init'] = _xfBase.init;
13598 XTake.prototype['@@transducer/result'] = _xfBase.result;
13599 XTake.prototype['@@transducer/step'] = function (result, input) {
13600 this.n -= 1;
13601 return this.n === 0 ? _reduced(this.xf['@@transducer/step'](result, input)) : this.xf['@@transducer/step'](result, input);
13602 };
13603 return _curry2(function _xtake(n, xf) {
13604 return new XTake(n, xf);
13605 });
13606 }();
13607
13608 var _xtakeWhile = function () {
13609 function XTakeWhile(f, xf) {
13610 this.xf = xf;
13611 this.f = f;
13612 }
13613 XTakeWhile.prototype['@@transducer/init'] = _xfBase.init;
13614 XTakeWhile.prototype['@@transducer/result'] = _xfBase.result;
13615 XTakeWhile.prototype['@@transducer/step'] = function (result, input) {
13616 return this.f(input) ? this.xf['@@transducer/step'](result, input) : _reduced(result);
13617 };
13618 return _curry2(function _xtakeWhile(f, xf) {
13619 return new XTakeWhile(f, xf);
13620 });
13621 }();
13622
13623 var _xwrap = function () {
13624 function XWrap(fn) {
13625 this.f = fn;
13626 }
13627 XWrap.prototype['@@transducer/init'] = function () {
13628 throw new Error('init not implemented on XWrap');
13629 };
13630 XWrap.prototype['@@transducer/result'] = function (acc) {
13631 return acc;
13632 };
13633 XWrap.prototype['@@transducer/step'] = function (acc, x) {
13634 return this.f(acc, x);
13635 };
13636 return function _xwrap(fn) {
13637 return new XWrap(fn);
13638 };
13639 }();
13640
13641 /**
13642 * Adds two numbers (or strings). Equivalent to `a + b` but curried.
13643 *
13644 * @func
13645 * @memberOf R
13646 * @category Math
13647 * @sig Number -> Number -> Number
13648 * @sig String -> String -> String
13649 * @param {Number|String} a The first value.
13650 * @param {Number|String} b The second value.
13651 * @return {Number|String} The result of `a + b`.
13652 * @example
13653 *
13654 * R.add(2, 3); //=> 5
13655 * R.add(7)(10); //=> 17
13656 */
13657 var add = _curry2(_add);
13658
13659 /**
13660 * Applies a function to the value at the given index of an array,
13661 * returning a new copy of the array with the element at the given
13662 * index replaced with the result of the function application.
13663 *
13664 * @func
13665 * @memberOf R
13666 * @category List
13667 * @sig (a -> a) -> Number -> [a] -> [a]
13668 * @param {Function} fn The function to apply.
13669 * @param {Number} idx The index.
13670 * @param {Array|Arguments} list An array-like object whose value
13671 * at the supplied index will be replaced.
13672 * @return {Array} A copy of the supplied array-like object with
13673 * the element at index `idx` replaced with the value
13674 * returned by applying `fn` to the existing element.
13675 * @example
13676 *
13677 * R.adjust(R.add(10), 1, [0, 1, 2]); //=> [0, 11, 2]
13678 * R.adjust(R.add(10))(1)([0, 1, 2]); //=> [0, 11, 2]
13679 */
13680 var adjust = _curry3(function (fn, idx, list) {
13681 if (idx >= list.length || idx < -list.length) {
13682 return list;
13683 }
13684 var start = idx < 0 ? list.length : 0;
13685 var _idx = start + idx;
13686 var _list = _concat(list);
13687 _list[_idx] = fn(list[_idx]);
13688 return _list;
13689 });
13690
13691 /**
13692 * Returns a function that always returns the given value. Note that for non-primitives the value
13693 * returned is a reference to the original value.
13694 *
13695 * @func
13696 * @memberOf R
13697 * @category Function
13698 * @sig a -> (* -> a)
13699 * @param {*} val The value to wrap in a function
13700 * @return {Function} A Function :: * -> val.
13701 * @example
13702 *
13703 * var t = R.always('Tee');
13704 * t(); //=> 'Tee'
13705 */
13706 var always = _curry1(function always(val) {
13707 return function () {
13708 return val;
13709 };
13710 });
13711
13712 /**
13713 * Returns a new list, composed of n-tuples of consecutive elements
13714 * If `n` is greater than the length of the list, an empty list is returned.
13715 *
13716 * @func
13717 * @memberOf R
13718 * @category List
13719 * @sig Number -> [a] -> [[a]]
13720 * @param {Number} n The size of the tuples to create
13721 * @param {Array} list The list to split into `n`-tuples
13722 * @return {Array} The new list.
13723 * @example
13724 *
13725 * R.aperture(2, [1, 2, 3, 4, 5]); //=> [[1, 2], [2, 3], [3, 4], [4, 5]]
13726 * R.aperture(3, [1, 2, 3, 4, 5]); //=> [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
13727 * R.aperture(7, [1, 2, 3, 4, 5]); //=> []
13728 */
13729 var aperture = _curry2(function aperture(n, list) {
13730 var idx = -1;
13731 var limit = list.length - (n - 1);
13732 var acc = new Array(limit >= 0 ? limit : 0);
13733 while (++idx < limit) {
13734 acc[idx] = _slice(list, idx, idx + n);
13735 }
13736 return acc;
13737 });
13738
13739 /**
13740 * Applies function `fn` to the argument list `args`. This is useful for
13741 * creating a fixed-arity function from a variadic function. `fn` should
13742 * be a bound function if context is significant.
13743 *
13744 * @func
13745 * @memberOf R
13746 * @category Function
13747 * @sig (*... -> a) -> [*] -> a
13748 * @param {Function} fn
13749 * @param {Array} args
13750 * @return {*}
13751 * @example
13752 *
13753 * var nums = [1, 2, 3, -99, 42, 6, 7];
13754 * R.apply(Math.max, nums); //=> 42
13755 */
13756 var apply = _curry2(function apply(fn, args) {
13757 return fn.apply(this, args);
13758 });
13759
13760 /**
13761 * Wraps a function of any arity (including nullary) in a function that accepts exactly `n`
13762 * parameters. Unlike `nAry`, which passes only `n` arguments to the wrapped function,
13763 * functions produced by `arity` will pass all provided arguments to the wrapped function.
13764 *
13765 * @func
13766 * @memberOf R
13767 * @sig (Number, (* -> *)) -> (* -> *)
13768 * @category Function
13769 * @param {Number} n The desired arity of the returned function.
13770 * @param {Function} fn The function to wrap.
13771 * @return {Function} A new function wrapping `fn`. The new function is
13772 * guaranteed to be of arity `n`.
13773 * @example
13774 *
13775 * var takesTwoArgs = function(a, b) {
13776 * return [a, b];
13777 * };
13778 * takesTwoArgs.length; //=> 2
13779 * takesTwoArgs(1, 2); //=> [1, 2]
13780 *
13781 * var takesOneArg = R.arity(1, takesTwoArgs);
13782 * takesOneArg.length; //=> 1
13783 * // All arguments are passed through to the wrapped function
13784 * takesOneArg(1, 2); //=> [1, 2]
13785 */
13786 var arity = _curry2(function (n, fn) {
13787 switch (n) {
13788 case 0:
13789 return function () {
13790 return fn.apply(this, arguments);
13791 };
13792 case 1:
13793 return function (a0) {
13794 void a0;
13795 return fn.apply(this, arguments);
13796 };
13797 case 2:
13798 return function (a0, a1) {
13799 void a1;
13800 return fn.apply(this, arguments);
13801 };
13802 case 3:
13803 return function (a0, a1, a2) {
13804 void a2;
13805 return fn.apply(this, arguments);
13806 };
13807 case 4:
13808 return function (a0, a1, a2, a3) {
13809 void a3;
13810 return fn.apply(this, arguments);
13811 };
13812 case 5:
13813 return function (a0, a1, a2, a3, a4) {
13814 void a4;
13815 return fn.apply(this, arguments);
13816 };
13817 case 6:
13818 return function (a0, a1, a2, a3, a4, a5) {
13819 void a5;
13820 return fn.apply(this, arguments);
13821 };
13822 case 7:
13823 return function (a0, a1, a2, a3, a4, a5, a6) {
13824 void a6;
13825 return fn.apply(this, arguments);
13826 };
13827 case 8:
13828 return function (a0, a1, a2, a3, a4, a5, a6, a7) {
13829 void a7;
13830 return fn.apply(this, arguments);
13831 };
13832 case 9:
13833 return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
13834 void a8;
13835 return fn.apply(this, arguments);
13836 };
13837 case 10:
13838 return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
13839 void a9;
13840 return fn.apply(this, arguments);
13841 };
13842 default:
13843 throw new Error('First argument to arity must be a non-negative integer no greater than ten');
13844 }
13845 });
13846
13847 /**
13848 * Makes a shallow clone of an object, setting or overriding the specified
13849 * property with the given value. Note that this copies and flattens
13850 * prototype properties onto the new object as well. All non-primitive
13851 * properties are copied by reference.
13852 *
13853 * @func
13854 * @memberOf R
13855 * @category Object
13856 * @sig String -> a -> {k: v} -> {k: v}
13857 * @param {String} prop the property name to set
13858 * @param {*} val the new value
13859 * @param {Object} obj the object to clone
13860 * @return {Object} a new object similar to the original except for the specified property.
13861 * @example
13862 *
13863 * R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3}
13864 */
13865 var assoc = _curry3(_assoc);
13866
13867 /**
13868 * Creates a function that is bound to a context.
13869 * Note: `R.bind` does not provide the additional argument-binding capabilities of
13870 * [Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
13871 *
13872 * @func
13873 * @memberOf R
13874 * @category Function
13875 * @category Object
13876 * @see R.partial
13877 * @sig (* -> *) -> {*} -> (* -> *)
13878 * @param {Function} fn The function to bind to context
13879 * @param {Object} thisObj The context to bind `fn` to
13880 * @return {Function} A function that will execute in the context of `thisObj`.
13881 */
13882 var bind = _curry2(function bind(fn, thisObj) {
13883 return arity(fn.length, function () {
13884 return fn.apply(thisObj, arguments);
13885 });
13886 });
13887
13888 /**
13889 * A function wrapping calls to the two functions in an `&&` operation, returning the result of the first
13890 * function if it is false-y and the result of the second function otherwise. Note that this is
13891 * short-circuited, meaning that the second function will not be invoked if the first returns a false-y
13892 * value.
13893 *
13894 * @func
13895 * @memberOf R
13896 * @category Logic
13897 * @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
13898 * @param {Function} f a predicate
13899 * @param {Function} g another predicate
13900 * @return {Function} a function that applies its arguments to `f` and `g` and `&&`s their outputs together.
13901 * @example
13902 *
13903 * var gt10 = function(x) { return x > 10; };
13904 * var even = function(x) { return x % 2 === 0 };
13905 * var f = R.both(gt10, even);
13906 * f(100); //=> true
13907 * f(101); //=> false
13908 */
13909 var both = _curry2(function both(f, g) {
13910 return function _both() {
13911 return f.apply(this, arguments) && g.apply(this, arguments);
13912 };
13913 });
13914
13915 /**
13916 * Makes a comparator function out of a function that reports whether the first element is less than the second.
13917 *
13918 * @func
13919 * @memberOf R
13920 * @category Function
13921 * @sig (a, b -> Boolean) -> (a, b -> Number)
13922 * @param {Function} pred A predicate function of arity two.
13923 * @return {Function} A Function :: a -> b -> Int that returns `-1` if a < b, `1` if b < a, otherwise `0`.
13924 * @example
13925 *
13926 * var cmp = R.comparator(function(a, b) {
13927 * return a.age < b.age;
13928 * });
13929 * var people = [
13930 * // ...
13931 * ];
13932 * R.sort(cmp, people);
13933 */
13934 var comparator = _curry1(function comparator(pred) {
13935 return function (a, b) {
13936 return pred(a, b) ? -1 : pred(b, a) ? 1 : 0;
13937 };
13938 });
13939
13940 /**
13941 * Takes a function `f` and returns a function `g` such that:
13942 *
13943 * - applying `g` to zero or more arguments will give __true__ if applying
13944 * the same arguments to `f` gives a logical __false__ value; and
13945 *
13946 * - applying `g` to zero or more arguments will give __false__ if applying
13947 * the same arguments to `f` gives a logical __true__ value.
13948 *
13949 * @func
13950 * @memberOf R
13951 * @category Logic
13952 * @sig (*... -> *) -> (*... -> Boolean)
13953 * @param {Function} f
13954 * @return {Function}
13955 * @example
13956 *
13957 * var isEven = function(n) { return n % 2 === 0; };
13958 * var isOdd = R.complement(isEven);
13959 * isOdd(21); //=> true
13960 * isOdd(42); //=> false
13961 */
13962 var complement = _curry1(_complement);
13963
13964 /**
13965 * Returns a function, `fn`, which encapsulates if/else-if/else logic.
13966 * Each argument to `R.cond` is a [predicate, transform] pair. All of
13967 * the arguments to `fn` are applied to each of the predicates in turn
13968 * until one returns a "truthy" value, at which point `fn` returns the
13969 * result of applying its arguments to the corresponding transformer.
13970 * If none of the predicates matches, `fn` returns undefined.
13971 *
13972 * @func
13973 * @memberOf R
13974 * @category Logic
13975 * @sig [(*... -> Boolean),(*... -> *)]... -> (*... -> *)
13976 * @param {...Function} functions
13977 * @return {Function}
13978 * @example
13979 *
13980 * var fn = R.cond(
13981 * [R.eq(0), R.always('water freezes at 0°C')],
13982 * [R.eq(100), R.always('water boils at 100°C')],
13983 * [R.T, function(temp) { return 'nothing special happens at ' + temp + '°C'; }]
13984 * );
13985 * fn(0); //=> 'water freezes at 0°C'
13986 * fn(50); //=> 'nothing special happens at 50°C'
13987 * fn(100); //=> 'water boils at 100°C'
13988 */
13989 var cond = function cond() {
13990 var pairs = arguments;
13991 return function () {
13992 var idx = -1;
13993 while (++idx < pairs.length) {
13994 if (pairs[idx][0].apply(this, arguments)) {
13995 return pairs[idx][1].apply(this, arguments);
13996 }
13997 }
13998 };
13999 };
14000
14001 /**
14002 * Returns `true` if the `x` is found in the `list`, using `pred` as an
14003 * equality predicate for `x`.
14004 *
14005 * @func
14006 * @memberOf R
14007 * @category List
14008 * @sig (a, a -> Boolean) -> a -> [a] -> Boolean
14009 * @param {Function} pred A predicate used to test whether two items are equal.
14010 * @param {*} x The item to find
14011 * @param {Array} list The list to iterate over
14012 * @return {Boolean} `true` if `x` is in `list`, else `false`.
14013 * @example
14014 *
14015 * var xs = [{x: 12}, {x: 11}, {x: 10}];
14016 * R.containsWith(function(a, b) { return a.x === b.x; }, {x: 10}, xs); //=> true
14017 * R.containsWith(function(a, b) { return a.x === b.x; }, {x: 1}, xs); //=> false
14018 */
14019 var containsWith = _curry3(_containsWith);
14020
14021 /**
14022 * Counts the elements of a list according to how many match each value
14023 * of a key generated by the supplied function. Returns an object
14024 * mapping the keys produced by `fn` to the number of occurrences in
14025 * the list. Note that all keys are coerced to strings because of how
14026 * JavaScript objects work.
14027 *
14028 * @func
14029 * @memberOf R
14030 * @category Relation
14031 * @sig (a -> String) -> [a] -> {*}
14032 * @param {Function} fn The function used to map values to keys.
14033 * @param {Array} list The list to count elements from.
14034 * @return {Object} An object mapping keys to number of occurrences in the list.
14035 * @example
14036 *
14037 * var numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2];
14038 * var letters = R.split('', 'abcABCaaaBBc');
14039 * R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1}
14040 * R.countBy(R.toLower)(letters); //=> {'a': 5, 'b': 4, 'c': 3}
14041 */
14042 var countBy = _curry2(function countBy(fn, list) {
14043 var counts = {};
14044 var len = list.length;
14045 var idx = -1;
14046 while (++idx < len) {
14047 var key = fn(list[idx]);
14048 counts[key] = (_has(key, counts) ? counts[key] : 0) + 1;
14049 }
14050 return counts;
14051 });
14052
14053 /**
14054 * Creates an object containing a single key:value pair.
14055 *
14056 * @func
14057 * @memberOf R
14058 * @category Object
14059 * @sig String -> a -> {String:a}
14060 * @param {String} key
14061 * @param {*} val
14062 * @return {Object}
14063 * @example
14064 *
14065 * var matchPhrases = R.compose(
14066 * R.createMapEntry('must'),
14067 * R.map(R.createMapEntry('match_phrase'))
14068 * );
14069 * matchPhrases(['foo', 'bar', 'baz']); //=> {must: [{match_phrase: 'foo'}, {match_phrase: 'bar'}, {match_phrase: 'baz'}]}
14070 */
14071 var createMapEntry = _curry2(_createMapEntry);
14072
14073 /**
14074 * Returns a curried equivalent of the provided function, with the
14075 * specified arity. The curried function has two unusual capabilities.
14076 * First, its arguments needn't be provided one at a time. If `g` is
14077 * `R.curryN(3, f)`, the following are equivalent:
14078 *
14079 * - `g(1)(2)(3)`
14080 * - `g(1)(2, 3)`
14081 * - `g(1, 2)(3)`
14082 * - `g(1, 2, 3)`
14083 *
14084 * Secondly, the special placeholder value `R.__` may be used to specify
14085 * "gaps", allowing partial application of any combination of arguments,
14086 * regardless of their positions. If `g` is as above and `_` is `R.__`,
14087 * the following are equivalent:
14088 *
14089 * - `g(1, 2, 3)`
14090 * - `g(_, 2, 3)(1)`
14091 * - `g(_, _, 3)(1)(2)`
14092 * - `g(_, _, 3)(1, 2)`
14093 * - `g(_, 2)(1)(3)`
14094 * - `g(_, 2)(1, 3)`
14095 * - `g(_, 2)(_, 3)(1)`
14096 *
14097 * @func
14098 * @memberOf R
14099 * @category Function
14100 * @sig Number -> (* -> a) -> (* -> a)
14101 * @param {Number} length The arity for the returned function.
14102 * @param {Function} fn The function to curry.
14103 * @return {Function} A new, curried function.
14104 * @see R.curry
14105 * @example
14106 *
14107 * var addFourNumbers = function() {
14108 * return R.sum([].slice.call(arguments, 0, 4));
14109 * };
14110 *
14111 * var curriedAddFourNumbers = R.curryN(4, addFourNumbers);
14112 * var f = curriedAddFourNumbers(1, 2);
14113 * var g = f(3);
14114 * g(4); //=> 10
14115 */
14116 var curryN = _curry2(function curryN(length, fn) {
14117 return arity(length, function () {
14118 var n = arguments.length;
14119 var shortfall = length - n;
14120 var idx = n;
14121 while (--idx >= 0) {
14122 if (arguments[idx] === __) {
14123 shortfall += 1;
14124 }
14125 }
14126 if (shortfall <= 0) {
14127 return fn.apply(this, arguments);
14128 } else {
14129 var initialArgs = _slice(arguments);
14130 return curryN(shortfall, function () {
14131 var currentArgs = _slice(arguments);
14132 var combinedArgs = [];
14133 var idx = -1;
14134 while (++idx < n) {
14135 var val = initialArgs[idx];
14136 combinedArgs[idx] = val === __ ? currentArgs.shift() : val;
14137 }
14138 return fn.apply(this, combinedArgs.concat(currentArgs));
14139 });
14140 }
14141 });
14142 });
14143
14144 /**
14145 * Decrements its argument.
14146 *
14147 * @func
14148 * @memberOf R
14149 * @category Math
14150 * @sig Number -> Number
14151 * @param {Number} n
14152 * @return {Number}
14153 * @example
14154 *
14155 * R.dec(42); //=> 41
14156 */
14157 var dec = add(-1);
14158
14159 /**
14160 * Returns the second argument if it is not null or undefined. If it is null
14161 * or undefined, the first (default) argument is returned.
14162 *
14163 * @func
14164 * @memberOf R
14165 * @category Logic
14166 * @sig a -> b -> a | b
14167 * @param {a} val The default value.
14168 * @param {b} val The value to return if it is not null or undefined
14169 * @return {*} The the second value or the default value
14170 * @example
14171 *
14172 * var defaultTo42 = defaultTo(42);
14173 *
14174 * defaultTo42(null); //=> 42
14175 * defaultTo42(undefined); //=> 42
14176 * defaultTo42('Ramda'); //=> 'Ramda'
14177 */
14178 var defaultTo = _curry2(function defaultTo(d, v) {
14179 return v == null ? d : v;
14180 });
14181
14182 /**
14183 * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list.
14184 * Duplication is determined according to the value returned by applying the supplied predicate to two list
14185 * elements.
14186 *
14187 * @func
14188 * @memberOf R
14189 * @category Relation
14190 * @sig (a,a -> Boolean) -> [a] -> [a] -> [a]
14191 * @param {Function} pred A predicate used to test whether two items are equal.
14192 * @param {Array} list1 The first list.
14193 * @param {Array} list2 The second list.
14194 * @see R.difference
14195 * @return {Array} The elements in `list1` that are not in `list2`.
14196 * @example
14197 *
14198 * function cmp(x, y) { return x.a === y.a; }
14199 * var l1 = [{a: 1}, {a: 2}, {a: 3}];
14200 * var l2 = [{a: 3}, {a: 4}];
14201 * R.differenceWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}]
14202 */
14203 var differenceWith = _curry3(function differenceWith(pred, first, second) {
14204 var out = [];
14205 var idx = -1;
14206 var firstLen = first.length;
14207 var containsPred = containsWith(pred);
14208 while (++idx < firstLen) {
14209 if (!containsPred(first[idx], second) && !containsPred(first[idx], out)) {
14210 out[out.length] = first[idx];
14211 }
14212 }
14213 return out;
14214 });
14215
14216 /**
14217 * Returns a new object that does not contain a `prop` property.
14218 *
14219 * @func
14220 * @memberOf R
14221 * @category Object
14222 * @sig String -> {k: v} -> {k: v}
14223 * @param {String} prop the name of the property to dissociate
14224 * @param {Object} obj the object to clone
14225 * @return {Object} a new object similar to the original but without the specified property
14226 * @example
14227 *
14228 * R.dissoc('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3}
14229 */
14230 var dissoc = _curry2(_dissoc);
14231
14232 /**
14233 * Divides two numbers. Equivalent to `a / b`.
14234 *
14235 * @func
14236 * @memberOf R
14237 * @category Math
14238 * @sig Number -> Number -> Number
14239 * @param {Number} a The first value.
14240 * @param {Number} b The second value.
14241 * @return {Number} The result of `a / b`.
14242 * @example
14243 *
14244 * R.divide(71, 100); //=> 0.71
14245 *
14246 * var half = R.divide(R.__, 2);
14247 * half(42); //=> 21
14248 *
14249 * var reciprocal = R.divide(1);
14250 * reciprocal(4); //=> 0.25
14251 */
14252 var divide = _curry2(function divide(a, b) {
14253 return a / b;
14254 });
14255
14256 /**
14257 * A function wrapping calls to the two functions in an `||` operation, returning the result of the first
14258 * function if it is truth-y and the result of the second function otherwise. Note that this is
14259 * short-circuited, meaning that the second function will not be invoked if the first returns a truth-y
14260 * value.
14261 *
14262 * @func
14263 * @memberOf R
14264 * @category Logic
14265 * @sig (*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
14266 * @param {Function} f a predicate
14267 * @param {Function} g another predicate
14268 * @return {Function} a function that applies its arguments to `f` and `g` and `||`s their outputs together.
14269 * @example
14270 *
14271 * var gt10 = function(x) { return x > 10; };
14272 * var even = function(x) { return x % 2 === 0 };
14273 * var f = R.either(gt10, even);
14274 * f(101); //=> true
14275 * f(8); //=> true
14276 */
14277 var either = _curry2(function either(f, g) {
14278 return function _either() {
14279 return f.apply(this, arguments) || g.apply(this, arguments);
14280 };
14281 });
14282
14283 /**
14284 * Tests if two items are equal. Equality is strict here, meaning reference equality for objects and
14285 * non-coercing equality for primitives.
14286 *
14287 * Has `Object.is` semantics: `NaN` is considered equal to `NaN`; `0` and `-0`
14288 * are not considered equal.
14289 *
14290 * @func
14291 * @memberOf R
14292 * @category Relation
14293 * @sig a -> a -> Boolean
14294 * @param {*} a
14295 * @param {*} b
14296 * @return {Boolean}
14297 * @example
14298 *
14299 * var o = {};
14300 * R.eq(o, o); //=> true
14301 * R.eq(o, {}); //=> false
14302 * R.eq(1, 1); //=> true
14303 * R.eq(1, '1'); //=> false
14304 * R.eq(0, -0); //=> false
14305 * R.eq(NaN, NaN); //=> true
14306 */
14307 var eq = _curry2(_eq);
14308
14309 /**
14310 * Reports whether two objects have the same value for the specified property. Useful as a curried predicate.
14311 *
14312 * Has `Object.is` semantics: `NaN` is considered equal to `NaN`; `0` and `-0`
14313 * are not considered equal.
14314 *
14315 * @func
14316 * @memberOf R
14317 * @category Object
14318 * @sig k -> {k: v} -> {k: v} -> Boolean
14319 * @param {String} prop The name of the property to compare
14320 * @param {Object} obj1
14321 * @param {Object} obj2
14322 * @return {Boolean}
14323 *
14324 * @example
14325 *
14326 * var o1 = { a: 1, b: 2, c: 3, d: 4 };
14327 * var o2 = { a: 10, b: 20, c: 3, d: 40 };
14328 * R.eqProps('a', o1, o2); //=> false
14329 * R.eqProps('c', o1, o2); //=> true
14330 */
14331 var eqProps = _curry3(function eqProps(prop, obj1, obj2) {
14332 return _eq(obj1[prop], obj2[prop]);
14333 });
14334
14335 /**
14336 * Like `filter`, but passes additional parameters to the predicate function. The predicate
14337 * function is passed three arguments: *(value, index, list)*.
14338 *
14339 * @func
14340 * @memberOf R
14341 * @category List
14342 * @sig (a, i, [a] -> Boolean) -> [a] -> [a]
14343 * @param {Function} fn The function called per iteration.
14344 * @param {Array} list The collection to iterate over.
14345 * @return {Array} The new filtered array.
14346 * @example
14347 *
14348 * var lastTwo = function(val, idx, list) {
14349 * return list.length - idx <= 2;
14350 * };
14351 * R.filterIndexed(lastTwo, [8, 6, 7, 5, 3, 0, 9]); //=> [0, 9]
14352 */
14353 var filterIndexed = _curry2(_filterIndexed);
14354
14355 /**
14356 * Iterate over an input `list`, calling a provided function `fn` for each element in the
14357 * list.
14358 *
14359 * `fn` receives one argument: *(value)*.
14360 *
14361 * Note: `R.forEach` does not skip deleted or unassigned indices (sparse arrays), unlike
14362 * the native `Array.prototype.forEach` method. For more details on this behavior, see:
14363 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description
14364 *
14365 * Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns the original
14366 * array. In some libraries this function is named `each`.
14367 *
14368 * @func
14369 * @memberOf R
14370 * @category List
14371 * @sig (a -> *) -> [a] -> [a]
14372 * @param {Function} fn The function to invoke. Receives one argument, `value`.
14373 * @param {Array} list The list to iterate over.
14374 * @return {Array} The original list.
14375 * @example
14376 *
14377 * var printXPlusFive = function(x) { console.log(x + 5); };
14378 * R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3]
14379 * //-> 6
14380 * //-> 7
14381 * //-> 8
14382 */
14383 var forEach = _curry2(_forEach);
14384
14385 /**
14386 * Like `forEach`, but but passes additional parameters to the predicate function.
14387 *
14388 * `fn` receives three arguments: *(value, index, list)*.
14389 *
14390 * Note: `R.forEachIndexed` does not skip deleted or unassigned indices (sparse arrays),
14391 * unlike the native `Array.prototype.forEach` method. For more details on this behavior,
14392 * see:
14393 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Description
14394 *
14395 * Also note that, unlike `Array.prototype.forEach`, Ramda's `forEach` returns the original
14396 * array. In some libraries this function is named `each`.
14397 *
14398 * @func
14399 * @memberOf R
14400 * @category List
14401 * @sig (a, i, [a] -> ) -> [a] -> [a]
14402 * @param {Function} fn The function to invoke. Receives three arguments:
14403 * (`value`, `index`, `list`).
14404 * @param {Array} list The list to iterate over.
14405 * @return {Array} The original list.
14406 * @example
14407 *
14408 * // Note that having access to the original `list` allows for
14409 * // mutation. While you *can* do this, it's very un-functional behavior:
14410 * var plusFive = function(num, idx, list) { list[idx] = num + 5 };
14411 * R.forEachIndexed(plusFive, [1, 2, 3]); //=> [6, 7, 8]
14412 */
14413 // i can't bear not to return *something*
14414 var forEachIndexed = _curry2(function forEachIndexed(fn, list) {
14415 var idx = -1, len = list.length;
14416 while (++idx < len) {
14417 fn(list[idx], idx, list);
14418 }
14419 // i can't bear not to return *something*
14420 return list;
14421 });
14422
14423 /**
14424 * Creates a new object out of a list key-value pairs.
14425 *
14426 * @func
14427 * @memberOf R
14428 * @category List
14429 * @sig [[k,v]] -> {k: v}
14430 * @param {Array} pairs An array of two-element arrays that will be the keys and values of the output object.
14431 * @return {Object} The object made by pairing up `keys` and `values`.
14432 * @example
14433 *
14434 * R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3}
14435 */
14436 var fromPairs = _curry1(function fromPairs(pairs) {
14437 var idx = -1, len = pairs.length, out = {};
14438 while (++idx < len) {
14439 if (_isArray(pairs[idx]) && pairs[idx].length) {
14440 out[pairs[idx][0]] = pairs[idx][1];
14441 }
14442 }
14443 return out;
14444 });
14445
14446 /**
14447 * Returns true if the first parameter is greater than the second.
14448 *
14449 * @func
14450 * @memberOf R
14451 * @category Math
14452 * @sig Number -> Number -> Boolean
14453 * @param {Number} a
14454 * @param {Number} b
14455 * @return {Boolean} a > b
14456 * @example
14457 *
14458 * R.gt(2, 6); //=> false
14459 * R.gt(2, 0); //=> true
14460 * R.gt(2, 2); //=> false
14461 * R.gt(R.__, 2)(10); //=> true
14462 * R.gt(2)(10); //=> false
14463 */
14464 var gt = _curry2(_gt);
14465
14466 /**
14467 * Returns true if the first parameter is greater than or equal to the second.
14468 *
14469 * @func
14470 * @memberOf R
14471 * @category Math
14472 * @sig Number -> Number -> Boolean
14473 * @param {Number} a
14474 * @param {Number} b
14475 * @return {Boolean} a >= b
14476 * @example
14477 *
14478 * R.gte(2, 6); //=> false
14479 * R.gte(2, 0); //=> true
14480 * R.gte(2, 2); //=> true
14481 * R.gte(R.__, 6)(2); //=> false
14482 * R.gte(2)(0); //=> true
14483 */
14484 var gte = _curry2(function gte(a, b) {
14485 return a >= b;
14486 });
14487
14488 /**
14489 * Returns whether or not an object has an own property with
14490 * the specified name
14491 *
14492 * @func
14493 * @memberOf R
14494 * @category Object
14495 * @sig s -> {s: x} -> Boolean
14496 * @param {String} prop The name of the property to check for.
14497 * @param {Object} obj The object to query.
14498 * @return {Boolean} Whether the property exists.
14499 * @example
14500 *
14501 * var hasName = R.has('name');
14502 * hasName({name: 'alice'}); //=> true
14503 * hasName({name: 'bob'}); //=> true
14504 * hasName({}); //=> false
14505 *
14506 * var point = {x: 0, y: 0};
14507 * var pointHas = R.has(R.__, point);
14508 * pointHas('x'); //=> true
14509 * pointHas('y'); //=> true
14510 * pointHas('z'); //=> false
14511 */
14512 var has = _curry2(_has);
14513
14514 /**
14515 * Returns whether or not an object or its prototype chain has
14516 * a property with the specified name
14517 *
14518 * @func
14519 * @memberOf R
14520 * @category Object
14521 * @sig s -> {s: x} -> Boolean
14522 * @param {String} prop The name of the property to check for.
14523 * @param {Object} obj The object to query.
14524 * @return {Boolean} Whether the property exists.
14525 * @example
14526 *
14527 * function Rectangle(width, height) {
14528 * this.width = width;
14529 * this.height = height;
14530 * }
14531 * Rectangle.prototype.area = function() {
14532 * return this.width * this.height;
14533 * };
14534 *
14535 * var square = new Rectangle(2, 2);
14536 * R.hasIn('width', square); //=> true
14537 * R.hasIn('area', square); //=> true
14538 */
14539 var hasIn = _curry2(function (prop, obj) {
14540 return prop in obj;
14541 });
14542
14543 /**
14544 * A function that does nothing but return the parameter supplied to it. Good as a default
14545 * or placeholder function.
14546 *
14547 * @func
14548 * @memberOf R
14549 * @category Function
14550 * @sig a -> a
14551 * @param {*} x The value to return.
14552 * @return {*} The input value, `x`.
14553 * @example
14554 *
14555 * R.identity(1); //=> 1
14556 *
14557 * var obj = {};
14558 * R.identity(obj) === obj; //=> true
14559 */
14560 var identity = _curry1(_identity);
14561
14562 /**
14563 * Creates a function that will process either the `onTrue` or the `onFalse` function depending
14564 * upon the result of the `condition` predicate.
14565 *
14566 * @func
14567 * @memberOf R
14568 * @category Logic
14569 * @sig (*... -> Boolean) -> (*... -> *) -> (*... -> *) -> (*... -> *)
14570 * @param {Function} condition A predicate function
14571 * @param {Function} onTrue A function to invoke when the `condition` evaluates to a truthy value.
14572 * @param {Function} onFalse A function to invoke when the `condition` evaluates to a falsy value.
14573 * @return {Function} A new unary function that will process either the `onTrue` or the `onFalse`
14574 * function depending upon the result of the `condition` predicate.
14575 * @example
14576 *
14577 * // Flatten all arrays in the list but leave other values alone.
14578 * var flattenArrays = R.map(R.ifElse(Array.isArray, R.flatten, R.identity));
14579 *
14580 * flattenArrays([[0], [[10], [8]], 1234, {}]); //=> [[0], [10, 8], 1234, {}]
14581 * flattenArrays([[[10], 123], [8, [10]], "hello"]); //=> [[10, 123], [8, 10], "hello"]
14582 */
14583 var ifElse = _curry3(function ifElse(condition, onTrue, onFalse) {
14584 return curryN(Math.max(condition.length, onTrue.length, onFalse.length), function _ifElse() {
14585 return condition.apply(this, arguments) ? onTrue.apply(this, arguments) : onFalse.apply(this, arguments);
14586 });
14587 });
14588
14589 /**
14590 * Increments its argument.
14591 *
14592 * @func
14593 * @memberOf R
14594 * @category Math
14595 * @sig Number -> Number
14596 * @param {Number} n
14597 * @return {Number}
14598 * @example
14599 *
14600 * R.inc(42); //=> 43
14601 */
14602 var inc = add(1);
14603
14604 /**
14605 * Returns the position of the first occurrence of an item in an array,
14606 * or -1 if the item is not included in the array.
14607 *
14608 * Has `Object.is` semantics: `NaN` is considered equal to `NaN`; `0` and `-0`
14609 * are not considered equal.
14610 *
14611 * @func
14612 * @memberOf R
14613 * @category List
14614 * @sig a -> [a] -> Number
14615 * @param {*} target The item to find.
14616 * @param {Array} list The array to search in.
14617 * @return {Number} the index of the target, or -1 if the target is not found.
14618 *
14619 * @example
14620 *
14621 * R.indexOf(3, [1,2,3,4]); //=> 2
14622 * R.indexOf(10, [1,2,3,4]); //=> -1
14623 */
14624 var indexOf = _curry2(function indexOf(target, list) {
14625 return _indexOf(list, target);
14626 });
14627
14628 /**
14629 * Inserts the sub-list into the list, at index `index`. _Note that this
14630 * is not destructive_: it returns a copy of the list with the changes.
14631 * <small>No lists have been harmed in the application of this function.</small>
14632 *
14633 * @func
14634 * @memberOf R
14635 * @category List
14636 * @sig Number -> [a] -> [a] -> [a]
14637 * @param {Number} index The position to insert the sub-list
14638 * @param {Array} elts The sub-list to insert into the Array
14639 * @param {Array} list The list to insert the sub-list into
14640 * @return {Array} A new Array with `elts` inserted starting at `index`.
14641 * @example
14642 *
14643 * R.insertAll(2, ['x','y','z'], [1,2,3,4]); //=> [1,2,'x','y','z',3,4]
14644 */
14645 var insertAll = _curry3(function insertAll(idx, elts, list) {
14646 idx = idx < list.length && idx >= 0 ? idx : list.length;
14647 return _concat(_concat(_slice(list, 0, idx), elts), _slice(list, idx));
14648 });
14649
14650 /**
14651 * See if an object (`val`) is an instance of the supplied constructor.
14652 * This function will check up the inheritance chain, if any.
14653 *
14654 * @func
14655 * @memberOf R
14656 * @category Type
14657 * @sig (* -> {*}) -> a -> Boolean
14658 * @param {Object} ctor A constructor
14659 * @param {*} val The value to test
14660 * @return {Boolean}
14661 * @example
14662 *
14663 * R.is(Object, {}); //=> true
14664 * R.is(Number, 1); //=> true
14665 * R.is(Object, 1); //=> false
14666 * R.is(String, 's'); //=> true
14667 * R.is(String, new String('')); //=> true
14668 * R.is(Object, new String('')); //=> true
14669 * R.is(Object, 's'); //=> false
14670 * R.is(Number, {}); //=> false
14671 */
14672 var is = _curry2(function is(Ctor, val) {
14673 return val != null && val.constructor === Ctor || val instanceof Ctor;
14674 });
14675
14676 /**
14677 * Tests whether or not an object is similar to an array.
14678 *
14679 * @func
14680 * @memberOf R
14681 * @category Type
14682 * @category List
14683 * @sig * -> Boolean
14684 * @param {*} x The object to test.
14685 * @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise.
14686 * @example
14687 *
14688 * R.isArrayLike([]); //=> true
14689 * R.isArrayLike(true); //=> false
14690 * R.isArrayLike({}); //=> false
14691 * R.isArrayLike({length: 10}); //=> false
14692 * R.isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true
14693 */
14694 var isArrayLike = _curry1(function isArrayLike(x) {
14695 if (_isArray(x)) {
14696 return true;
14697 }
14698 if (!x) {
14699 return false;
14700 }
14701 if (typeof x !== 'object') {
14702 return false;
14703 }
14704 if (x instanceof String) {
14705 return false;
14706 }
14707 if (x.nodeType === 1) {
14708 return !!x.length;
14709 }
14710 if (x.length === 0) {
14711 return true;
14712 }
14713 if (x.length > 0) {
14714 return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1);
14715 }
14716 return false;
14717 });
14718
14719 /**
14720 * Reports whether the list has zero elements.
14721 *
14722 * @func
14723 * @memberOf R
14724 * @category Logic
14725 * @sig [a] -> Boolean
14726 * @param {Array} list
14727 * @return {Boolean}
14728 * @example
14729 *
14730 * R.isEmpty([1, 2, 3]); //=> false
14731 * R.isEmpty([]); //=> true
14732 * R.isEmpty(''); //=> true
14733 * R.isEmpty(null); //=> false
14734 */
14735 var isEmpty = _curry1(function isEmpty(list) {
14736 return Object(list).length === 0;
14737 });
14738
14739 /**
14740 * Returns `true` if the input value is `NaN`.
14741 *
14742 * Equivalent to ES6's [`Number.isNaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN).
14743 *
14744 * @deprecated since v0.14.0
14745 * @func
14746 * @memberOf R
14747 * @category Math
14748 * @sig * -> Boolean
14749 * @param {*} x
14750 * @return {Boolean}
14751 * @example
14752 *
14753 * R.isNaN(NaN); //=> true
14754 * R.isNaN(undefined); //=> false
14755 * R.isNaN({}); //=> false
14756 */
14757 var isNaN = _curry1(function isNaN(x) {
14758 return typeof x === 'number' && x !== x;
14759 });
14760
14761 /**
14762 * Checks if the input value is `null` or `undefined`.
14763 *
14764 * @func
14765 * @memberOf R
14766 * @category Type
14767 * @sig * -> Boolean
14768 * @param {*} x The value to test.
14769 * @return {Boolean} `true` if `x` is `undefined` or `null`, otherwise `false`.
14770 * @example
14771 *
14772 * R.isNil(null); //=> true
14773 * R.isNil(undefined); //=> true
14774 * R.isNil(0); //=> false
14775 * R.isNil([]); //=> false
14776 */
14777 var isNil = _curry1(function isNil(x) {
14778 return x == null;
14779 });
14780
14781 /**
14782 * Returns `true` if all elements are unique, otherwise `false`.
14783 *
14784 * Has `Object.is` semantics: `NaN` is considered equal to `NaN`; `0` and `-0`
14785 * are not considered equal.
14786 *
14787 * @func
14788 * @memberOf R
14789 * @category List
14790 * @sig [a] -> Boolean
14791 * @param {Array} list The array to consider.
14792 * @return {Boolean} `true` if all elements are unique, else `false`.
14793 * @example
14794 *
14795 * R.isSet(['1', 1]); //=> true
14796 * R.isSet([1, 1]); //=> false
14797 * R.isSet([{}, {}]); //=> true
14798 */
14799 var isSet = _curry1(function isSet(list) {
14800 var len = list.length;
14801 var idx = -1;
14802 while (++idx < len) {
14803 if (_indexOf(list, list[idx], idx + 1) >= 0) {
14804 return false;
14805 }
14806 }
14807 return true;
14808 });
14809
14810 /**
14811 * Returns a list containing the names of all the
14812 * properties of the supplied object, including prototype properties.
14813 * Note that the order of the output array is not guaranteed to be
14814 * consistent across different JS platforms.
14815 *
14816 * @func
14817 * @memberOf R
14818 * @category Object
14819 * @sig {k: v} -> [k]
14820 * @param {Object} obj The object to extract properties from
14821 * @return {Array} An array of the object's own and prototype properties.
14822 * @example
14823 *
14824 * var F = function() { this.x = 'X'; };
14825 * F.prototype.y = 'Y';
14826 * var f = new F();
14827 * R.keysIn(f); //=> ['x', 'y']
14828 */
14829 var keysIn = _curry1(function keysIn(obj) {
14830 var prop, ks = [];
14831 for (prop in obj) {
14832 ks[ks.length] = prop;
14833 }
14834 return ks;
14835 });
14836
14837 /**
14838 * Returns the position of the last occurrence of an item in
14839 * an array, or -1 if the item is not included in the array.
14840 *
14841 * Has `Object.is` semantics: `NaN` is considered equal to `NaN`; `0` and `-0`
14842 * are not considered equal.
14843 *
14844 * @func
14845 * @memberOf R
14846 * @category List
14847 * @sig a -> [a] -> Number
14848 * @param {*} target The item to find.
14849 * @param {Array} list The array to search in.
14850 * @return {Number} the index of the target, or -1 if the target is not found.
14851 *
14852 * @example
14853 *
14854 * R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6
14855 * R.lastIndexOf(10, [1,2,3,4]); //=> -1
14856 */
14857 var lastIndexOf = _curry2(function lastIndexOf(target, list) {
14858 return _lastIndexOf(list, target);
14859 });
14860
14861 /**
14862 * Returns the number of elements in the array by returning `list.length`.
14863 *
14864 * @func
14865 * @memberOf R
14866 * @category List
14867 * @sig [a] -> Number
14868 * @param {Array} list The array to inspect.
14869 * @return {Number} The length of the array.
14870 * @example
14871 *
14872 * R.length([]); //=> 0
14873 * R.length([1, 2, 3]); //=> 3
14874 */
14875 var length = _curry1(function length(list) {
14876 return list != null && is(Number, list.length) ? list.length : NaN;
14877 });
14878
14879 /**
14880 * Creates a lens. Supply a function to `get` values from inside an object, and a `set`
14881 * function to change values on an object. (n.b.: This can, and should, be done without
14882 * mutating the original object!) The lens is a function wrapped around the input `get`
14883 * function, with the `set` function attached as a property on the wrapper. A `map`
14884 * function is also attached to the returned function that takes a function to operate
14885 * on the specified (`get`) property, which is then `set` before returning. The attached
14886 * `set` and `map` functions are curried.
14887 *
14888 * @func
14889 * @memberOf R
14890 * @category Object
14891 * @sig (k -> v) -> (v -> a -> *) -> (a -> b)
14892 * @param {Function} get A function that gets a value by property name
14893 * @param {Function} set A function that sets a value by property name
14894 * @return {Function} the returned function has `set` and `map` properties that are
14895 * also curried functions.
14896 * @example
14897 *
14898 * var headLens = R.lens(
14899 * function get(arr) { return arr[0]; },
14900 * function set(val, arr) { return [val].concat(arr.slice(1)); }
14901 * );
14902 * headLens([10, 20, 30, 40]); //=> 10
14903 * headLens.set('mu', [10, 20, 30, 40]); //=> ['mu', 20, 30, 40]
14904 * headLens.map(function(x) { return x + 1; }, [10, 20, 30, 40]); //=> [11, 20, 30, 40]
14905 *
14906 * var phraseLens = R.lens(
14907 * function get(obj) { return obj.phrase; },
14908 * function set(val, obj) {
14909 * var out = R.clone(obj);
14910 * out.phrase = val;
14911 * return out;
14912 * }
14913 * );
14914 * var obj1 = { phrase: 'Absolute filth . . . and I LOVED it!'};
14915 * var obj2 = { phrase: "What's all this, then?"};
14916 * phraseLens(obj1); // => 'Absolute filth . . . and I LOVED it!'
14917 * phraseLens(obj2); // => "What's all this, then?"
14918 * phraseLens.set('Ooh Betty', obj1); //=> { phrase: 'Ooh Betty'}
14919 * phraseLens.map(R.toUpper, obj2); //=> { phrase: "WHAT'S ALL THIS, THEN?"}
14920 */
14921 var lens = _curry2(function lens(get, set) {
14922 var lns = function (a) {
14923 return get(a);
14924 };
14925 lns.set = _curry2(set);
14926 lns.map = _curry2(function (fn, a) {
14927 return set(fn(get(a)), a);
14928 });
14929 return lns;
14930 });
14931
14932 /**
14933 * Returns a lens associated with the provided object.
14934 *
14935 * @func
14936 * @memberOf R
14937 * @category Object
14938 * @sig ({} -> v) -> (v -> a -> *) -> {} -> (a -> b)
14939 * @see R.lens
14940 * @param {Function} get A function that gets a value by property name
14941 * @param {Function} set A function that sets a value by property name
14942 * @param {Object} the actual object of interest
14943 * @return {Function} the returned function has `set` and `map` properties that are
14944 * also curried functions.
14945 * @example
14946 *
14947 * var xo = {x: 1};
14948 * var xoLens = R.lensOn(function get(o) { return o.x; },
14949 * function set(v) { return {x: v}; },
14950 * xo);
14951 * xoLens(); //=> 1
14952 * xoLens.set(1000); //=> {x: 1000}
14953 * xoLens.map(R.add(1)); //=> {x: 2}
14954 */
14955 var lensOn = _curry3(function lensOn(get, set, obj) {
14956 var lns = function () {
14957 return get(obj);
14958 };
14959 lns.set = set;
14960 lns.map = function (fn) {
14961 return set(fn(get(obj)));
14962 };
14963 return lns;
14964 });
14965
14966 /**
14967 * Returns true if the first parameter is less than the second.
14968 *
14969 * @func
14970 * @memberOf R
14971 * @category Math
14972 * @sig Number -> Number -> Boolean
14973 * @param {Number} a
14974 * @param {Number} b
14975 * @return {Boolean} a < b
14976 * @example
14977 *
14978 * R.lt(2, 6); //=> true
14979 * R.lt(2, 0); //=> false
14980 * R.lt(2, 2); //=> false
14981 * R.lt(5)(10); //=> true
14982 * R.lt(R.__, 5)(10); //=> false // right-sectioned currying
14983 */
14984 var lt = _curry2(_lt);
14985
14986 /**
14987 * Returns true if the first parameter is less than or equal to the second.
14988 *
14989 * @func
14990 * @memberOf R
14991 * @category Math
14992 * @sig Number -> Number -> Boolean
14993 * @param {Number} a
14994 * @param {Number} b
14995 * @return {Boolean} a <= b
14996 * @example
14997 *
14998 * R.lte(2, 6); //=> true
14999 * R.lte(2, 0); //=> false
15000 * R.lte(2, 2); //=> true
15001 * R.lte(R.__, 2)(1); //=> true
15002 * R.lte(2)(10); //=> true
15003 */
15004 var lte = _curry2(function lte(a, b) {
15005 return a <= b;
15006 });
15007
15008 /**
15009 * The mapAccum function behaves like a combination of map and reduce; it applies a
15010 * function to each element of a list, passing an accumulating parameter from left to
15011 * right, and returning a final value of this accumulator together with the new list.
15012 *
15013 * The iterator function receives two arguments, *acc* and *value*, and should return
15014 * a tuple *[acc, value]*.
15015 *
15016 * @func
15017 * @memberOf R
15018 * @category List
15019 * @sig (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
15020 * @param {Function} fn The function to be called on every element of the input `list`.
15021 * @param {*} acc The accumulator value.
15022 * @param {Array} list The list to iterate over.
15023 * @return {*} The final, accumulated value.
15024 * @example
15025 *
15026 * var digits = ['1', '2', '3', '4'];
15027 * var append = function(a, b) {
15028 * return [a + b, a + b];
15029 * }
15030 *
15031 * R.mapAccum(append, 0, digits); //=> ['01234', ['01', '012', '0123', '01234']]
15032 */
15033 var mapAccum = _curry3(function mapAccum(fn, acc, list) {
15034 var idx = -1, len = list.length, result = [], tuple = [acc];
15035 while (++idx < len) {
15036 tuple = fn(tuple[0], list[idx]);
15037 result[idx] = tuple[1];
15038 }
15039 return [
15040 tuple[0],
15041 result
15042 ];
15043 });
15044
15045 /**
15046 * The mapAccumRight function behaves like a combination of map and reduce; it applies a
15047 * function to each element of a list, passing an accumulating parameter from right
15048 * to left, and returning a final value of this accumulator together with the new list.
15049 *
15050 * Similar to `mapAccum`, except moves through the input list from the right to the
15051 * left.
15052 *
15053 * The iterator function receives two arguments, *acc* and *value*, and should return
15054 * a tuple *[acc, value]*.
15055 *
15056 * @func
15057 * @memberOf R
15058 * @category List
15059 * @sig (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
15060 * @param {Function} fn The function to be called on every element of the input `list`.
15061 * @param {*} acc The accumulator value.
15062 * @param {Array} list The list to iterate over.
15063 * @return {*} The final, accumulated value.
15064 * @example
15065 *
15066 * var digits = ['1', '2', '3', '4'];
15067 * var append = function(a, b) {
15068 * return [a + b, a + b];
15069 * }
15070 *
15071 * R.mapAccumRight(append, 0, digits); //=> ['04321', ['04321', '0432', '043', '04']]
15072 */
15073 var mapAccumRight = _curry3(function mapAccumRight(fn, acc, list) {
15074 var idx = list.length, result = [], tuple = [acc];
15075 while (--idx >= 0) {
15076 tuple = fn(tuple[0], list[idx]);
15077 result[idx] = tuple[1];
15078 }
15079 return [
15080 tuple[0],
15081 result
15082 ];
15083 });
15084
15085 /**
15086 * Like `map`, but but passes additional parameters to the mapping function.
15087 * `fn` receives three arguments: *(value, index, list)*.
15088 *
15089 * Note: `R.mapIndexed` does not skip deleted or unassigned indices (sparse arrays), unlike
15090 * the native `Array.prototype.map` method. For more details on this behavior, see:
15091 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#Description
15092 *
15093 * @func
15094 * @memberOf R
15095 * @category List
15096 * @sig (a,i,[b] -> b) -> [a] -> [b]
15097 * @param {Function} fn The function to be called on every element of the input `list`.
15098 * @param {Array} list The list to be iterated over.
15099 * @return {Array} The new list.
15100 * @example
15101 *
15102 * var squareEnds = function(elt, idx, list) {
15103 * if (idx === 0 || idx === list.length - 1) {
15104 * return elt * elt;
15105 * }
15106 * return elt;
15107 * };
15108 *
15109 * R.mapIndexed(squareEnds, [8, 5, 3, 0, 9]); //=> [64, 5, 3, 0, 81]
15110 */
15111 var mapIndexed = _curry2(function mapIndexed(fn, list) {
15112 var idx = -1, len = list.length, result = [];
15113 while (++idx < len) {
15114 result[idx] = fn(list[idx], idx, list);
15115 }
15116 return result;
15117 });
15118
15119 /**
15120 * mathMod behaves like the modulo operator should mathematically, unlike the `%`
15121 * operator (and by extension, R.modulo). So while "-17 % 5" is -2,
15122 * mathMod(-17, 5) is 3. mathMod requires Integer arguments, and returns NaN
15123 * when the modulus is zero or negative.
15124 *
15125 * @func
15126 * @memberOf R
15127 * @category Math
15128 * @sig Number -> Number -> Number
15129 * @param {Number} m The dividend.
15130 * @param {Number} p the modulus.
15131 * @return {Number} The result of `b mod a`.
15132 * @see R.moduloBy
15133 * @example
15134 *
15135 * R.mathMod(-17, 5); //=> 3
15136 * R.mathMod(17, 5); //=> 2
15137 * R.mathMod(17, -5); //=> NaN
15138 * R.mathMod(17, 0); //=> NaN
15139 * R.mathMod(17.2, 5); //=> NaN
15140 * R.mathMod(17, 5.3); //=> NaN
15141 *
15142 * var clock = R.mathMod(R.__, 12);
15143 * clock(15); //=> 3
15144 * clock(24); //=> 0
15145 *
15146 * var seventeenMod = R.mathMod(17);
15147 * seventeenMod(3); //=> 2
15148 * seventeenMod(4); //=> 1
15149 * seventeenMod(10); //=> 7
15150 */
15151 var mathMod = _curry2(function mathMod(m, p) {
15152 if (!_isInteger(m)) {
15153 return NaN;
15154 }
15155 if (!_isInteger(p) || p < 1) {
15156 return NaN;
15157 }
15158 return (m % p + p) % p;
15159 });
15160
15161 /**
15162 * Determines the largest of a list of items as determined by pairwise comparisons from the supplied comparator.
15163 * Note that this will return undefined if supplied an empty list.
15164 *
15165 * @func
15166 * @memberOf R
15167 * @category Math
15168 * @sig (a -> Number) -> [a] -> a
15169 * @param {Function} keyFn A comparator function for elements in the list
15170 * @param {Array} list A list of comparable elements
15171 * @return {*} The greatest element in the list. `undefined` if the list is empty.
15172 * @see R.max
15173 * @example
15174 *
15175 * function cmp(obj) { return obj.x; }
15176 * var a = {x: 1}, b = {x: 2}, c = {x: 3};
15177 * R.maxBy(cmp, [a, b, c]); //=> {x: 3}
15178 */
15179 var maxBy = _curry2(_createMaxMinBy(_gt));
15180
15181 /**
15182 * Determines the smallest of a list of items as determined by pairwise comparisons from the supplied comparator
15183 * Note that this will return undefined if supplied an empty list.
15184 *
15185 * @func
15186 * @memberOf R
15187 * @category Math
15188 * @sig (a -> Number) -> [a] -> a
15189 * @param {Function} keyFn A comparator function for elements in the list
15190 * @param {Array} list A list of comparable elements
15191 * @see R.min
15192 * @return {*} The greatest element in the list. `undefined` if the list is empty.
15193 * @example
15194 *
15195 * function cmp(obj) { return obj.x; }
15196 * var a = {x: 1}, b = {x: 2}, c = {x: 3};
15197 * R.minBy(cmp, [a, b, c]); //=> {x: 1}
15198 */
15199 var minBy = _curry2(_createMaxMinBy(_lt));
15200
15201 /**
15202 * Divides the second parameter by the first and returns the remainder.
15203 * Note that this functions preserves the JavaScript-style behavior for
15204 * modulo. For mathematical modulo see `mathMod`
15205 *
15206 * @func
15207 * @memberOf R
15208 * @category Math
15209 * @sig Number -> Number -> Number
15210 * @param {Number} a The value to the divide.
15211 * @param {Number} b The pseudo-modulus
15212 * @return {Number} The result of `b % a`.
15213 * @see R.mathMod
15214 * @example
15215 *
15216 * R.modulo(17, 3); //=> 2
15217 * // JS behavior:
15218 * R.modulo(-17, 3); //=> -2
15219 * R.modulo(17, -3); //=> 2
15220 *
15221 * var isOdd = R.modulo(R.__, 2);
15222 * isOdd(42); //=> 0
15223 * isOdd(21); //=> 1
15224 */
15225 var modulo = _curry2(function modulo(a, b) {
15226 return a % b;
15227 });
15228
15229 /**
15230 * Multiplies two numbers. Equivalent to `a * b` but curried.
15231 *
15232 * @func
15233 * @memberOf R
15234 * @category Math
15235 * @sig Number -> Number -> Number
15236 * @param {Number} a The first value.
15237 * @param {Number} b The second value.
15238 * @return {Number} The result of `a * b`.
15239 * @example
15240 *
15241 * var double = R.multiply(2);
15242 * var triple = R.multiply(3);
15243 * double(3); //=> 6
15244 * triple(4); //=> 12
15245 * R.multiply(2, 5); //=> 10
15246 */
15247 var multiply = _curry2(_multiply);
15248
15249 /**
15250 * Wraps a function of any arity (including nullary) in a function that accepts exactly `n`
15251 * parameters. Any extraneous parameters will not be passed to the supplied function.
15252 *
15253 * @func
15254 * @memberOf R
15255 * @category Function
15256 * @sig Number -> (* -> a) -> (* -> a)
15257 * @param {Number} n The desired arity of the new function.
15258 * @param {Function} fn The function to wrap.
15259 * @return {Function} A new function wrapping `fn`. The new function is guaranteed to be of
15260 * arity `n`.
15261 * @example
15262 *
15263 * var takesTwoArgs = function(a, b) {
15264 * return [a, b];
15265 * };
15266 * takesTwoArgs.length; //=> 2
15267 * takesTwoArgs(1, 2); //=> [1, 2]
15268 *
15269 * var takesOneArg = R.nAry(1, takesTwoArgs);
15270 * takesOneArg.length; //=> 1
15271 * // Only `n` arguments are passed to the wrapped function
15272 * takesOneArg(1, 2); //=> [1, undefined]
15273 */
15274 var nAry = _curry2(function (n, fn) {
15275 switch (n) {
15276 case 0:
15277 return function () {
15278 return fn.call(this);
15279 };
15280 case 1:
15281 return function (a0) {
15282 return fn.call(this, a0);
15283 };
15284 case 2:
15285 return function (a0, a1) {
15286 return fn.call(this, a0, a1);
15287 };
15288 case 3:
15289 return function (a0, a1, a2) {
15290 return fn.call(this, a0, a1, a2);
15291 };
15292 case 4:
15293 return function (a0, a1, a2, a3) {
15294 return fn.call(this, a0, a1, a2, a3);
15295 };
15296 case 5:
15297 return function (a0, a1, a2, a3, a4) {
15298 return fn.call(this, a0, a1, a2, a3, a4);
15299 };
15300 case 6:
15301 return function (a0, a1, a2, a3, a4, a5) {
15302 return fn.call(this, a0, a1, a2, a3, a4, a5);
15303 };
15304 case 7:
15305 return function (a0, a1, a2, a3, a4, a5, a6) {
15306 return fn.call(this, a0, a1, a2, a3, a4, a5, a6);
15307 };
15308 case 8:
15309 return function (a0, a1, a2, a3, a4, a5, a6, a7) {
15310 return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7);
15311 };
15312 case 9:
15313 return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
15314 return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7, a8);
15315 };
15316 case 10:
15317 return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
15318 return fn.call(this, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
15319 };
15320 default:
15321 throw new Error('First argument to nAry must be a non-negative integer no greater than ten');
15322 }
15323 });
15324
15325 /**
15326 * Negates its argument.
15327 *
15328 * @func
15329 * @memberOf R
15330 * @category Math
15331 * @sig Number -> Number
15332 * @param {Number} n
15333 * @return {Number}
15334 * @example
15335 *
15336 * R.negate(42); //=> -42
15337 */
15338 var negate = _curry1(function negate(n) {
15339 return -n;
15340 });
15341
15342 /**
15343 * A function that returns the `!` of its argument. It will return `true` when
15344 * passed false-y value, and `false` when passed a truth-y one.
15345 *
15346 * @func
15347 * @memberOf R
15348 * @category Logic
15349 * @sig * -> Boolean
15350 * @param {*} a any value
15351 * @return {Boolean} the logical inverse of passed argument.
15352 * @see complement
15353 * @example
15354 *
15355 * R.not(true); //=> false
15356 * R.not(false); //=> true
15357 * R.not(0); => true
15358 * R.not(1); => false
15359 */
15360 var not = _curry1(function not(a) {
15361 return !a;
15362 });
15363
15364 /**
15365 * Returns the nth element in a list.
15366 * If n is negative the element at index length + n is returned.
15367 *
15368 * @func
15369 * @memberOf R
15370 * @category List
15371 * @sig Number -> [a] -> a
15372 * @param {Number} idx
15373 * @param {Array} list
15374 * @return {*} The nth element of the list.
15375 * @example
15376 *
15377 * var list = ['foo', 'bar', 'baz', 'quux'];
15378 * R.nth(1, list); //=> 'bar'
15379 * R.nth(-1, list); //=> 'quux'
15380 * R.nth(-99, list); //=> undefined
15381 */
15382 var nth = _curry2(_nth);
15383
15384 /**
15385 * Returns a function which returns its nth argument.
15386 *
15387 * @func
15388 * @memberOf R
15389 * @category Function
15390 * @sig Number -> *... -> *
15391 * @param {Number} n
15392 * @return {Function}
15393 * @example
15394 *
15395 * R.nthArg(1)('a', 'b', 'c'); //=> 'b'
15396 * R.nthArg(-1)('a', 'b', 'c'); //=> 'c'
15397 */
15398 var nthArg = _curry1(function nthArg(n) {
15399 return function () {
15400 return _nth(n, arguments);
15401 };
15402 });
15403
15404 /**
15405 * Returns the nth character of the given string.
15406 *
15407 * @func
15408 * @memberOf R
15409 * @category String
15410 * @sig Number -> String -> String
15411 * @param {Number} n
15412 * @param {String} str
15413 * @return {String}
15414 * @example
15415 *
15416 * R.nthChar(2, 'Ramda'); //=> 'm'
15417 * R.nthChar(-2, 'Ramda'); //=> 'd'
15418 */
15419 var nthChar = _curry2(function nthChar(n, str) {
15420 return str.charAt(n < 0 ? str.length + n : n);
15421 });
15422
15423 /**
15424 * Returns the character code of the nth character of the given string.
15425 *
15426 * @func
15427 * @memberOf R
15428 * @category String
15429 * @sig Number -> String -> Number
15430 * @param {Number} n
15431 * @param {String} str
15432 * @return {Number}
15433 * @example
15434 *
15435 * R.nthCharCode(2, 'Ramda'); //=> 'm'.charCodeAt(0)
15436 * R.nthCharCode(-2, 'Ramda'); //=> 'd'.charCodeAt(0)
15437 */
15438 var nthCharCode = _curry2(function nthCharCode(n, str) {
15439 return str.charCodeAt(n < 0 ? str.length + n : n);
15440 });
15441
15442 /**
15443 * Returns a singleton array containing the value provided.
15444 *
15445 * Note this `of` is different from the ES6 `of`; See
15446 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of
15447 *
15448 * @func
15449 * @memberOf R
15450 * @category Function
15451 * @sig a -> [a]
15452 * @param {*} x any value
15453 * @return {Array} An array wrapping `x`.
15454 * @example
15455 *
15456 * R.of(null); //=> [null]
15457 * R.of([42]); //=> [[42]]
15458 */
15459 var of = _curry1(function of(x) {
15460 return [x];
15461 });
15462
15463 /**
15464 * Returns a partial copy of an object omitting the keys specified.
15465 *
15466 * @func
15467 * @memberOf R
15468 * @category Object
15469 * @sig [String] -> {String: *} -> {String: *}
15470 * @param {Array} names an array of String property names to omit from the new object
15471 * @param {Object} obj The object to copy from
15472 * @return {Object} A new object with properties from `names` not on it.
15473 * @example
15474 *
15475 * R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}
15476 */
15477 var omit = _curry2(function omit(names, obj) {
15478 var result = {};
15479 for (var prop in obj) {
15480 if (_indexOf(names, prop) < 0) {
15481 result[prop] = obj[prop];
15482 }
15483 }
15484 return result;
15485 });
15486
15487 /**
15488 * Accepts a function `fn` and returns a function that guards invocation of `fn` such that
15489 * `fn` can only ever be called once, no matter how many times the returned function is
15490 * invoked.
15491 *
15492 * @func
15493 * @memberOf R
15494 * @category Function
15495 * @sig (a... -> b) -> (a... -> b)
15496 * @param {Function} fn The function to wrap in a call-only-once wrapper.
15497 * @return {Function} The wrapped function.
15498 * @example
15499 *
15500 * var addOneOnce = R.once(function(x){ return x + 1; });
15501 * addOneOnce(10); //=> 11
15502 * addOneOnce(addOneOnce(50)); //=> 11
15503 */
15504 var once = _curry1(function once(fn) {
15505 var called = false, result;
15506 return function () {
15507 if (called) {
15508 return result;
15509 }
15510 called = true;
15511 result = fn.apply(this, arguments);
15512 return result;
15513 };
15514 });
15515
15516 /**
15517 * Retrieve the value at a given path.
15518 *
15519 * @func
15520 * @memberOf R
15521 * @category Object
15522 * @sig [String] -> {*} -> *
15523 * @param {Array} path The path to use.
15524 * @return {*} The data at `path`.
15525 * @example
15526 *
15527 * R.path(['a', 'b'], {a: {b: 2}}); //=> 2
15528 */
15529 var path = _curry2(_path);
15530
15531 /**
15532 * Determines whether a nested path on an object has a specific value.
15533 * Most likely used to filter a list.
15534 *
15535 * Has `Object.is` semantics: `NaN` is considered equal to `NaN`; `0` and `-0`
15536 * are not considered equal.
15537 *
15538 * @func
15539 * @memberOf R
15540 * @category Relation
15541 * @sig [String] -> * -> {String: *} -> Boolean
15542 * @param {Array} path The path of the nested property to use
15543 * @param {*} val The value to compare the nested property with
15544 * @param {Object} obj The object to check the nested property in
15545 * @return {Boolean} `true` if the value equals the nested object property,
15546 * `false` otherwise.
15547 * @example
15548 *
15549 * var user1 = { address: { zipCode: 90210 } };
15550 * var user2 = { address: { zipCode: 55555 } };
15551 * var user3 = { name: 'Bob' };
15552 * var users = [ user1, user2, user3 ];
15553 * var isFamous = R.pathEq(['address', 'zipCode'], 90210);
15554 * R.filter(isFamous, users); //=> [ user1 ]
15555 */
15556 var pathEq = _curry3(function pathEq(path, val, obj) {
15557 return _eq(_path(path, obj), val);
15558 });
15559
15560 /**
15561 * Returns a partial copy of an object containing only the keys specified. If the key does not exist, the
15562 * property is ignored.
15563 *
15564 * @func
15565 * @memberOf R
15566 * @category Object
15567 * @sig [String] -> {String: *} -> {String: *}
15568 * @param {Array} names an array of String property names to copy onto a new object
15569 * @param {Object} obj The object to copy from
15570 * @return {Object} A new object with only properties from `names` on it.
15571 * @example
15572 *
15573 * R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
15574 * R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1}
15575 */
15576 var pick = _curry2(function pick(names, obj) {
15577 var result = {};
15578 for (var prop in obj) {
15579 if (_indexOf(names, prop) >= 0) {
15580 result[prop] = obj[prop];
15581 }
15582 }
15583 return result;
15584 });
15585
15586 /**
15587 * Similar to `pick` except that this one includes a `key: undefined` pair for properties that don't exist.
15588 *
15589 * @func
15590 * @memberOf R
15591 * @category Object
15592 * @sig [k] -> {k: v} -> {k: v}
15593 * @param {Array} names an array of String property names to copy onto a new object
15594 * @param {Object} obj The object to copy from
15595 * @return {Object} A new object with only properties from `names` on it.
15596 * @see R.pick
15597 * @example
15598 *
15599 * R.pickAll(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
15600 * R.pickAll(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined}
15601 */
15602 var pickAll = _curry2(function pickAll(names, obj) {
15603 var result = {};
15604 var idx = -1;
15605 var len = names.length;
15606 while (++idx < len) {
15607 var name = names[idx];
15608 result[name] = obj[name];
15609 }
15610 return result;
15611 });
15612
15613 /**
15614 * Returns a partial copy of an object containing only the keys that
15615 * satisfy the supplied predicate.
15616 *
15617 * @func
15618 * @memberOf R
15619 * @category Object
15620 * @sig (v, k -> Boolean) -> {k: v} -> {k: v}
15621 * @param {Function} pred A predicate to determine whether or not a key
15622 * should be included on the output object.
15623 * @param {Object} obj The object to copy from
15624 * @return {Object} A new object with only properties that satisfy `pred`
15625 * on it.
15626 * @see R.pick
15627 * @example
15628 *
15629 * var isUpperCase = function(val, key) { return key.toUpperCase() === key; }
15630 * R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}
15631 */
15632 var pickBy = _curry2(function pickBy(test, obj) {
15633 var result = {};
15634 for (var prop in obj) {
15635 if (test(obj[prop], prop, obj)) {
15636 result[prop] = obj[prop];
15637 }
15638 }
15639 return result;
15640 });
15641
15642 /**
15643 * Returns a new list with the given element at the front, followed by the contents of the
15644 * list.
15645 *
15646 * @func
15647 * @memberOf R
15648 * @category List
15649 * @sig a -> [a] -> [a]
15650 * @param {*} el The item to add to the head of the output list.
15651 * @param {Array} list The array to add to the tail of the output list.
15652 * @return {Array} A new array.
15653 * @example
15654 *
15655 * R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum']
15656 */
15657 var prepend = _curry2(_prepend);
15658
15659 /**
15660 * Returns a function that when supplied an object returns the indicated property of that object, if it exists.
15661 *
15662 * @func
15663 * @memberOf R
15664 * @category Object
15665 * @sig s -> {s: a} -> a
15666 * @param {String} p The property name
15667 * @param {Object} obj The object to query
15668 * @return {*} The value at `obj.p`.
15669 * @example
15670 *
15671 * R.prop('x', {x: 100}); //=> 100
15672 * R.prop('x', {}); //=> undefined
15673 */
15674 var prop = _curry2(function prop(p, obj) {
15675 return obj[p];
15676 });
15677
15678 /**
15679 * Determines whether the given property of an object has a specific value.
15680 * Most likely used to filter a list.
15681 *
15682 * Has `Object.is` semantics: `NaN` is considered equal to `NaN`; `0` and `-0`
15683 * are not considered equal.
15684 *
15685 * @func
15686 * @memberOf R
15687 * @category Relation
15688 * @sig k -> v -> {k: v} -> Boolean
15689 * @param {Number|String} name The property name (or index) to use.
15690 * @param {*} val The value to compare the property with.
15691 * @return {Boolean} `true` if the properties are equal, `false` otherwise.
15692 * @example
15693 *
15694 * var abby = {name: 'Abby', age: 7, hair: 'blond'};
15695 * var fred = {name: 'Fred', age: 12, hair: 'brown'};
15696 * var rusty = {name: 'Rusty', age: 10, hair: 'brown'};
15697 * var alois = {name: 'Alois', age: 15, disposition: 'surly'};
15698 * var kids = [abby, fred, rusty, alois];
15699 * var hasBrownHair = R.propEq('hair', 'brown');
15700 * R.filter(hasBrownHair, kids); //=> [fred, rusty]
15701 */
15702 var propEq = _curry3(function propEq(name, val, obj) {
15703 return _eq(obj[name], val);
15704 });
15705
15706 /**
15707 * If the given, non-null object has an own property with the specified name,
15708 * returns the value of that property.
15709 * Otherwise returns the provided default value.
15710 *
15711 * @func
15712 * @memberOf R
15713 * @category Object
15714 * @sig a -> String -> Object -> a
15715 * @param {*} val The default value.
15716 * @param {String} p The name of the property to return.
15717 * @param {Object} obj The object to query.
15718 * @return {*} The value of given property of the supplied object or the default value.
15719 * @example
15720 *
15721 * var alice = {
15722 * name: 'ALICE',
15723 * age: 101
15724 * };
15725 * var favorite = R.prop('favoriteLibrary');
15726 * var favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary');
15727 *
15728 * favorite(alice); //=> undefined
15729 * favoriteWithDefault(alice); //=> 'Ramda'
15730 */
15731 var propOr = _curry3(function propOr(val, p, obj) {
15732 return _has(p, obj) ? obj[p] : val;
15733 });
15734
15735 /**
15736 * Acts as multiple `get`: array of keys in, array of values out. Preserves order.
15737 *
15738 * @func
15739 * @memberOf R
15740 * @category Object
15741 * @sig [k] -> {k: v} -> [v]
15742 * @param {Array} ps The property names to fetch
15743 * @param {Object} obj The object to query
15744 * @return {Array} The corresponding values or partially applied function.
15745 * @example
15746 *
15747 * R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2]
15748 * R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2]
15749 *
15750 * var fullName = R.compose(R.join(' '), R.props(['first', 'last']));
15751 * fullName({last: 'Bullet-Tooth', age: 33, first: 'Tony'}); //=> 'Tony Bullet-Tooth'
15752 */
15753 var props = _curry2(function props(ps, obj) {
15754 var len = ps.length;
15755 var out = [];
15756 var idx = -1;
15757 while (++idx < len) {
15758 out[idx] = obj[ps[idx]];
15759 }
15760 return out;
15761 });
15762
15763 /**
15764 * Returns a list of numbers from `from` (inclusive) to `to`
15765 * (exclusive).
15766 *
15767 * @func
15768 * @memberOf R
15769 * @category List
15770 * @sig Number -> Number -> [Number]
15771 * @param {Number} from The first number in the list.
15772 * @param {Number} to One more than the last number in the list.
15773 * @return {Array} The list of numbers in tthe set `[a, b)`.
15774 * @example
15775 *
15776 * R.range(1, 5); //=> [1, 2, 3, 4]
15777 * R.range(50, 53); //=> [50, 51, 52]
15778 */
15779 var range = _curry2(function range(from, to) {
15780 var result = [];
15781 var n = from;
15782 while (n < to) {
15783 result[result.length] = n;
15784 n += 1;
15785 }
15786 return result;
15787 });
15788
15789 /**
15790 * Like `reduce`, but passes additional parameters to the predicate function.
15791 *
15792 * The iterator function receives four values: *(acc, value, index, list)*
15793 *
15794 * Note: `R.reduceIndexed` does not skip deleted or unassigned indices (sparse arrays),
15795 * unlike the native `Array.prototype.reduce` method. For more details on this behavior,
15796 * see:
15797 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description
15798 *
15799 * @func
15800 * @memberOf R
15801 * @category List
15802 * @sig (a,b,i,[b] -> a) -> a -> [b] -> a
15803 * @param {Function} fn The iterator function. Receives four values: the accumulator, the
15804 * current element from `list`, that element's index, and the entire `list` itself.
15805 * @param {*} acc The accumulator value.
15806 * @param {Array} list The list to iterate over.
15807 * @return {*} The final, accumulated value.
15808 * @example
15809 *
15810 * var letters = ['a', 'b', 'c'];
15811 * var objectify = function(accObject, elem, idx, list) {
15812 * accObject[elem] = idx;
15813 * return accObject;
15814 * };
15815 *
15816 * R.reduceIndexed(objectify, {}, letters); //=> { 'a': 0, 'b': 1, 'c': 2 }
15817 */
15818 var reduceIndexed = _curry3(function reduceIndexed(fn, acc, list) {
15819 var idx = -1, len = list.length;
15820 while (++idx < len) {
15821 acc = fn(acc, list[idx], idx, list);
15822 }
15823 return acc;
15824 });
15825
15826 /**
15827 * Returns a single item by iterating through the list, successively calling the iterator
15828 * function and passing it an accumulator value and the current value from the array, and
15829 * then passing the result to the next call.
15830 *
15831 * Similar to `reduce`, except moves through the input list from the right to the left.
15832 *
15833 * The iterator function receives two values: *(acc, value)*
15834 *
15835 * Note: `R.reduceRight` does not skip deleted or unassigned indices (sparse arrays), unlike
15836 * the native `Array.prototype.reduce` method. For more details on this behavior, see:
15837 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight#Description
15838 *
15839 * @func
15840 * @memberOf R
15841 * @category List
15842 * @sig (a,b -> a) -> a -> [b] -> a
15843 * @param {Function} fn The iterator function. Receives two values, the accumulator and the
15844 * current element from the array.
15845 * @param {*} acc The accumulator value.
15846 * @param {Array} list The list to iterate over.
15847 * @return {*} The final, accumulated value.
15848 * @example
15849 *
15850 * var pairs = [ ['a', 1], ['b', 2], ['c', 3] ];
15851 * var flattenPairs = function(acc, pair) {
15852 * return acc.concat(pair);
15853 * };
15854 *
15855 * R.reduceRight(flattenPairs, [], pairs); //=> [ 'c', 3, 'b', 2, 'a', 1 ]
15856 */
15857 var reduceRight = _curry3(function reduceRight(fn, acc, list) {
15858 var idx = list.length;
15859 while (--idx >= 0) {
15860 acc = fn(acc, list[idx]);
15861 }
15862 return acc;
15863 });
15864
15865 /**
15866 * Like `reduceRight`, but passes additional parameters to the predicate function. Moves through
15867 * the input list from the right to the left.
15868 *
15869 * The iterator function receives four values: *(acc, value, index, list)*.
15870 *
15871 * Note: `R.reduceRightIndexed` does not skip deleted or unassigned indices (sparse arrays),
15872 * unlike the native `Array.prototype.reduce` method. For more details on this behavior,
15873 * see:
15874 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight#Description
15875 *
15876 * @func
15877 * @memberOf R
15878 * @category List
15879 * @sig (a,b,i,[b] -> a -> [b] -> a
15880 * @param {Function} fn The iterator function. Receives four values: the accumulator, the
15881 * current element from `list`, that element's index, and the entire `list` itself.
15882 * @param {*} acc The accumulator value.
15883 * @param {Array} list The list to iterate over.
15884 * @return {*} The final, accumulated value.
15885 * @example
15886 *
15887 * var letters = ['a', 'b', 'c'];
15888 * var objectify = function(accObject, elem, idx, list) {
15889 * accObject[elem] = idx;
15890 * return accObject;
15891 * };
15892 *
15893 * R.reduceRightIndexed(objectify, {}, letters); //=> { 'c': 2, 'b': 1, 'a': 0 }
15894 */
15895 var reduceRightIndexed = _curry3(function reduceRightIndexed(fn, acc, list) {
15896 var idx = list.length;
15897 while (--idx >= 0) {
15898 acc = fn(acc, list[idx], idx, list);
15899 }
15900 return acc;
15901 });
15902
15903 /**
15904 * Like `reject`, but passes additional parameters to the predicate function. The predicate
15905 * function is passed three arguments: *(value, index, list)*.
15906 *
15907 * @func
15908 * @memberOf R
15909 * @category List
15910 * @sig (a, i, [a] -> Boolean) -> [a] -> [a]
15911 * @param {Function} fn The function called per iteration.
15912 * @param {Array} list The collection to iterate over.
15913 * @return {Array} The new filtered array.
15914 * @example
15915 *
15916 * var lastTwo = function(val, idx, list) {
15917 * return list.length - idx <= 2;
15918 * };
15919 *
15920 * R.rejectIndexed(lastTwo, [8, 6, 7, 5, 3, 0, 9]); //=> [8, 6, 7, 5, 3]
15921 */
15922 var rejectIndexed = _curry2(function rejectIndexed(fn, list) {
15923 return _filterIndexed(_complement(fn), list);
15924 });
15925
15926 /**
15927 * Removes the sub-list of `list` starting at index `start` and containing
15928 * `count` elements. _Note that this is not destructive_: it returns a
15929 * copy of the list with the changes.
15930 * <small>No lists have been harmed in the application of this function.</small>
15931 *
15932 * @func
15933 * @memberOf R
15934 * @category List
15935 * @sig Number -> Number -> [a] -> [a]
15936 * @param {Number} start The position to start removing elements
15937 * @param {Number} count The number of elements to remove
15938 * @param {Array} list The list to remove from
15939 * @return {Array} A new Array with `count` elements from `start` removed.
15940 * @example
15941 *
15942 * R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8]
15943 */
15944 var remove = _curry3(function remove(start, count, list) {
15945 return _concat(_slice(list, 0, Math.min(start, list.length)), _slice(list, Math.min(list.length, start + count)));
15946 });
15947
15948 /**
15949 * Replace a substring or regex match in a string with a replacement.
15950 *
15951 * @func
15952 * @memberOf R
15953 * @category String
15954 * @sig RegExp|String -> String -> String -> String
15955 * @param {RegExp|String} pattern A regular expression or a substring to match.
15956 * @param {String} replacement The string to replace the matches with.
15957 * @param {String} str The String to do the search and replacement in.
15958 * @return {String} The result.
15959 * @example
15960 *
15961 * R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo'
15962 * R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo'
15963 *
15964 * // Use the "g" (global) flag to replace all occurrences:
15965 * R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar'
15966 */
15967 var replace = _curry3(function replace(regex, replacement, str) {
15968 return str.replace(regex, replacement);
15969 });
15970
15971 /**
15972 * Returns a new list with the same elements as the original list, just
15973 * in the reverse order.
15974 *
15975 * @func
15976 * @memberOf R
15977 * @category List
15978 * @sig [a] -> [a]
15979 * @param {Array} list The list to reverse.
15980 * @return {Array} A copy of the list in reverse order.
15981 * @example
15982 *
15983 * R.reverse([1, 2, 3]); //=> [3, 2, 1]
15984 * R.reverse([1, 2]); //=> [2, 1]
15985 * R.reverse([1]); //=> [1]
15986 * R.reverse([]); //=> []
15987 */
15988 var reverse = _curry1(function reverse(list) {
15989 return _slice(list).reverse();
15990 });
15991
15992 /**
15993 * Scan is similar to reduce, but returns a list of successively reduced values from the left
15994 *
15995 * @func
15996 * @memberOf R
15997 * @category List
15998 * @sig (a,b -> a) -> a -> [b] -> [a]
15999 * @param {Function} fn The iterator function. Receives two values, the accumulator and the
16000 * current element from the array
16001 * @param {*} acc The accumulator value.
16002 * @param {Array} list The list to iterate over.
16003 * @return {Array} A list of all intermediately reduced values.
16004 * @example
16005 *
16006 * var numbers = [1, 2, 3, 4];
16007 * var factorials = R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24]
16008 */
16009 var scan = _curry3(function scan(fn, acc, list) {
16010 var idx = 0, len = list.length + 1, result = [acc];
16011 while (++idx < len) {
16012 acc = fn(acc, list[idx - 1]);
16013 result[idx] = acc;
16014 }
16015 return result;
16016 });
16017
16018 /**
16019 * Returns a copy of the list, sorted according to the comparator function, which should accept two values at a
16020 * time and return a negative number if the first value is smaller, a positive number if it's larger, and zero
16021 * if they are equal. Please note that this is a **copy** of the list. It does not modify the original.
16022 *
16023 * @func
16024 * @memberOf R
16025 * @category List
16026 * @sig (a,a -> Number) -> [a] -> [a]
16027 * @param {Function} comparator A sorting function :: a -> b -> Int
16028 * @param {Array} list The list to sort
16029 * @return {Array} a new array with its elements sorted by the comparator function.
16030 * @example
16031 *
16032 * var diff = function(a, b) { return a - b; };
16033 * R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7]
16034 */
16035 var sort = _curry2(function sort(comparator, list) {
16036 return _slice(list).sort(comparator);
16037 });
16038
16039 /**
16040 * Sorts the list according to a key generated by the supplied function.
16041 *
16042 * @func
16043 * @memberOf R
16044 * @category Relation
16045 * @sig (a -> String) -> [a] -> [a]
16046 * @param {Function} fn The function mapping `list` items to keys.
16047 * @param {Array} list The list to sort.
16048 * @return {Array} A new list sorted by the keys generated by `fn`.
16049 * @example
16050 *
16051 * var sortByFirstItem = R.sortBy(prop(0));
16052 * var sortByNameCaseInsensitive = R.sortBy(compose(R.toLower, prop('name')));
16053 * var pairs = [[-1, 1], [-2, 2], [-3, 3]];
16054 * sortByFirstItem(pairs); //=> [[-3, 3], [-2, 2], [-1, 1]]
16055 * var alice = {
16056 * name: 'ALICE',
16057 * age: 101
16058 * };
16059 * var bob = {
16060 * name: 'Bob',
16061 * age: -10
16062 * };
16063 * var clara = {
16064 * name: 'clara',
16065 * age: 314.159
16066 * };
16067 * var people = [clara, bob, alice];
16068 * sortByNameCaseInsensitive(people); //=> [alice, bob, clara]
16069 */
16070 var sortBy = _curry2(function sortBy(fn, list) {
16071 return _slice(list).sort(function (a, b) {
16072 var aa = fn(a);
16073 var bb = fn(b);
16074 return aa < bb ? -1 : aa > bb ? 1 : 0;
16075 });
16076 });
16077
16078 /**
16079 * Finds the first index of a substring in a string, returning -1 if it's not present
16080 *
16081 * @func
16082 * @memberOf R
16083 * @category String
16084 * @sig String -> String -> Number
16085 * @param {String} c A string to find.
16086 * @param {String} str The string to search in
16087 * @return {Number} The first index of `c` or -1 if not found.
16088 * @example
16089 *
16090 * R.strIndexOf('c', 'abcdefg'); //=> 2
16091 */
16092 var strIndexOf = _curry2(function strIndexOf(c, str) {
16093 return str.indexOf(c);
16094 });
16095
16096 /**
16097 *
16098 * Finds the last index of a substring in a string, returning -1 if it's not present
16099 *
16100 * @func
16101 * @memberOf R
16102 * @category String
16103 * @sig String -> String -> Number
16104 * @param {String} c A string to find.
16105 * @param {String} str The string to search in
16106 * @return {Number} The last index of `c` or -1 if not found.
16107 * @example
16108 *
16109 * R.strLastIndexOf('a', 'banana split'); //=> 5
16110 */
16111 var strLastIndexOf = _curry2(function (c, str) {
16112 return str.lastIndexOf(c);
16113 });
16114
16115 /**
16116 * Subtracts two numbers. Equivalent to `a - b` but curried.
16117 *
16118 * @func
16119 * @memberOf R
16120 * @category Math
16121 * @sig Number -> Number -> Number
16122 * @param {Number} a The first value.
16123 * @param {Number} b The second value.
16124 * @return {Number} The result of `a - b`.
16125 * @example
16126 *
16127 * R.subtract(10, 8); //=> 2
16128 *
16129 * var minus5 = R.subtract(R.__, 5);
16130 * minus5(17); //=> 12
16131 *
16132 * var complementaryAngle = R.subtract(90);
16133 * complementaryAngle(30); //=> 60
16134 * complementaryAngle(72); //=> 18
16135 */
16136 var subtract = _curry2(function subtract(a, b) {
16137 return a - b;
16138 });
16139
16140 /**
16141 * Runs the given function with the supplied object, then returns the object.
16142 *
16143 * @func
16144 * @memberOf R
16145 * @category Function
16146 * @sig (a -> *) -> a -> a
16147 * @param {Function} fn The function to call with `x`. The return value of `fn` will be thrown away.
16148 * @param {*} x
16149 * @return {*} `x`.
16150 * @example
16151 *
16152 * var sayX = function(x) { console.log('x is ' + x); };
16153 * R.tap(sayX, 100); //=> 100
16154 * //-> 'x is 100'
16155 */
16156 var tap = _curry2(function tap(fn, x) {
16157 fn(x);
16158 return x;
16159 });
16160
16161 /**
16162 * Determines whether a given string matches a given regular expression.
16163 *
16164 * @func
16165 * @memberOf R
16166 * @category String
16167 * @sig RegExp -> String -> Boolean
16168 * @param {RegExp} pattern
16169 * @param {String} str
16170 * @return {Boolean}
16171 * @example
16172 *
16173 * R.test(/^x/, 'xyz'); //=> true
16174 * R.test(/^y/, 'xyz'); //=> false
16175 */
16176 var test = _curry2(function test(pattern, str) {
16177 return _cloneRegExp(pattern).test(str);
16178 });
16179
16180 /**
16181 * Calls an input function `n` times, returning an array containing the results of those
16182 * function calls.
16183 *
16184 * `fn` is passed one argument: The current value of `n`, which begins at `0` and is
16185 * gradually incremented to `n - 1`.
16186 *
16187 * @func
16188 * @memberOf R
16189 * @category List
16190 * @sig (i -> a) -> i -> [a]
16191 * @param {Function} fn The function to invoke. Passed one argument, the current value of `n`.
16192 * @param {Number} n A value between `0` and `n - 1`. Increments after each function call.
16193 * @return {Array} An array containing the return values of all calls to `fn`.
16194 * @example
16195 *
16196 * R.times(R.identity, 5); //=> [0, 1, 2, 3, 4]
16197 */
16198 var times = _curry2(function times(fn, n) {
16199 var len = Number(n);
16200 var list = new Array(len);
16201 var idx = 0;
16202 while (idx < len) {
16203 list[idx] = fn(idx);
16204 idx += 1;
16205 }
16206 return list;
16207 });
16208
16209 /**
16210 * Converts an object into an array of key, value arrays.
16211 * Only the object's own properties are used.
16212 * Note that the order of the output array is not guaranteed to be
16213 * consistent across different JS platforms.
16214 *
16215 * @func
16216 * @memberOf R
16217 * @category Object
16218 * @sig {String: *} -> [[String,*]]
16219 * @param {Object} obj The object to extract from
16220 * @return {Array} An array of key, value arrays from the object's own properties.
16221 * @example
16222 *
16223 * R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]]
16224 */
16225 var toPairs = _curry1(function toPairs(obj) {
16226 var pairs = [];
16227 for (var prop in obj) {
16228 if (_has(prop, obj)) {
16229 pairs[pairs.length] = [
16230 prop,
16231 obj[prop]
16232 ];
16233 }
16234 }
16235 return pairs;
16236 });
16237
16238 /**
16239 * Converts an object into an array of key, value arrays.
16240 * The object's own properties and prototype properties are used.
16241 * Note that the order of the output array is not guaranteed to be
16242 * consistent across different JS platforms.
16243 *
16244 * @func
16245 * @memberOf R
16246 * @category Object
16247 * @sig {String: *} -> [[String,*]]
16248 * @param {Object} obj The object to extract from
16249 * @return {Array} An array of key, value arrays from the object's own
16250 * and prototype properties.
16251 * @example
16252 *
16253 * var F = function() { this.x = 'X'; };
16254 * F.prototype.y = 'Y';
16255 * var f = new F();
16256 * R.toPairsIn(f); //=> [['x','X'], ['y','Y']]
16257 */
16258 var toPairsIn = _curry1(function toPairsIn(obj) {
16259 var pairs = [];
16260 for (var prop in obj) {
16261 pairs[pairs.length] = [
16262 prop,
16263 obj[prop]
16264 ];
16265 }
16266 return pairs;
16267 });
16268
16269 /**
16270 * Removes (strips) whitespace from both ends of the string.
16271 *
16272 * @func
16273 * @memberOf R
16274 * @category String
16275 * @sig String -> String
16276 * @param {String} str The string to trim.
16277 * @return {String} Trimmed version of `str`.
16278 * @example
16279 *
16280 * R.trim(' xyz '); //=> 'xyz'
16281 * R.map(R.trim, R.split(',', 'x, y, z')); //=> ['x', 'y', 'z']
16282 */
16283 var trim = function () {
16284 var ws = '\t\n\x0B\f\r \xA0\u1680\u180E\u2000\u2001\u2002\u2003' + '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' + '\u2029\uFEFF';
16285 var zeroWidth = '\u200B';
16286 var hasProtoTrim = typeof String.prototype.trim === 'function';
16287 if (!hasProtoTrim || (ws.trim() || !zeroWidth.trim())) {
16288 return _curry1(function trim(str) {
16289 var beginRx = new RegExp('^[' + ws + '][' + ws + ']*');
16290 var endRx = new RegExp('[' + ws + '][' + ws + ']*$');
16291 return str.replace(beginRx, '').replace(endRx, '');
16292 });
16293 } else {
16294 return _curry1(function trim(str) {
16295 return str.trim();
16296 });
16297 }
16298 }();
16299
16300 /**
16301 * Gives a single-word string description of the (native) type of a value, returning such
16302 * answers as 'Object', 'Number', 'Array', or 'Null'. Does not attempt to distinguish user
16303 * Object types any further, reporting them all as 'Object'.
16304 *
16305 * @func
16306 * @memberOf R
16307 * @category Type
16308 * @sig (* -> {*}) -> String
16309 * @param {*} val The value to test
16310 * @return {String}
16311 * @example
16312 *
16313 * R.type({}); //=> "Object"
16314 * R.type(1); //=> "Number"
16315 * R.type(false); //=> "Boolean"
16316 * R.type('s'); //=> "String"
16317 * R.type(null); //=> "Null"
16318 * R.type([]); //=> "Array"
16319 * R.type(/[A-z]/); //=> "RegExp"
16320 */
16321 var type = _curry1(function type(val) {
16322 return val === null ? 'Null' : val === undefined ? 'Undefined' : Object.prototype.toString.call(val).slice(8, -1);
16323 });
16324
16325 /**
16326 * Takes a function `fn`, which takes a single array argument, and returns
16327 * a function which:
16328 *
16329 * - takes any number of positional arguments;
16330 * - passes these arguments to `fn` as an array; and
16331 * - returns the result.
16332 *
16333 * In other words, R.unapply derives a variadic function from a function
16334 * which takes an array. R.unapply is the inverse of R.apply.
16335 *
16336 * @func
16337 * @memberOf R
16338 * @category Function
16339 * @sig ([*...] -> a) -> (*... -> a)
16340 * @param {Function} fn
16341 * @return {Function}
16342 * @see R.apply
16343 * @example
16344 *
16345 * R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]'
16346 */
16347 var unapply = _curry1(function unapply(fn) {
16348 return function () {
16349 return fn(_slice(arguments));
16350 };
16351 });
16352
16353 /**
16354 * Wraps a function of any arity (including nullary) in a function that accepts exactly 1
16355 * parameter. Any extraneous parameters will not be passed to the supplied function.
16356 *
16357 * @func
16358 * @memberOf R
16359 * @category Function
16360 * @sig (* -> b) -> (a -> b)
16361 * @param {Function} fn The function to wrap.
16362 * @return {Function} A new function wrapping `fn`. The new function is guaranteed to be of
16363 * arity 1.
16364 * @example
16365 *
16366 * var takesTwoArgs = function(a, b) {
16367 * return [a, b];
16368 * };
16369 * takesTwoArgs.length; //=> 2
16370 * takesTwoArgs(1, 2); //=> [1, 2]
16371 *
16372 * var takesOneArg = R.unary(takesTwoArgs);
16373 * takesOneArg.length; //=> 1
16374 * // Only 1 argument is passed to the wrapped function
16375 * takesOneArg(1, 2); //=> [1, undefined]
16376 */
16377 var unary = _curry1(function unary(fn) {
16378 return nAry(1, fn);
16379 });
16380
16381 /**
16382 * Returns a function of arity `n` from a (manually) curried function.
16383 *
16384 * @func
16385 * @memberOf R
16386 * @category Function
16387 * @sig Number -> (a -> b) -> (a -> c)
16388 * @param {Number} length The arity for the returned function.
16389 * @param {Function} fn The function to uncurry.
16390 * @return {Function} A new function.
16391 * @see R.curry
16392 * @example
16393 *
16394 * var addFour = function(a) {
16395 * return function(b) {
16396 * return function(c) {
16397 * return function(d) {
16398 * return a + b + c + d;
16399 * };
16400 * };
16401 * };
16402 * };
16403 *
16404 * var uncurriedAddFour = R.uncurryN(4, addFour);
16405 * curriedAddFour(1, 2, 3, 4); //=> 10
16406 */
16407 var uncurryN = _curry2(function uncurryN(depth, fn) {
16408 return curryN(depth, function () {
16409 var currentDepth = 1;
16410 var value = fn;
16411 var idx = 0;
16412 var endIdx;
16413 while (currentDepth <= depth && typeof value === 'function') {
16414 endIdx = currentDepth === depth ? arguments.length : idx + value.length;
16415 value = value.apply(this, _slice(arguments, idx, endIdx));
16416 currentDepth += 1;
16417 idx = endIdx;
16418 }
16419 return value;
16420 });
16421 });
16422
16423 /**
16424 * Builds a list from a seed value. Accepts an iterator function, which returns either false
16425 * to stop iteration or an array of length 2 containing the value to add to the resulting
16426 * list and the seed to be used in the next call to the iterator function.
16427 *
16428 * The iterator function receives one argument: *(seed)*.
16429 *
16430 * @func
16431 * @memberOf R
16432 * @category List
16433 * @sig (a -> [b]) -> * -> [b]
16434 * @param {Function} fn The iterator function. receives one argument, `seed`, and returns
16435 * either false to quit iteration or an array of length two to proceed. The element
16436 * at index 0 of this array will be added to the resulting array, and the element
16437 * at index 1 will be passed to the next call to `fn`.
16438 * @param {*} seed The seed value.
16439 * @return {Array} The final list.
16440 * @example
16441 *
16442 * var f = function(n) { return n > 50 ? false : [-n, n + 10] };
16443 * R.unfold(f, 10); //=> [-10, -20, -30, -40, -50]
16444 */
16445 var unfold = _curry2(function unfold(fn, seed) {
16446 var pair = fn(seed);
16447 var result = [];
16448 while (pair && pair.length) {
16449 result[result.length] = pair[0];
16450 pair = fn(pair[1]);
16451 }
16452 return result;
16453 });
16454
16455 /**
16456 * Returns a new list containing only one copy of each element in the original list, based
16457 * upon the value returned by applying the supplied predicate to two list elements. Prefers
16458 * the first item if two items compare equal based on the predicate.
16459 *
16460 * @func
16461 * @memberOf R
16462 * @category List
16463 * @sig (a, a -> Boolean) -> [a] -> [a]
16464 * @param {Function} pred A predicate used to test whether two items are equal.
16465 * @param {Array} list The array to consider.
16466 * @return {Array} The list of unique items.
16467 * @example
16468 *
16469 * var strEq = function(a, b) { return String(a) === String(b); };
16470 * R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2]
16471 * R.uniqWith(strEq)([{}, {}]); //=> [{}]
16472 * R.uniqWith(strEq)([1, '1', 1]); //=> [1]
16473 * R.uniqWith(strEq)(['1', 1, 1]); //=> ['1']
16474 */
16475 var uniqWith = _curry2(function uniqWith(pred, list) {
16476 var idx = -1, len = list.length;
16477 var result = [], item;
16478 while (++idx < len) {
16479 item = list[idx];
16480 if (!_containsWith(pred, item, result)) {
16481 result[result.length] = item;
16482 }
16483 }
16484 return result;
16485 });
16486
16487 /**
16488 * Returns a new copy of the array with the element at the
16489 * provided index replaced with the given value.
16490 *
16491 * @func
16492 * @memberOf R
16493 * @category List
16494 * @sig Number -> a -> [a] -> [a]
16495 * @param {Number} idx The index to update.
16496 * @param {*} x The value to exist at the given index of the returned array.
16497 * @param {Array|Arguments} list The source array-like object to be updated.
16498 * @return {Array} A copy of `list` with the value at index `idx` replaced with `x`.
16499 * @example
16500 *
16501 * R.update(1, 11, [0, 1, 2]); //=> [0, 11, 2]
16502 * R.update(1)(11)([0, 1, 2]); //=> [0, 11, 2]
16503 */
16504 var update = _curry3(function (idx, x, list) {
16505 return adjust(always(x), idx, list);
16506 });
16507
16508 /**
16509 * Returns a list of all the properties, including prototype properties,
16510 * of the supplied object.
16511 * Note that the order of the output array is not guaranteed to be
16512 * consistent across different JS platforms.
16513 *
16514 * @func
16515 * @memberOf R
16516 * @category Object
16517 * @sig {k: v} -> [v]
16518 * @param {Object} obj The object to extract values from
16519 * @return {Array} An array of the values of the object's own and prototype properties.
16520 * @example
16521 *
16522 * var F = function() { this.x = 'X'; };
16523 * F.prototype.y = 'Y';
16524 * var f = new F();
16525 * R.valuesIn(f); //=> ['X', 'Y']
16526 */
16527 var valuesIn = _curry1(function valuesIn(obj) {
16528 var prop, vs = [];
16529 for (prop in obj) {
16530 vs[vs.length] = obj[prop];
16531 }
16532 return vs;
16533 });
16534
16535 /**
16536 * Takes a spec object and a test object; returns true if the test satisfies
16537 * the spec. Each of the spec's own properties must be a predicate function.
16538 * Each predicate is applied to the value of the corresponding property of
16539 * the test object. `where` returns true if all the predicates return true,
16540 * false otherwise.
16541 *
16542 * `where` is well suited to declaratively expressing constraints for other
16543 * functions such as `filter` and `find`.
16544 *
16545 * @func
16546 * @memberOf R
16547 * @category Object
16548 * @sig {String: (* -> Boolean)} -> {String: *} -> Boolean
16549 * @param {Object} spec
16550 * @param {Object} testObj
16551 * @return {Boolean}
16552 * @example
16553 *
16554 * // pred :: Object -> Boolean
16555 * var pred = R.where({
16556 * a: R.eq('foo'),
16557 * b: R.complement(R.eq('bar')),
16558 * x: R.gt(_, 10),
16559 * y: R.lt(_, 20)
16560 * });
16561 *
16562 * pred({a: 'foo', b: 'xxx', x: 11, y: 19}); //=> true
16563 * pred({a: 'xxx', b: 'xxx', x: 11, y: 19}); //=> false
16564 * pred({a: 'foo', b: 'bar', x: 11, y: 19}); //=> false
16565 * pred({a: 'foo', b: 'xxx', x: 10, y: 19}); //=> false
16566 * pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> false
16567 */
16568 var where = _curry2(function where(spec, testObj) {
16569 for (var prop in spec) {
16570 if (_has(prop, spec) && !spec[prop](testObj[prop])) {
16571 return false;
16572 }
16573 }
16574 return true;
16575 });
16576
16577 /**
16578 * Wrap a function inside another to allow you to make adjustments to the parameters, or do
16579 * other processing either before the internal function is called or with its results.
16580 *
16581 * @func
16582 * @memberOf R
16583 * @category Function
16584 * @sig (a... -> b) -> ((a... -> b) -> a... -> c) -> (a... -> c)
16585 * @param {Function} fn The function to wrap.
16586 * @param {Function} wrapper The wrapper function.
16587 * @return {Function} The wrapped function.
16588 * @example
16589 *
16590 * var greet = function(name) {return 'Hello ' + name;};
16591 *
16592 * var shoutedGreet = R.wrap(greet, function(gr, name) {
16593 * return gr(name).toUpperCase();
16594 * });
16595 * shoutedGreet("Kathy"); //=> "HELLO KATHY"
16596 *
16597 * var shortenedGreet = R.wrap(greet, function(gr, name) {
16598 * return gr(name.substring(0, 3));
16599 * });
16600 * shortenedGreet("Robert"); //=> "Hello Rob"
16601 */
16602 var wrap = _curry2(function wrap(fn, wrapper) {
16603 return curryN(fn.length, function () {
16604 return wrapper.apply(this, _concat([fn], arguments));
16605 });
16606 });
16607
16608 /**
16609 * Creates a new list out of the two supplied by creating each possible
16610 * pair from the lists.
16611 *
16612 * @func
16613 * @memberOf R
16614 * @category List
16615 * @sig [a] -> [b] -> [[a,b]]
16616 * @param {Array} as The first list.
16617 * @param {Array} bs The second list.
16618 * @return {Array} The list made by combining each possible pair from
16619 * `as` and `bs` into pairs (`[a, b]`).
16620 * @example
16621 *
16622 * R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
16623 */
16624 // = xprodWith(prepend); (takes about 3 times as long...)
16625 var xprod = _curry2(function xprod(a, b) {
16626 // = xprodWith(prepend); (takes about 3 times as long...)
16627 var idx = -1;
16628 var ilen = a.length;
16629 var j;
16630 var jlen = b.length;
16631 var result = [];
16632 while (++idx < ilen) {
16633 j = -1;
16634 while (++j < jlen) {
16635 result[result.length] = [
16636 a[idx],
16637 b[j]
16638 ];
16639 }
16640 }
16641 return result;
16642 });
16643
16644 /**
16645 * Creates a new list out of the two supplied by pairing up
16646 * equally-positioned items from both lists. The returned list is
16647 * truncated to the length of the shorter of the two input lists.
16648 * Note: `zip` is equivalent to `zipWith(function(a, b) { return [a, b] })`.
16649 *
16650 * @func
16651 * @memberOf R
16652 * @category List
16653 * @sig [a] -> [b] -> [[a,b]]
16654 * @param {Array} list1 The first array to consider.
16655 * @param {Array} list2 The second array to consider.
16656 * @return {Array} The list made by pairing up same-indexed elements of `list1` and `list2`.
16657 * @example
16658 *
16659 * R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']]
16660 */
16661 var zip = _curry2(function zip(a, b) {
16662 var rv = [];
16663 var idx = -1;
16664 var len = Math.min(a.length, b.length);
16665 while (++idx < len) {
16666 rv[idx] = [
16667 a[idx],
16668 b[idx]
16669 ];
16670 }
16671 return rv;
16672 });
16673
16674 /**
16675 * Creates a new object out of a list of keys and a list of values.
16676 *
16677 * @func
16678 * @memberOf R
16679 * @category List
16680 * @sig [String] -> [*] -> {String: *}
16681 * @param {Array} keys The array that will be properties on the output object.
16682 * @param {Array} values The list of values on the output object.
16683 * @return {Object} The object made by pairing up same-indexed elements of `keys` and `values`.
16684 * @example
16685 *
16686 * R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3}
16687 */
16688 var zipObj = _curry2(function zipObj(keys, values) {
16689 var idx = -1, len = keys.length, out = {};
16690 while (++idx < len) {
16691 out[keys[idx]] = values[idx];
16692 }
16693 return out;
16694 });
16695
16696 /**
16697 * Creates a new list out of the two supplied by applying the function to
16698 * each equally-positioned pair in the lists. The returned list is
16699 * truncated to the length of the shorter of the two input lists.
16700 *
16701 * @function
16702 * @memberOf R
16703 * @category List
16704 * @sig (a,b -> c) -> [a] -> [b] -> [c]
16705 * @param {Function} fn The function used to combine the two elements into one value.
16706 * @param {Array} list1 The first array to consider.
16707 * @param {Array} list2 The second array to consider.
16708 * @return {Array} The list made by combining same-indexed elements of `list1` and `list2`
16709 * using `fn`.
16710 * @example
16711 *
16712 * var f = function(x, y) {
16713 * // ...
16714 * };
16715 * R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']);
16716 * //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')]
16717 */
16718 var zipWith = _curry3(function zipWith(fn, a, b) {
16719 var rv = [], idx = -1, len = Math.min(a.length, b.length);
16720 while (++idx < len) {
16721 rv[idx] = fn(a[idx], b[idx]);
16722 }
16723 return rv;
16724 });
16725
16726 /**
16727 * A function that always returns `false`. Any passed in parameters are ignored.
16728 *
16729 * @func
16730 * @memberOf R
16731 * @category Function
16732 * @sig * -> false
16733 * @see R.always
16734 * @return {Boolean} false
16735 * @example
16736 *
16737 * R.F(); //=> false
16738 */
16739 var F = always(false);
16740
16741 /**
16742 * A function that always returns `true`. Any passed in parameters are ignored.
16743 *
16744 * @func
16745 * @memberOf R
16746 * @category Function
16747 * @sig * -> true
16748 * @see R.always
16749 * @return {Boolean} `true`.
16750 * @example
16751 *
16752 * R.T(); //=> true
16753 */
16754 var T = always(true);
16755
16756 var _append = function _append(el, list) {
16757 return _concat(list, [el]);
16758 };
16759
16760 var _assocPath = function _assocPath(path, val, obj) {
16761 switch (path.length) {
16762 case 0:
16763 return obj;
16764 case 1:
16765 return _assoc(path[0], val, obj);
16766 default:
16767 return _assoc(path[0], _assocPath(_slice(path, 1), val, Object(obj[path[0]])), obj);
16768 }
16769 };
16770
16771 /**
16772 * Copies an object.
16773 *
16774 * @private
16775 * @param {*} value The value to be copied
16776 * @param {Array} refFrom Array containing the source references
16777 * @param {Array} refTo Array containing the copied source references
16778 * @return {*} The copied value.
16779 */
16780 var _baseCopy = function _baseCopy(value, refFrom, refTo) {
16781 var copy = function copy(copiedValue) {
16782 var len = refFrom.length;
16783 var idx = -1;
16784 while (++idx < len) {
16785 if (value === refFrom[idx]) {
16786 return refTo[idx];
16787 }
16788 }
16789 refFrom[idx + 1] = value;
16790 refTo[idx + 1] = copiedValue;
16791 for (var key in value) {
16792 copiedValue[key] = _baseCopy(value[key], refFrom, refTo);
16793 }
16794 return copiedValue;
16795 };
16796 switch (type(value)) {
16797 case 'Object':
16798 return copy({});
16799 case 'Array':
16800 return copy([]);
16801 case 'Date':
16802 return new Date(value);
16803 case 'RegExp':
16804 return _cloneRegExp(value);
16805 default:
16806 return value;
16807 }
16808 };
16809
16810 /**
16811 * Similar to hasMethod, this checks whether a function has a [methodname]
16812 * function. If it isn't an array it will execute that function otherwise it will
16813 * default to the ramda implementation.
16814 *
16815 * @private
16816 * @param {Function} fn ramda implemtation
16817 * @param {String} methodname property to check for a custom implementation
16818 * @return {Object} Whatever the return value of the method is.
16819 */
16820 var _checkForMethod = function _checkForMethod(methodname, fn) {
16821 return function () {
16822 var length = arguments.length;
16823 if (length === 0) {
16824 return fn();
16825 }
16826 var obj = arguments[length - 1];
16827 return _isArray(obj) || typeof obj[methodname] !== 'function' ? fn.apply(this, arguments) : obj[methodname].apply(obj, _slice(arguments, 0, length - 1));
16828 };
16829 };
16830
16831 var _composeL = function _composeL(innerLens, outerLens) {
16832 return lens(_compose(innerLens, outerLens), function (x, source) {
16833 var newInnerValue = innerLens.set(x, outerLens(source));
16834 return outerLens.set(newInnerValue, source);
16835 });
16836 };
16837
16838 /**
16839 * A right-associative two-argument composition function like `_compose`
16840 * but with automatic handling of promises (or, more precisely,
16841 * "thenables"). This function is used to construct a more general
16842 * `composeP` function, which accepts any number of arguments.
16843 *
16844 * @private
16845 * @category Function
16846 * @param {Function} f A function.
16847 * @param {Function} g A function.
16848 * @return {Function} A new function that is the equivalent of `f(g(x))`.
16849 * @example
16850 *
16851 * var Q = require('q');
16852 * var double = function(x) { return x * 2; };
16853 * var squareAsync = function(x) { return Q.when(x * x); };
16854 * var squareAsyncThenDouble = _composeP(double, squareAsync);
16855 *
16856 * squareAsyncThenDouble(5)
16857 * .then(function(result) {
16858 * // the result is now 50.
16859 * });
16860 */
16861 var _composeP = function _composeP(f, g) {
16862 return function () {
16863 var context = this;
16864 var value = g.apply(this, arguments);
16865 if (_isThenable(value)) {
16866 return value.then(function (result) {
16867 return f.call(context, result);
16868 });
16869 } else {
16870 return f.call(this, value);
16871 }
16872 };
16873 };
16874
16875 var _contains = function _contains(a, list) {
16876 return _indexOf(list, a) >= 0;
16877 };
16878
16879 /*
16880 * Returns a function that makes a multi-argument version of compose from
16881 * either _compose or _composeP.
16882 */
16883 var _createComposer = function _createComposer(composeFunction) {
16884 return function () {
16885 var idx = arguments.length - 1;
16886 var fn = arguments[idx];
16887 var length = fn.length;
16888 while (--idx >= 0) {
16889 fn = composeFunction(arguments[idx], fn);
16890 }
16891 return arity(length, fn);
16892 };
16893 };
16894
16895 /**
16896 * Create a function which takes a list
16897 * and determines the winning value by a comparator. Used internally
16898 * by `R.max` and `R.min`
16899 *
16900 * @private
16901 * @param {Function} compatator a function to compare two items
16902 * @param {*} intialVal, default value if nothing else wins
16903 * @category Math
16904 * @return {Function}
16905 */
16906 var _createMaxMin = function _createMaxMin(comparator, initialVal) {
16907 return _curry1(function (list) {
16908 var idx = -1, winner = initialVal, computed;
16909 while (++idx < list.length) {
16910 computed = +list[idx];
16911 if (comparator(computed, winner)) {
16912 winner = computed;
16913 }
16914 }
16915 return winner;
16916 });
16917 };
16918
16919 var _createPartialApplicator = function _createPartialApplicator(concat) {
16920 return function (fn) {
16921 var args = _slice(arguments, 1);
16922 return arity(Math.max(0, fn.length - args.length), function () {
16923 return fn.apply(this, concat(args, arguments));
16924 });
16925 };
16926 };
16927
16928 /**
16929 * Returns a function that dispatches with different strategies based on the
16930 * object in list position (last argument). If it is an array, executes [fn].
16931 * Otherwise, if it has a function with [methodname], it will execute that
16932 * function (functor case). Otherwise, if it is a transformer, uses transducer
16933 * [xf] to return a new transformer (transducer case). Otherwise, it will
16934 * default to executing [fn].
16935 *
16936 * @private
16937 * @param {String} methodname property to check for a custom implementation
16938 * @param {Function} xf transducer to initialize if object is transformer
16939 * @param {Function} fn default ramda implementation
16940 * @return {Function} A function that dispatches on object in list position
16941 */
16942 var _dispatchable = function _dispatchable(methodname, xf, fn) {
16943 return function () {
16944 var length = arguments.length;
16945 if (length === 0) {
16946 return fn();
16947 }
16948 var obj = arguments[length - 1];
16949 if (!_isArray(obj)) {
16950 var args = _slice(arguments, 0, length - 1);
16951 if (typeof obj[methodname] === 'function') {
16952 return obj[methodname].apply(obj, args);
16953 }
16954 if (_isTransformer(obj)) {
16955 var transducer = xf.apply(null, args);
16956 return transducer(obj);
16957 }
16958 }
16959 return fn.apply(this, arguments);
16960 };
16961 };
16962
16963 var _dissocPath = function _dissocPath(path, obj) {
16964 switch (path.length) {
16965 case 0:
16966 return obj;
16967 case 1:
16968 return _dissoc(path[0], obj);
16969 default:
16970 var head = path[0];
16971 var tail = _slice(path, 1);
16972 return obj[head] == null ? obj : _assoc(head, _dissocPath(tail, obj[head]), obj);
16973 }
16974 };
16975
16976 /**
16977 * Private function that determines whether or not a provided object has a given method.
16978 * Does not ignore methods stored on the object's prototype chain. Used for dynamically
16979 * dispatching Ramda methods to non-Array objects.
16980 *
16981 * @private
16982 * @param {String} methodName The name of the method to check for.
16983 * @param {Object} obj The object to test.
16984 * @return {Boolean} `true` has a given method, `false` otherwise.
16985 * @example
16986 *
16987 * var person = { name: 'John' };
16988 * person.shout = function() { alert(this.name); };
16989 *
16990 * _hasMethod('shout', person); //=> true
16991 * _hasMethod('foo', person); //=> false
16992 */
16993 var _hasMethod = function _hasMethod(methodName, obj) {
16994 return obj != null && !_isArray(obj) && typeof obj[methodName] === 'function';
16995 };
16996
16997 /**
16998 * `_makeFlat` is a helper function that returns a one-level or fully recursive function
16999 * based on the flag passed in.
17000 *
17001 * @private
17002 */
17003 var _makeFlat = function _makeFlat(recursive) {
17004 return function flatt(list) {
17005 var value, result = [], idx = -1, j, ilen = list.length, jlen;
17006 while (++idx < ilen) {
17007 if (isArrayLike(list[idx])) {
17008 value = recursive ? flatt(list[idx]) : list[idx];
17009 j = -1;
17010 jlen = value.length;
17011 while (++j < jlen) {
17012 result[result.length] = value[j];
17013 }
17014 } else {
17015 result[result.length] = list[idx];
17016 }
17017 }
17018 return result;
17019 };
17020 };
17021
17022 var _reduce = function () {
17023 function _arrayReduce(xf, acc, list) {
17024 var idx = -1, len = list.length;
17025 while (++idx < len) {
17026 acc = xf['@@transducer/step'](acc, list[idx]);
17027 if (acc && acc['@@transducer/reduced']) {
17028 acc = acc['@@transducer/value'];
17029 break;
17030 }
17031 }
17032 return xf['@@transducer/result'](acc);
17033 }
17034 function _iterableReduce(xf, acc, iter) {
17035 var step = iter.next();
17036 while (!step.done) {
17037 acc = xf['@@transducer/step'](acc, step.value);
17038 if (acc && acc['@@transducer/reduced']) {
17039 acc = acc['@@transducer/value'];
17040 break;
17041 }
17042 step = iter.next();
17043 }
17044 return xf['@@transducer/result'](acc);
17045 }
17046 function _methodReduce(xf, acc, obj) {
17047 return xf['@@transducer/result'](obj.reduce(bind(xf['@@transducer/step'], xf), acc));
17048 }
17049 var symIterator = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator';
17050 return function _reduce(fn, acc, list) {
17051 if (typeof fn === 'function') {
17052 fn = _xwrap(fn);
17053 }
17054 if (isArrayLike(list)) {
17055 return _arrayReduce(fn, acc, list);
17056 }
17057 if (typeof list.reduce === 'function') {
17058 return _methodReduce(fn, acc, list);
17059 }
17060 if (list[symIterator] != null) {
17061 return _iterableReduce(fn, acc, list[symIterator]());
17062 }
17063 if (typeof list.next === 'function') {
17064 return _iterableReduce(fn, acc, list);
17065 }
17066 throw new TypeError('reduce: list must be array or iterable');
17067 };
17068 }();
17069
17070 var _xall = function () {
17071 function XAll(f, xf) {
17072 this.xf = xf;
17073 this.f = f;
17074 this.all = true;
17075 }
17076 XAll.prototype['@@transducer/init'] = _xfBase.init;
17077 XAll.prototype['@@transducer/result'] = function (result) {
17078 if (this.all) {
17079 result = this.xf['@@transducer/step'](result, true);
17080 }
17081 return this.xf['@@transducer/result'](result);
17082 };
17083 XAll.prototype['@@transducer/step'] = function (result, input) {
17084 if (!this.f(input)) {
17085 this.all = false;
17086 result = _reduced(this.xf['@@transducer/step'](result, false));
17087 }
17088 return result;
17089 };
17090 return _curry2(function _xall(f, xf) {
17091 return new XAll(f, xf);
17092 });
17093 }();
17094
17095 var _xany = function () {
17096 function XAny(f, xf) {
17097 this.xf = xf;
17098 this.f = f;
17099 this.any = false;
17100 }
17101 XAny.prototype['@@transducer/init'] = _xfBase.init;
17102 XAny.prototype['@@transducer/result'] = function (result) {
17103 if (!this.any) {
17104 result = this.xf['@@transducer/step'](result, false);
17105 }
17106 return this.xf['@@transducer/result'](result);
17107 };
17108 XAny.prototype['@@transducer/step'] = function (result, input) {
17109 if (this.f(input)) {
17110 this.any = true;
17111 result = _reduced(this.xf['@@transducer/step'](result, true));
17112 }
17113 return result;
17114 };
17115 return _curry2(function _xany(f, xf) {
17116 return new XAny(f, xf);
17117 });
17118 }();
17119
17120 var _xdrop = function () {
17121 function XDrop(n, xf) {
17122 this.xf = xf;
17123 this.n = n;
17124 }
17125 XDrop.prototype['@@transducer/init'] = _xfBase.init;
17126 XDrop.prototype['@@transducer/result'] = _xfBase.result;
17127 XDrop.prototype.step = function (result, input) {
17128 if (this.n > 0) {
17129 this.n -= 1;
17130 return result;
17131 }
17132 return this.xf['@@transducer/step'](result, input);
17133 };
17134 return _curry2(function _xdrop(n, xf) {
17135 return new XDrop(n, xf);
17136 });
17137 }();
17138
17139 var _xdropWhile = function () {
17140 function XDropWhile(f, xf) {
17141 this.xf = xf;
17142 this.f = f;
17143 }
17144 XDropWhile.prototype['@@transducer/init'] = _xfBase.init;
17145 XDropWhile.prototype['@@transducer/result'] = _xfBase.result;
17146 XDropWhile.prototype['@@transducer/step'] = function (result, input) {
17147 if (this.f) {
17148 if (this.f(input)) {
17149 return result;
17150 }
17151 this.f = null;
17152 }
17153 return this.xf['@@transducer/step'](result, input);
17154 };
17155 return _curry2(function _xdropWhile(f, xf) {
17156 return new XDropWhile(f, xf);
17157 });
17158 }();
17159
17160 var _xgroupBy = function () {
17161 function XGroupBy(f, xf) {
17162 this.xf = xf;
17163 this.f = f;
17164 this.inputs = {};
17165 }
17166 XGroupBy.prototype['@@transducer/init'] = _xfBase.init;
17167 XGroupBy.prototype['@@transducer/result'] = function (result) {
17168 var key;
17169 for (key in this.inputs) {
17170 if (_has(key, this.inputs)) {
17171 result = this.xf['@@transducer/step'](result, this.inputs[key]);
17172 if (result['@@transducer/reduced']) {
17173 result = result['@@transducer/value'];
17174 break;
17175 }
17176 }
17177 }
17178 return this.xf['@@transducer/result'](result);
17179 };
17180 XGroupBy.prototype['@@transducer/step'] = function (result, input) {
17181 var key = this.f(input);
17182 this.inputs[key] = this.inputs[key] || [
17183 key,
17184 []
17185 ];
17186 this.inputs[key][1] = _append(input, this.inputs[key][1]);
17187 return result;
17188 };
17189 return _curry2(function _xgroupBy(f, xf) {
17190 return new XGroupBy(f, xf);
17191 });
17192 }();
17193
17194 /**
17195 * Returns `true` if all elements of the list match the predicate, `false` if there are any
17196 * that don't.
17197 *
17198 * Acts as a transducer if a transformer is given in list position.
17199 * @see R.transduce
17200 *
17201 * @func
17202 * @memberOf R
17203 * @category List
17204 * @sig (a -> Boolean) -> [a] -> Boolean
17205 * @param {Function} fn The predicate function.
17206 * @param {Array} list The array to consider.
17207 * @return {Boolean} `true` if the predicate is satisfied by every element, `false`
17208 * otherwise.
17209 * @example
17210 *
17211 * var lessThan2 = R.flip(R.lt)(2);
17212 * var lessThan3 = R.flip(R.lt)(3);
17213 * R.all(lessThan2)([1, 2]); //=> false
17214 * R.all(lessThan3)([1, 2]); //=> true
17215 */
17216 var all = _curry2(_dispatchable('all', _xall, _all));
17217
17218 /**
17219 * A function that returns the first argument if it's falsy otherwise the second
17220 * argument. Note that this is NOT short-circuited, meaning that if expressions
17221 * are passed they are both evaluated.
17222 *
17223 * Dispatches to the `and` method of the first argument if applicable.
17224 *
17225 * @func
17226 * @memberOf R
17227 * @category Logic
17228 * @sig * -> * -> *
17229 * @param {*} a any value
17230 * @param {*} b any other value
17231 * @return {*} the first argument if falsy otherwise the second argument.
17232 * @example
17233 *
17234 * R.and(false, true); //=> false
17235 * R.and(0, []); //=> 0
17236 * R.and(null, ''); => null
17237 */
17238 var and = _curry2(function and(a, b) {
17239 return _hasMethod('and', a) ? a.and(b) : a && b;
17240 });
17241
17242 /**
17243 * Returns `true` if at least one of elements of the list match the predicate, `false`
17244 * otherwise.
17245 *
17246 * Acts as a transducer if a transformer is given in list position.
17247 * @see R.transduce
17248 *
17249 * @func
17250 * @memberOf R
17251 * @category List
17252 * @sig (a -> Boolean) -> [a] -> Boolean
17253 * @param {Function} fn The predicate function.
17254 * @param {Array} list The array to consider.
17255 * @return {Boolean} `true` if the predicate is satisfied by at least one element, `false`
17256 * otherwise.
17257 * @example
17258 *
17259 * var lessThan0 = R.flip(R.lt)(0);
17260 * var lessThan2 = R.flip(R.lt)(2);
17261 * R.any(lessThan0)([1, 2]); //=> false
17262 * R.any(lessThan2)([1, 2]); //=> true
17263 */
17264 var any = _curry2(_dispatchable('any', _xany, _any));
17265
17266 /**
17267 * Returns a new list containing the contents of the given list, followed by the given
17268 * element.
17269 *
17270 * @func
17271 * @memberOf R
17272 * @category List
17273 * @sig a -> [a] -> [a]
17274 * @param {*} el The element to add to the end of the new list.
17275 * @param {Array} list The list whose contents will be added to the beginning of the output
17276 * list.
17277 * @return {Array} A new list containing the contents of the old list followed by `el`.
17278 * @example
17279 *
17280 * R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
17281 * R.append('tests', []); //=> ['tests']
17282 * R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]
17283 */
17284 var append = _curry2(_append);
17285
17286 /**
17287 * Makes a shallow clone of an object, setting or overriding the nodes
17288 * required to create the given path, and placing the specific value at the
17289 * tail end of that path. Note that this copies and flattens prototype
17290 * properties onto the new object as well. All non-primitive properties
17291 * are copied by reference.
17292 *
17293 * @func
17294 * @memberOf R
17295 * @category Object
17296 * @sig [String] -> a -> {k: v} -> {k: v}
17297 * @param {Array} path the path to set
17298 * @param {*} val the new value
17299 * @param {Object} obj the object to clone
17300 * @return {Object} a new object similar to the original except along the specified path.
17301 * @example
17302 *
17303 * R.assocPath(['a', 'b', 'c'], 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}}
17304 */
17305 var assocPath = _curry3(_assocPath);
17306
17307 /**
17308 * Wraps a function of any arity (including nullary) in a function that accepts exactly 2
17309 * parameters. Any extraneous parameters will not be passed to the supplied function.
17310 *
17311 * @func
17312 * @memberOf R
17313 * @category Function
17314 * @sig (* -> c) -> (a, b -> c)
17315 * @param {Function} fn The function to wrap.
17316 * @return {Function} A new function wrapping `fn`. The new function is guaranteed to be of
17317 * arity 2.
17318 * @example
17319 *
17320 * var takesThreeArgs = function(a, b, c) {
17321 * return [a, b, c];
17322 * };
17323 * takesThreeArgs.length; //=> 3
17324 * takesThreeArgs(1, 2, 3); //=> [1, 2, 3]
17325 *
17326 * var takesTwoArgs = R.binary(takesThreeArgs);
17327 * takesTwoArgs.length; //=> 2
17328 * // Only 2 arguments are passed to the wrapped function
17329 * takesTwoArgs(1, 2, 3); //=> [1, 2, undefined]
17330 */
17331 var binary = _curry1(function binary(fn) {
17332 return nAry(2, fn);
17333 });
17334
17335 /**
17336 * Creates a deep copy of the value which may contain (nested) `Array`s and
17337 * `Object`s, `Number`s, `String`s, `Boolean`s and `Date`s. `Function`s are
17338 * not copied, but assigned by their reference.
17339 *
17340 * @func
17341 * @memberOf R
17342 * @category Object
17343 * @sig {*} -> {*}
17344 * @param {*} value The object or array to clone
17345 * @return {*} A new object or array.
17346 * @example
17347 *
17348 * var objects = [{}, {}, {}];
17349 * var objectsClone = R.clone(objects);
17350 * objects[0] === objectsClone[0]; //=> false
17351 */
17352 var clone = _curry1(function clone(value) {
17353 return _baseCopy(value, [], []);
17354 });
17355
17356 /**
17357 * Creates a new function that runs each of the functions supplied as parameters in turn,
17358 * passing the return value of each function invocation to the next function invocation,
17359 * beginning with whatever arguments were passed to the initial invocation.
17360 *
17361 * Note that `compose` is a right-associative function, which means the functions provided
17362 * will be invoked in order from right to left. In the example `var h = compose(f, g)`,
17363 * the function `h` is equivalent to `f( g(x) )`, where `x` represents the arguments
17364 * originally passed to `h`.
17365 *
17366 * @func
17367 * @memberOf R
17368 * @category Function
17369 * @sig ((y -> z), (x -> y), ..., (b -> c), (a... -> b)) -> (a... -> z)
17370 * @param {...Function} functions A variable number of functions.
17371 * @return {Function} A new function which represents the result of calling each of the
17372 * input `functions`, passing the result of each function call to the next, from
17373 * right to left.
17374 * @example
17375 *
17376 * var triple = function(x) { return x * 3; };
17377 * var double = function(x) { return x * 2; };
17378 * var square = function(x) { return x * x; };
17379 * var squareThenDoubleThenTriple = R.compose(triple, double, square);
17380 *
17381 * //≅ triple(double(square(5)))
17382 * squareThenDoubleThenTriple(5); //=> 150
17383 */
17384 var compose = _createComposer(_compose);
17385
17386 /**
17387 * Creates a new lens that allows getting and setting values of nested properties, by
17388 * following each given lens in succession.
17389 *
17390 * Note that `composeL` is a right-associative function, which means the lenses provided
17391 * will be invoked in order from right to left.
17392 *
17393 * @func
17394 * @memberOf R
17395 * @category Function
17396 * @see R.lens
17397 * @sig ((y -> z), (x -> y), ..., (b -> c), (a -> b)) -> (a -> z)
17398 * @param {...Function} lenses A variable number of lenses.
17399 * @return {Function} A new lens which represents the result of calling each of the
17400 * input `lenses`, passing the result of each getter/setter as the source
17401 * to the next, from right to left.
17402 * @example
17403 *
17404 * var headLens = R.lensIndex(0);
17405 * var secondLens = R.lensIndex(1);
17406 * var xLens = R.lensProp('x');
17407 * var secondOfXOfHeadLens = R.composeL(secondLens, xLens, headLens);
17408 *
17409 * var source = [{x: [0, 1], y: [2, 3]}, {x: [4, 5], y: [6, 7]}];
17410 * secondOfXOfHeadLens(source); //=> 1
17411 * secondOfXOfHeadLens.set(123, source); //=> [{x: [0, 123], y: [2, 3]}, {x: [4, 5], y: [6, 7]}]
17412 */
17413 var composeL = function () {
17414 var idx = arguments.length - 1;
17415 var fn = arguments[idx];
17416 while (--idx >= 0) {
17417 fn = _composeL(arguments[idx], fn);
17418 }
17419 return fn;
17420 };
17421
17422 /**
17423 * Similar to `compose` but with automatic handling of promises (or, more
17424 * precisely, "thenables"). The behavior is identical to that of
17425 * compose() if all composed functions return something other than
17426 * promises (i.e., objects with a .then() method). If one of the function
17427 * returns a promise, however, then the next function in the composition
17428 * is called asynchronously, in the success callback of the promise, using
17429 * the resolved value as an input. Note that `composeP` is a right-
17430 * associative function, just like `compose`.
17431 *
17432 * @func
17433 * @memberOf R
17434 * @category Function
17435 * @sig ((y -> z), (x -> y), ..., (b -> c), (a... -> b)) -> (a... -> z)
17436 * @param {...Function} functions A variable number of functions.
17437 * @return {Function} A new function which represents the result of calling each of the
17438 * input `functions`, passing either the returned result or the asynchronously
17439 * resolved value) of each function call to the next, from right to left.
17440 * @example
17441 *
17442 * var Q = require('q');
17443 * var triple = function(x) { return x * 3; };
17444 * var double = function(x) { return x * 2; };
17445 * var squareAsync = function(x) { return Q.when(x * x); };
17446 * var squareAsyncThenDoubleThenTriple = R.composeP(triple, double, squareAsync);
17447 *
17448 * //≅ squareAsync(5).then(function(x) { return triple(double(x)) };
17449 * squareAsyncThenDoubleThenTriple(5)
17450 * .then(function(result) {
17451 * // result is 150
17452 * });
17453 */
17454 var composeP = _createComposer(_composeP);
17455
17456 /**
17457 * Returns a new list consisting of the elements of the first list followed by the elements
17458 * of the second.
17459 *
17460 * @func
17461 * @memberOf R
17462 * @category List
17463 * @sig [a] -> [a] -> [a]
17464 * @param {Array} list1 The first list to merge.
17465 * @param {Array} list2 The second set to merge.
17466 * @return {Array} A new array consisting of the contents of `list1` followed by the
17467 * contents of `list2`. If, instead of an Array for `list1`, you pass an
17468 * object with a `concat` method on it, `concat` will call `list1.concat`
17469 * and pass it the value of `list2`.
17470 *
17471 * @example
17472 *
17473 * R.concat([], []); //=> []
17474 * R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
17475 * R.concat('ABC', 'DEF'); // 'ABCDEF'
17476 */
17477 var concat = _curry2(function (set1, set2) {
17478 if (_isArray(set2)) {
17479 return _concat(set1, set2);
17480 } else if (_hasMethod('concat', set1)) {
17481 return set1.concat(set2);
17482 } else {
17483 throw new TypeError('can\'t concat ' + typeof set1);
17484 }
17485 });
17486
17487 /**
17488 * Returns `true` if the specified item is somewhere in the list, `false` otherwise.
17489 * Equivalent to `indexOf(a, list) >= 0`.
17490 *
17491 * Has `Object.is` semantics: `NaN` is considered equal to `NaN`; `0` and `-0`
17492 * are not considered equal.
17493 *
17494 * @func
17495 * @memberOf R
17496 * @category List
17497 * @sig a -> [a] -> Boolean
17498 * @param {Object} a The item to compare against.
17499 * @param {Array} list The array to consider.
17500 * @return {Boolean} `true` if the item is in the list, `false` otherwise.
17501 *
17502 * @example
17503 *
17504 * R.contains(3)([1, 2, 3]); //=> true
17505 * R.contains(4)([1, 2, 3]); //=> false
17506 * R.contains({})([{}, {}]); //=> false
17507 * var obj = {};
17508 * R.contains(obj)([{}, obj, {}]); //=> true
17509 */
17510 var contains = _curry2(_contains);
17511
17512 /**
17513 * Returns a curried equivalent of the provided function. The curried
17514 * function has two unusual capabilities. First, its arguments needn't
17515 * be provided one at a time. If `f` is a ternary function and `g` is
17516 * `R.curry(f)`, the following are equivalent:
17517 *
17518 * - `g(1)(2)(3)`
17519 * - `g(1)(2, 3)`
17520 * - `g(1, 2)(3)`
17521 * - `g(1, 2, 3)`
17522 *
17523 * Secondly, the special placeholder value `R.__` may be used to specify
17524 * "gaps", allowing partial application of any combination of arguments,
17525 * regardless of their positions. If `g` is as above and `_` is `R.__`,
17526 * the following are equivalent:
17527 *
17528 * - `g(1, 2, 3)`
17529 * - `g(_, 2, 3)(1)`
17530 * - `g(_, _, 3)(1)(2)`
17531 * - `g(_, _, 3)(1, 2)`
17532 * - `g(_, 2)(1)(3)`
17533 * - `g(_, 2)(1, 3)`
17534 * - `g(_, 2)(_, 3)(1)`
17535 *
17536 * @func
17537 * @memberOf R
17538 * @category Function
17539 * @sig (* -> a) -> (* -> a)
17540 * @param {Function} fn The function to curry.
17541 * @return {Function} A new, curried function.
17542 * @see R.curryN
17543 * @example
17544 *
17545 * var addFourNumbers = function(a, b, c, d) {
17546 * return a + b + c + d;
17547 * };
17548 *
17549 * var curriedAddFourNumbers = R.curry(addFourNumbers);
17550 * var f = curriedAddFourNumbers(1, 2);
17551 * var g = f(3);
17552 * g(4); //=> 10
17553 */
17554 var curry = _curry1(function curry(fn) {
17555 return curryN(fn.length, fn);
17556 });
17557
17558 /**
17559 * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list.
17560 *
17561 * @func
17562 * @memberOf R
17563 * @category Relation
17564 * @sig [a] -> [a] -> [a]
17565 * @param {Array} list1 The first list.
17566 * @param {Array} list2 The second list.
17567 * @return {Array} The elements in `list1` that are not in `list2`.
17568 * @see R.differenceWith
17569 * @example
17570 *
17571 * R.difference([1,2,3,4], [7,6,5,4,3]); //=> [1,2]
17572 * R.difference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5]
17573 */
17574 var difference = _curry2(function difference(first, second) {
17575 var out = [];
17576 var idx = -1;
17577 var firstLen = first.length;
17578 while (++idx < firstLen) {
17579 if (!_contains(first[idx], second) && !_contains(first[idx], out)) {
17580 out[out.length] = first[idx];
17581 }
17582 }
17583 return out;
17584 });
17585
17586 /**
17587 * Makes a shallow clone of an object, omitting the property at the
17588 * given path. Note that this copies and flattens prototype properties
17589 * onto the new object as well. All non-primitive properties are copied
17590 * by reference.
17591 *
17592 * @func
17593 * @memberOf R
17594 * @category Object
17595 * @sig [String] -> {k: v} -> {k: v}
17596 * @param {Array} path the path to set
17597 * @param {Object} obj the object to clone
17598 * @return {Object} a new object without the property at path
17599 * @example
17600 *
17601 * R.dissocPath(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}}
17602 */
17603 var dissocPath = _curry2(_dissocPath);
17604
17605 /**
17606 * Returns a list containing all but the first `n` elements of the given `list`.
17607 *
17608 * Acts as a transducer if a transformer is given in list position.
17609 * @see R.transduce
17610 *
17611 * @func
17612 * @memberOf R
17613 * @category List
17614 * @sig Number -> [a] -> [a]
17615 * @param {Number} n The number of elements of `list` to skip.
17616 * @param {Array} list The array to consider.
17617 * @return {Array} The last `n` elements of `list`.
17618 * @example
17619 *
17620 * R.drop(3, [1,2,3,4,5,6,7]); //=> [4,5,6,7]
17621 */
17622 var drop = _curry2(_dispatchable('drop', _xdrop, function drop(n, list) {
17623 return n <= 0 ? list : _slice(list, n);
17624 }));
17625
17626 /**
17627 * Returns a new list containing the last `n` elements of a given list, passing each value
17628 * to the supplied predicate function, skipping elements while the predicate function returns
17629 * `true`. The predicate function is passed one argument: *(value)*.
17630 *
17631 * Acts as a transducer if a transformer is given in list position.
17632 * @see R.transduce
17633 *
17634 * @func
17635 * @memberOf R
17636 * @category List
17637 * @sig (a -> Boolean) -> [a] -> [a]
17638 * @param {Function} fn The function called per iteration.
17639 * @param {Array} list The collection to iterate over.
17640 * @return {Array} A new array.
17641 * @example
17642 *
17643 * var lteTwo = function(x) {
17644 * return x <= 2;
17645 * };
17646 *
17647 * R.dropWhile(lteTwo, [1, 2, 3, 4]); //=> [3, 4]
17648 */
17649 var dropWhile = _curry2(_dispatchable('dropWhile', _xdropWhile, function dropWhile(pred, list) {
17650 var idx = -1, len = list.length;
17651 while (++idx < len && pred(list[idx])) {
17652 }
17653 return _slice(list, idx);
17654 }));
17655
17656 /**
17657 * `empty` wraps any object in an array. This implementation is compatible with the
17658 * Fantasy-land Monoid spec, and will work with types that implement that spec.
17659 *
17660 * @func
17661 * @memberOf R
17662 * @category Function
17663 * @sig * -> []
17664 * @return {Array} An empty array.
17665 * @example
17666 *
17667 * R.empty([1,2,3,4,5]); //=> []
17668 */
17669 var empty = _curry1(function empty(x) {
17670 return _hasMethod('empty', x) ? x.empty() : [];
17671 });
17672
17673 /**
17674 * Returns a new list containing only those items that match a given predicate function.
17675 * The predicate function is passed one argument: *(value)*.
17676 *
17677 * Note that `R.filter` does not skip deleted or unassigned indices, unlike the native
17678 * `Array.prototype.filter` method. For more details on this behavior, see:
17679 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Description
17680 *
17681 * Acts as a transducer if a transformer is given in list position.
17682 * @see R.transduce
17683 *
17684 * @func
17685 * @memberOf R
17686 * @category List
17687 * @sig (a -> Boolean) -> [a] -> [a]
17688 * @param {Function} fn The function called per iteration.
17689 * @param {Array} list The collection to iterate over.
17690 * @return {Array} The new filtered array.
17691 * @example
17692 *
17693 * var isEven = function(n) {
17694 * return n % 2 === 0;
17695 * };
17696 * R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4]
17697 */
17698 var filter = _curry2(_dispatchable('filter', _xfilter, _filter));
17699
17700 /**
17701 * Returns the first element of the list which matches the predicate, or `undefined` if no
17702 * element matches.
17703 *
17704 * Acts as a transducer if a transformer is given in list position.
17705 * @see R.transduce
17706 *
17707 * @func
17708 * @memberOf R
17709 * @category List
17710 * @sig (a -> Boolean) -> [a] -> a | undefined
17711 * @param {Function} fn The predicate function used to determine if the element is the
17712 * desired one.
17713 * @param {Array} list The array to consider.
17714 * @return {Object} The element found, or `undefined`.
17715 * @example
17716 *
17717 * var xs = [{a: 1}, {a: 2}, {a: 3}];
17718 * R.find(R.propEq('a', 2))(xs); //=> {a: 2}
17719 * R.find(R.propEq('a', 4))(xs); //=> undefined
17720 */
17721 var find = _curry2(_dispatchable('find', _xfind, function find(fn, list) {
17722 var idx = -1;
17723 var len = list.length;
17724 while (++idx < len) {
17725 if (fn(list[idx])) {
17726 return list[idx];
17727 }
17728 }
17729 }));
17730
17731 /**
17732 * Returns the index of the first element of the list which matches the predicate, or `-1`
17733 * if no element matches.
17734 *
17735 * Acts as a transducer if a transformer is given in list position.
17736 * @see R.transduce
17737 *
17738 * @func
17739 * @memberOf R
17740 * @category List
17741 * @sig (a -> Boolean) -> [a] -> Number
17742 * @param {Function} fn The predicate function used to determine if the element is the
17743 * desired one.
17744 * @param {Array} list The array to consider.
17745 * @return {Number} The index of the element found, or `-1`.
17746 * @example
17747 *
17748 * var xs = [{a: 1}, {a: 2}, {a: 3}];
17749 * R.findIndex(R.propEq('a', 2))(xs); //=> 1
17750 * R.findIndex(R.propEq('a', 4))(xs); //=> -1
17751 */
17752 var findIndex = _curry2(_dispatchable('findIndex', _xfindIndex, function findIndex(fn, list) {
17753 var idx = -1;
17754 var len = list.length;
17755 while (++idx < len) {
17756 if (fn(list[idx])) {
17757 return idx;
17758 }
17759 }
17760 return -1;
17761 }));
17762
17763 /**
17764 * Returns the last element of the list which matches the predicate, or `undefined` if no
17765 * element matches.
17766 *
17767 * Acts as a transducer if a transformer is given in list position.
17768 * @see R.transduce
17769 *
17770 * @func
17771 * @memberOf R
17772 * @category List
17773 * @sig (a -> Boolean) -> [a] -> a | undefined
17774 * @param {Function} fn The predicate function used to determine if the element is the
17775 * desired one.
17776 * @param {Array} list The array to consider.
17777 * @return {Object} The element found, or `undefined`.
17778 * @example
17779 *
17780 * var xs = [{a: 1, b: 0}, {a:1, b: 1}];
17781 * R.findLast(R.propEq('a', 1))(xs); //=> {a: 1, b: 1}
17782 * R.findLast(R.propEq('a', 4))(xs); //=> undefined
17783 */
17784 var findLast = _curry2(_dispatchable('findLast', _xfindLast, function findLast(fn, list) {
17785 var idx = list.length;
17786 while (--idx >= 0) {
17787 if (fn(list[idx])) {
17788 return list[idx];
17789 }
17790 }
17791 }));
17792
17793 /**
17794 * Returns the index of the last element of the list which matches the predicate, or
17795 * `-1` if no element matches.
17796 *
17797 * Acts as a transducer if a transformer is given in list position.
17798 * @see R.transduce
17799 *
17800 * @func
17801 * @memberOf R
17802 * @category List
17803 * @sig (a -> Boolean) -> [a] -> Number
17804 * @param {Function} fn The predicate function used to determine if the element is the
17805 * desired one.
17806 * @param {Array} list The array to consider.
17807 * @return {Number} The index of the element found, or `-1`.
17808 * @example
17809 *
17810 * var xs = [{a: 1, b: 0}, {a:1, b: 1}];
17811 * R.findLastIndex(R.propEq('a', 1))(xs); //=> 1
17812 * R.findLastIndex(R.propEq('a', 4))(xs); //=> -1
17813 */
17814 var findLastIndex = _curry2(_dispatchable('findLastIndex', _xfindLastIndex, function findLastIndex(fn, list) {
17815 var idx = list.length;
17816 while (--idx >= 0) {
17817 if (fn(list[idx])) {
17818 return idx;
17819 }
17820 }
17821 return -1;
17822 }));
17823
17824 /**
17825 * Returns a new list by pulling every item out of it (and all its sub-arrays) and putting
17826 * them in a new array, depth-first.
17827 *
17828 * @func
17829 * @memberOf R
17830 * @category List
17831 * @sig [a] -> [b]
17832 * @param {Array} list The array to consider.
17833 * @return {Array} The flattened list.
17834 * @example
17835 *
17836 * R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]);
17837 * //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
17838 */
17839 var flatten = _curry1(_makeFlat(true));
17840
17841 /**
17842 * Returns a new function much like the supplied one, except that the first two arguments'
17843 * order is reversed.
17844 *
17845 * @func
17846 * @memberOf R
17847 * @category Function
17848 * @sig (a -> b -> c -> ... -> z) -> (b -> a -> c -> ... -> z)
17849 * @param {Function} fn The function to invoke with its first two parameters reversed.
17850 * @return {*} The result of invoking `fn` with its first two parameters' order reversed.
17851 * @example
17852 *
17853 * var mergeThree = function(a, b, c) {
17854 * return ([]).concat(a, b, c);
17855 * };
17856 *
17857 * mergeThree(1, 2, 3); //=> [1, 2, 3]
17858 *
17859 * R.flip(mergeThree)(1, 2, 3); //=> [2, 1, 3]
17860 */
17861 var flip = _curry1(function flip(fn) {
17862 return curry(function (a, b) {
17863 var args = _slice(arguments);
17864 args[0] = b;
17865 args[1] = a;
17866 return fn.apply(this, args);
17867 });
17868 });
17869
17870 /**
17871 * Returns a list of function names of object's own and prototype functions
17872 *
17873 * @func
17874 * @memberOf R
17875 * @category Object
17876 * @sig {*} -> [String]
17877 * @param {Object} obj The objects with functions in it
17878 * @return {Array} A list of the object's own properties and prototype
17879 * properties that map to functions.
17880 * @example
17881 *
17882 * R.functionsIn(R); // returns list of ramda's own and prototype function names
17883 *
17884 * var F = function() { this.x = function(){}; this.y = 1; }
17885 * F.prototype.z = function() {};
17886 * F.prototype.a = 100;
17887 * R.functionsIn(new F()); //=> ["x", "z"]
17888 */
17889 var functionsIn = _curry1(_functionsWith(keysIn));
17890
17891 /**
17892 * Splits a list into sub-lists stored in an object, based on the result of calling a String-returning function
17893 * on each element, and grouping the results according to values returned.
17894 *
17895 * Acts as a transducer if a transformer is given in list position.
17896 * @see R.transduce
17897 *
17898 * @func
17899 * @memberOf R
17900 * @category List
17901 * @sig (a -> String) -> [a] -> {String: [a]}
17902 * @param {Function} fn Function :: a -> String
17903 * @param {Array} list The array to group
17904 * @return {Object} An object with the output of `fn` for keys, mapped to arrays of elements
17905 * that produced that key when passed to `fn`.
17906 * @example
17907 *
17908 * var byGrade = R.groupBy(function(student) {
17909 * var score = student.score;
17910 * return score < 65 ? 'F' :
17911 * score < 70 ? 'D' :
17912 * score < 80 ? 'C' :
17913 * score < 90 ? 'B' : 'A';
17914 * });
17915 * var students = [{name: 'Abby', score: 84},
17916 * {name: 'Eddy', score: 58},
17917 * // ...
17918 * {name: 'Jack', score: 69}];
17919 * byGrade(students);
17920 * // {
17921 * // 'A': [{name: 'Dianne', score: 99}],
17922 * // 'B': [{name: 'Abby', score: 84}]
17923 * // // ...,
17924 * // 'F': [{name: 'Eddy', score: 58}]
17925 * // }
17926 */
17927 var groupBy = _curry2(_dispatchable('groupBy', _xgroupBy, function groupBy(fn, list) {
17928 return _reduce(function (acc, elt) {
17929 var key = fn(elt);
17930 acc[key] = _append(elt, acc[key] || (acc[key] = []));
17931 return acc;
17932 }, {}, list);
17933 }));
17934
17935 /**
17936 * Returns the first element in a list.
17937 * In some libraries this function is named `first`.
17938 *
17939 * @func
17940 * @memberOf R
17941 * @category List
17942 * @sig [a] -> a
17943 * @param {Array} list The array to consider.
17944 * @return {*} The first element of the list, or `undefined` if the list is empty.
17945 * @example
17946 *
17947 * R.head(['fi', 'fo', 'fum']); //=> 'fi'
17948 */
17949 var head = nth(0);
17950
17951 /**
17952 * Inserts the supplied element into the list, at index `index`. _Note
17953 * that this is not destructive_: it returns a copy of the list with the changes.
17954 * <small>No lists have been harmed in the application of this function.</small>
17955 *
17956 * @func
17957 * @memberOf R
17958 * @category List
17959 * @sig Number -> a -> [a] -> [a]
17960 * @param {Number} index The position to insert the element
17961 * @param {*} elt The element to insert into the Array
17962 * @param {Array} list The list to insert into
17963 * @return {Array} A new Array with `elt` inserted at `index`.
17964 * @example
17965 *
17966 * R.insert(2, 'x', [1,2,3,4]); //=> [1,2,'x',3,4]
17967 */
17968 var insert = _curry3(function insert(idx, elt, list) {
17969 idx = idx < list.length && idx >= 0 ? idx : list.length;
17970 return _concat(_append(elt, _slice(list, 0, idx)), _slice(list, idx));
17971 });
17972
17973 /**
17974 * Combines two lists into a set (i.e. no duplicates) composed of those
17975 * elements common to both lists. Duplication is determined according
17976 * to the value returned by applying the supplied predicate to two list
17977 * elements.
17978 *
17979 * @func
17980 * @memberOf R
17981 * @category Relation
17982 * @sig (a,a -> Boolean) -> [a] -> [a] -> [a]
17983 * @param {Function} pred A predicate function that determines whether
17984 * the two supplied elements are equal.
17985 * @param {Array} list1 One list of items to compare
17986 * @param {Array} list2 A second list of items to compare
17987 * @see R.intersection
17988 * @return {Array} A new list containing those elements common to both lists.
17989 * @example
17990 *
17991 * var buffaloSpringfield = [
17992 * {id: 824, name: 'Richie Furay'},
17993 * {id: 956, name: 'Dewey Martin'},
17994 * {id: 313, name: 'Bruce Palmer'},
17995 * {id: 456, name: 'Stephen Stills'},
17996 * {id: 177, name: 'Neil Young'}
17997 * ];
17998 * var csny = [
17999 * {id: 204, name: 'David Crosby'},
18000 * {id: 456, name: 'Stephen Stills'},
18001 * {id: 539, name: 'Graham Nash'},
18002 * {id: 177, name: 'Neil Young'}
18003 * ];
18004 *
18005 * var sameId = function(o1, o2) {return o1.id === o2.id;};
18006 *
18007 * R.intersectionWith(sameId, buffaloSpringfield, csny);
18008 * //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}]
18009 */
18010 var intersectionWith = _curry3(function intersectionWith(pred, list1, list2) {
18011 var results = [], idx = -1;
18012 while (++idx < list1.length) {
18013 if (_containsWith(pred, list1[idx], list2)) {
18014 results[results.length] = list1[idx];
18015 }
18016 }
18017 return uniqWith(pred, results);
18018 });
18019
18020 /**
18021 * Creates a new list with the separator interposed between elements.
18022 *
18023 * @func
18024 * @memberOf R
18025 * @category List
18026 * @sig a -> [a] -> [a]
18027 * @param {*} separator The element to add to the list.
18028 * @param {Array} list The list to be interposed.
18029 * @return {Array} The new list.
18030 * @example
18031 *
18032 * R.intersperse('n', ['ba', 'a', 'a']); //=> ['ba', 'n', 'a', 'n', 'a']
18033 */
18034 var intersperse = _curry2(_checkForMethod('intersperse', function intersperse(separator, list) {
18035 var out = [];
18036 var idx = -1;
18037 var length = list.length;
18038 while (++idx < length) {
18039 if (idx === length - 1) {
18040 out.push(list[idx]);
18041 } else {
18042 out.push(list[idx], separator);
18043 }
18044 }
18045 return out;
18046 }));
18047
18048 /**
18049 * Returns the result of applying `obj[methodName]` to `args`.
18050 *
18051 * @func
18052 * @memberOf R
18053 * @category Object
18054 * @sig String -> [*] -> Object -> *
18055 * @param {String} methodName
18056 * @param {Array} args
18057 * @param {Object} obj
18058 * @return {*}
18059 * @example
18060 *
18061 * // toBinary :: Number -> String
18062 * var toBinary = R.invoke('toString', [2])
18063 *
18064 * toBinary(42); //=> '101010'
18065 * toBinary(63); //=> '111111'
18066 */
18067 var invoke = curry(function invoke(methodName, args, obj) {
18068 return obj[methodName].apply(obj, args);
18069 });
18070
18071 /**
18072 * Turns a named method with a specified arity into a function
18073 * that can be called directly supplied with arguments and a target object.
18074 *
18075 * The returned function is curried and accepts `len + 1` parameters where
18076 * the final parameter is the target object.
18077 *
18078 * @func
18079 * @memberOf R
18080 * @category Function
18081 * @sig (Number, String) -> (a... -> c -> b)
18082 * @param {Number} len Number of arguments the returned function should take
18083 * before the target object.
18084 * @param {Function} method Name of the method to call.
18085 * @return {Function} A new curried function.
18086 * @example
18087 *
18088 * var sliceFrom = R.invoker(1, 'slice');
18089 * sliceFrom(6, 'abcdefghijklm'); //=> 'ghijklm'
18090 * var sliceFrom6 = R.invoker(2, 'slice', 6);
18091 * sliceFrom6(8, 'abcdefghijklm'); //=> 'gh'
18092 */
18093 var invoker = curry(function invoker(arity, method) {
18094 var initialArgs = _slice(arguments, 2);
18095 var len = arity - initialArgs.length;
18096 return curryN(len + 1, function () {
18097 var target = arguments[len];
18098 var args = initialArgs.concat(_slice(arguments, 0, len));
18099 return target[method].apply(target, args);
18100 });
18101 });
18102
18103 /**
18104 * Returns a string made by inserting the `separator` between each
18105 * element and concatenating all the elements into a single string.
18106 *
18107 * @func
18108 * @memberOf R
18109 * @category List
18110 * @sig String -> [a] -> String
18111 * @param {Number|String} separator The string used to separate the elements.
18112 * @param {Array} xs The elements to join into a string.
18113 * @return {String} str The string made by concatenating `xs` with `separator`.
18114 * @example
18115 *
18116 * var spacer = R.join(' ');
18117 * spacer(['a', 2, 3.4]); //=> 'a 2 3.4'
18118 * R.join('|', [1, 2, 3]); //=> '1|2|3'
18119 */
18120 var join = invoker(1, 'join');
18121
18122 /**
18123 * Returns a list containing the names of all the enumerable own
18124 * properties of the supplied object.
18125 * Note that the order of the output array is not guaranteed to be
18126 * consistent across different JS platforms.
18127 *
18128 * @func
18129 * @memberOf R
18130 * @category Object
18131 * @sig {k: v} -> [k]
18132 * @param {Object} obj The object to extract properties from
18133 * @return {Array} An array of the object's own properties.
18134 * @example
18135 *
18136 * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c']
18137 */
18138 // cover IE < 9 keys issues
18139 var keys = function () {
18140 // cover IE < 9 keys issues
18141 var hasEnumBug = !{ toString: null }.propertyIsEnumerable('toString');
18142 var nonEnumerableProps = [
18143 'constructor',
18144 'valueOf',
18145 'isPrototypeOf',
18146 'toString',
18147 'propertyIsEnumerable',
18148 'hasOwnProperty',
18149 'toLocaleString'
18150 ];
18151 return _curry1(function keys(obj) {
18152 if (Object(obj) !== obj) {
18153 return [];
18154 }
18155 if (Object.keys) {
18156 return Object.keys(obj);
18157 }
18158 var prop, ks = [], nIdx;
18159 for (prop in obj) {
18160 if (_has(prop, obj)) {
18161 ks[ks.length] = prop;
18162 }
18163 }
18164 if (hasEnumBug) {
18165 nIdx = nonEnumerableProps.length;
18166 while (--nIdx >= 0) {
18167 prop = nonEnumerableProps[nIdx];
18168 if (_has(prop, obj) && !_contains(prop, ks)) {
18169 ks[ks.length] = prop;
18170 }
18171 }
18172 }
18173 return ks;
18174 });
18175 }();
18176
18177 /**
18178 * Returns the last element from a list.
18179 *
18180 * @func
18181 * @memberOf R
18182 * @category List
18183 * @sig [a] -> a
18184 * @param {Array} list The array to consider.
18185 * @return {*} The last element of the list, or `undefined` if the list is empty.
18186 * @example
18187 *
18188 * R.last(['fi', 'fo', 'fum']); //=> 'fum'
18189 */
18190 var last = nth(-1);
18191
18192 /**
18193 * Creates a lens that will focus on index `n` of the source array.
18194 *
18195 * @func
18196 * @memberOf R
18197 * @category List
18198 * @see R.lens
18199 * @sig Number -> (a -> b)
18200 * @param {Number} n The index of the array that the returned lens will focus on.
18201 * @return {Function} the returned function has `set` and `map` properties that are
18202 * also curried functions.
18203 * @example
18204 *
18205 * var headLens = R.lensIndex(0);
18206 * headLens([10, 20, 30, 40]); //=> 10
18207 * headLens.set('mu', [10, 20, 30, 40]); //=> ['mu', 20, 30, 40]
18208 * headLens.map(function(x) { return x + 1; }, [10, 20, 30, 40]); //=> [11, 20, 30, 40]
18209 */
18210 var lensIndex = function lensIndex(n) {
18211 return lens(nth(n), function (x, xs) {
18212 return _slice(xs, 0, n).concat([x], _slice(xs, n + 1));
18213 });
18214 };
18215
18216 /**
18217 * Creates a lens that will focus on property `k` of the source object.
18218 *
18219 * @func
18220 * @memberOf R
18221 * @category Object
18222 * @see R.lens
18223 * @sig String -> (a -> b)
18224 * @param {String} k A string that represents a property to focus on.
18225 * @return {Function} the returned function has `set` and `map` properties that are
18226 * also curried functions.
18227 * @example
18228 *
18229 * var phraseLens = R.lensProp('phrase');
18230 * var obj1 = { phrase: 'Absolute filth . . . and I LOVED it!'};
18231 * var obj2 = { phrase: "What's all this, then?"};
18232 * phraseLens(obj1); // => 'Absolute filth . . . and I LOVED it!'
18233 * phraseLens(obj2); // => "What's all this, then?"
18234 * phraseLens.set('Ooh Betty', obj1); //=> { phrase: 'Ooh Betty'}
18235 * phraseLens.map(R.toUpper, obj2); //=> { phrase: "WHAT'S ALL THIS, THEN?"}
18236 */
18237 var lensProp = function (k) {
18238 return lens(prop(k), assoc(k));
18239 };
18240
18241 /**
18242 * Returns a new list, constructed by applying the supplied function to every element of the
18243 * supplied list.
18244 *
18245 * Note: `R.map` does not skip deleted or unassigned indices (sparse arrays), unlike the
18246 * native `Array.prototype.map` method. For more details on this behavior, see:
18247 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#Description
18248 *
18249 * Acts as a transducer if a transformer is given in list position.
18250 * @see R.transduce
18251 *
18252 * @func
18253 * @memberOf R
18254 * @category List
18255 * @sig (a -> b) -> [a] -> [b]
18256 * @param {Function} fn The function to be called on every element of the input `list`.
18257 * @param {Array} list The list to be iterated over.
18258 * @return {Array} The new list.
18259 * @example
18260 *
18261 * var double = function(x) {
18262 * return x * 2;
18263 * };
18264 *
18265 * R.map(double, [1, 2, 3]); //=> [2, 4, 6]
18266 */
18267 var map = _curry2(_dispatchable('map', _xmap, _map));
18268
18269 /**
18270 * Map, but for objects. Creates an object with the same keys as `obj` and values
18271 * generated by running each property of `obj` through `fn`. `fn` is passed one argument:
18272 * *(value)*.
18273 *
18274 * @func
18275 * @memberOf R
18276 * @category Object
18277 * @sig (v -> v) -> {k: v} -> {k: v}
18278 * @param {Function} fn A function called for each property in `obj`. Its return value will
18279 * become a new property on the return object.
18280 * @param {Object} obj The object to iterate over.
18281 * @return {Object} A new object with the same keys as `obj` and values that are the result
18282 * of running each property through `fn`.
18283 * @example
18284 *
18285 * var values = { x: 1, y: 2, z: 3 };
18286 * var double = function(num) {
18287 * return num * 2;
18288 * };
18289 *
18290 * R.mapObj(double, values); //=> { x: 2, y: 4, z: 6 }
18291 */
18292 var mapObj = _curry2(function mapObject(fn, obj) {
18293 return _reduce(function (acc, key) {
18294 acc[key] = fn(obj[key]);
18295 return acc;
18296 }, {}, keys(obj));
18297 });
18298
18299 /**
18300 * Like `mapObj`, but but passes additional arguments to the predicate function. The
18301 * predicate function is passed three arguments: *(value, key, obj)*.
18302 *
18303 * @func
18304 * @memberOf R
18305 * @category Object
18306 * @sig (v, k, {k: v} -> v) -> {k: v} -> {k: v}
18307 * @param {Function} fn A function called for each property in `obj`. Its return value will
18308 * become a new property on the return object.
18309 * @param {Object} obj The object to iterate over.
18310 * @return {Object} A new object with the same keys as `obj` and values that are the result
18311 * of running each property through `fn`.
18312 * @example
18313 *
18314 * var values = { x: 1, y: 2, z: 3 };
18315 * var prependKeyAndDouble = function(num, key, obj) {
18316 * return key + (num * 2);
18317 * };
18318 *
18319 * R.mapObjIndexed(prependKeyAndDouble, values); //=> { x: 'x2', y: 'y4', z: 'z6' }
18320 */
18321 var mapObjIndexed = _curry2(function mapObjectIndexed(fn, obj) {
18322 return _reduce(function (acc, key) {
18323 acc[key] = fn(obj[key], key, obj);
18324 return acc;
18325 }, {}, keys(obj));
18326 });
18327
18328 /**
18329 * Tests a regular expression against a String
18330 *
18331 * @func
18332 * @memberOf R
18333 * @category String
18334 * @sig RegExp -> String -> [String] | null
18335 * @param {RegExp} rx A regular expression.
18336 * @param {String} str The string to match against
18337 * @return {Array} The list of matches, or null if no matches found.
18338 * @see R.invoker
18339 * @example
18340 *
18341 * R.match(/([a-z]a)/g, 'bananas'); //=> ['ba', 'na', 'na']
18342 */
18343 var match = invoker(1, 'match');
18344
18345 /**
18346 * Determines the largest of a list of numbers (or elements that can be cast to numbers)
18347 *
18348 * @func
18349 * @memberOf R
18350 * @category Math
18351 * @sig [Number] -> Number
18352 * @see R.maxBy
18353 * @param {Array} list A list of numbers
18354 * @return {Number} The greatest number in the list.
18355 * @example
18356 *
18357 * R.max([7, 3, 9, 2, 4, 9, 3]); //=> 9
18358 */
18359 var max = _createMaxMin(_gt, -Infinity);
18360
18361 /**
18362 * Determines the smallest of a list of numbers (or elements that can be cast to numbers)
18363 *
18364 * @func
18365 * @memberOf R
18366 * @category Math
18367 * @sig [Number] -> Number
18368 * @param {Array} list A list of numbers
18369 * @return {Number} The greatest number in the list.
18370 * @see R.minBy
18371 * @example
18372 *
18373 * R.min([7, 3, 9, 2, 4, 9, 3]); //=> 2
18374 */
18375 var min = _createMaxMin(_lt, Infinity);
18376
18377 /**
18378 * Returns `true` if no elements of the list match the predicate,
18379 * `false` otherwise.
18380 *
18381 * @func
18382 * @memberOf R
18383 * @category List
18384 * @sig (a -> Boolean) -> [a] -> Boolean
18385 * @param {Function} fn The predicate function.
18386 * @param {Array} list The array to consider.
18387 * @return {Boolean} `true` if the predicate is not satisfied by every element, `false` otherwise.
18388 * @example
18389 *
18390 * R.none(R.isNaN, [1, 2, 3]); //=> true
18391 * R.none(R.isNaN, [1, 2, 3, NaN]); //=> false
18392 */
18393 var none = _curry2(_complement(_dispatchable('any', _xany, _any)));
18394
18395 /**
18396 * A function that returns the first truthy of two arguments otherwise the
18397 * last argument. Note that this is NOT short-circuited, meaning that if
18398 * expressions are passed they are both evaluated.
18399 *
18400 * Dispatches to the `or` method of the first argument if applicable.
18401 *
18402 * @func
18403 * @memberOf R
18404 * @category Logic
18405 * @sig * -> * -> *
18406 * @param {*} a any value
18407 * @param {*} b any other value
18408 * @return {*} the first truthy argument, otherwise the last argument.
18409 * @example
18410 *
18411 * R.or(false, true); //=> true
18412 * R.or(0, []); //=> []
18413 * R.or(null, ''); => ''
18414 */
18415 var or = _curry2(function or(a, b) {
18416 return _hasMethod('or', a) ? a.or(b) : a || b;
18417 });
18418
18419 /**
18420 * Accepts as its arguments a function and any number of values and returns a function that,
18421 * when invoked, calls the original function with all of the values prepended to the
18422 * original function's arguments list. In some libraries this function is named `applyLeft`.
18423 *
18424 * @func
18425 * @memberOf R
18426 * @category Function
18427 * @sig (a -> b -> ... -> i -> j -> ... -> m -> n) -> a -> b-> ... -> i -> (j -> ... -> m -> n)
18428 * @param {Function} fn The function to invoke.
18429 * @param {...*} [args] Arguments to prepend to `fn` when the returned function is invoked.
18430 * @return {Function} A new function wrapping `fn`. When invoked, it will call `fn`
18431 * with `args` prepended to `fn`'s arguments list.
18432 * @example
18433 *
18434 * var multiply = function(a, b) { return a * b; };
18435 * var double = R.partial(multiply, 2);
18436 * double(2); //=> 4
18437 *
18438 * var greet = function(salutation, title, firstName, lastName) {
18439 * return salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
18440 * };
18441 * var sayHello = R.partial(greet, 'Hello');
18442 * var sayHelloToMs = R.partial(sayHello, 'Ms.');
18443 * sayHelloToMs('Jane', 'Jones'); //=> 'Hello, Ms. Jane Jones!'
18444 */
18445 var partial = curry(_createPartialApplicator(_concat));
18446
18447 /**
18448 * Accepts as its arguments a function and any number of values and returns a function that,
18449 * when invoked, calls the original function with all of the values appended to the original
18450 * function's arguments list.
18451 *
18452 * Note that `partialRight` is the opposite of `partial`: `partialRight` fills `fn`'s arguments
18453 * from the right to the left. In some libraries this function is named `applyRight`.
18454 *
18455 * @func
18456 * @memberOf R
18457 * @category Function
18458 * @sig (a -> b-> ... -> i -> j -> ... -> m -> n) -> j -> ... -> m -> n -> (a -> b-> ... -> i)
18459 * @param {Function} fn The function to invoke.
18460 * @param {...*} [args] Arguments to append to `fn` when the returned function is invoked.
18461 * @return {Function} A new function wrapping `fn`. When invoked, it will call `fn` with
18462 * `args` appended to `fn`'s arguments list.
18463 * @example
18464 *
18465 * var greet = function(salutation, title, firstName, lastName) {
18466 * return salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
18467 * };
18468 * var greetMsJaneJones = R.partialRight(greet, 'Ms.', 'Jane', 'Jones');
18469 *
18470 * greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!'
18471 */
18472 var partialRight = curry(_createPartialApplicator(flip(_concat)));
18473
18474 /**
18475 * Takes a predicate and a list and returns the pair of lists of
18476 * elements which do and do not satisfy the predicate, respectively.
18477 *
18478 * @func
18479 * @memberOf R
18480 * @category List
18481 * @sig (a -> Boolean) -> [a] -> [[a],[a]]
18482 * @param {Function} pred A predicate to determine which array the element belongs to.
18483 * @param {Array} list The array to partition.
18484 * @return {Array} A nested array, containing first an array of elements that satisfied the predicate,
18485 * and second an array of elements that did not satisfy.
18486 * @example
18487 *
18488 * R.partition(R.contains('s'), ['sss', 'ttt', 'foo', 'bars']);
18489 * //=> [ [ 'sss', 'bars' ], [ 'ttt', 'foo' ] ]
18490 */
18491 var partition = _curry2(function partition(pred, list) {
18492 return _reduce(function (acc, elt) {
18493 var xs = acc[pred(elt) ? 0 : 1];
18494 xs[xs.length] = elt;
18495 return acc;
18496 }, [
18497 [],
18498 []
18499 ], list);
18500 });
18501
18502 /**
18503 * Creates a new function that runs each of the functions supplied as parameters in turn,
18504 * passing the return value of each function invocation to the next function invocation,
18505 * beginning with whatever arguments were passed to the initial invocation.
18506 *
18507 * `pipe` is the mirror version of `compose`. `pipe` is left-associative, which means that
18508 * each of the functions provided is executed in order from left to right.
18509 *
18510 * In some libraries this function is named `sequence`.
18511 * @func
18512 * @memberOf R
18513 * @category Function
18514 * @sig ((a... -> b), (b -> c), ..., (x -> y), (y -> z)) -> (a... -> z)
18515 * @param {...Function} functions A variable number of functions.
18516 * @return {Function} A new function which represents the result of calling each of the
18517 * input `functions`, passing the result of each function call to the next, from
18518 * left to right.
18519 * @example
18520 *
18521 * var triple = function(x) { return x * 3; };
18522 * var double = function(x) { return x * 2; };
18523 * var square = function(x) { return x * x; };
18524 * var squareThenDoubleThenTriple = R.pipe(square, double, triple);
18525 *
18526 * //≅ triple(double(square(5)))
18527 * squareThenDoubleThenTriple(5); //=> 150
18528 */
18529 var pipe = function pipe() {
18530 return compose.apply(this, reverse(arguments));
18531 };
18532
18533 /**
18534 * Creates a new lens that allows getting and setting values of nested properties, by
18535 * following each given lens in succession.
18536 *
18537 * `pipeL` is the mirror version of `composeL`. `pipeL` is left-associative, which means that
18538 * each of the functions provided is executed in order from left to right.
18539 *
18540 * @func
18541 * @memberOf R
18542 * @category Function
18543 * @see R.lens
18544 * @sig ((a -> b), (b -> c), ..., (x -> y), (y -> z)) -> (a -> z)
18545 * @param {...Function} lenses A variable number of lenses.
18546 * @return {Function} A new lens which represents the result of calling each of the
18547 * input `lenses`, passing the result of each getter/setter as the source
18548 * to the next, from right to left.
18549 * @example
18550 *
18551 * var headLens = R.lensIndex(0);
18552 * var secondLens = R.lensIndex(1);
18553 * var xLens = R.lensProp('x');
18554 * var headThenXThenSecondLens = R.pipeL(headLens, xLens, secondLens);
18555 *
18556 * var source = [{x: [0, 1], y: [2, 3]}, {x: [4, 5], y: [6, 7]}];
18557 * headThenXThenSecondLens(source); //=> 1
18558 * headThenXThenSecondLens.set(123, source); //=> [{x: [0, 123], y: [2, 3]}, {x: [4, 5], y: [6, 7]}]
18559 */
18560 var pipeL = compose(apply(composeL), unapply(reverse));
18561
18562 /**
18563 * Creates a new function that runs each of the functions supplied as parameters in turn,
18564 * passing to the next function invocation either the value returned by the previous
18565 * function or the resolved value if the returned value is a promise. In other words,
18566 * if some of the functions in the sequence return promises, `pipeP` pipes the values
18567 * asynchronously. If none of the functions return promises, the behavior is the same as
18568 * that of `pipe`.
18569 *
18570 * `pipeP` is the mirror version of `composeP`. `pipeP` is left-associative, which means that
18571 * each of the functions provided is executed in order from left to right.
18572 *
18573 * @func
18574 * @memberOf R
18575 * @category Function
18576 * @sig ((a... -> b), (b -> c), ..., (x -> y), (y -> z)) -> (a... -> z)
18577 * @param {...Function} functions A variable number of functions.
18578 * @return {Function} A new function which represents the result of calling each of the
18579 * input `functions`, passing either the returned result or the asynchronously
18580 * resolved value) of each function call to the next, from left to right.
18581 * @example
18582 *
18583 * var Q = require('q');
18584 * var triple = function(x) { return x * 3; };
18585 * var double = function(x) { return x * 2; };
18586 * var squareAsync = function(x) { return Q.when(x * x); };
18587 * var squareAsyncThenDoubleThenTriple = R.pipeP(squareAsync, double, triple);
18588 *
18589 * //≅ squareAsync(5).then(function(x) { return triple(double(x)) };
18590 * squareAsyncThenDoubleThenTriple(5)
18591 * .then(function(result) {
18592 * // result is 150
18593 * });
18594 */
18595 var pipeP = function pipeP() {
18596 return composeP.apply(this, reverse(arguments));
18597 };
18598
18599 /**
18600 * Returns a single item by iterating through the list, successively calling the iterator
18601 * function and passing it an accumulator value and the current value from the array, and
18602 * then passing the result to the next call.
18603 *
18604 * The iterator function receives two values: *(acc, value)*
18605 *
18606 * Note: `R.reduce` does not skip deleted or unassigned indices (sparse arrays), unlike
18607 * the native `Array.prototype.reduce` method. For more details on this behavior, see:
18608 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description
18609 *
18610 * @func
18611 * @memberOf R
18612 * @category List
18613 * @sig (a,b -> a) -> a -> [b] -> a
18614 * @param {Function} fn The iterator function. Receives two values, the accumulator and the
18615 * current element from the array.
18616 * @param {*} acc The accumulator value.
18617 * @param {Array} list The list to iterate over.
18618 * @return {*} The final, accumulated value.
18619 * @example
18620 *
18621 * var numbers = [1, 2, 3];
18622 * var add = function(a, b) {
18623 * return a + b;
18624 * };
18625 *
18626 * R.reduce(add, 10, numbers); //=> 16
18627 */
18628 var reduce = _curry3(_reduce);
18629
18630 /**
18631 * Similar to `filter`, except that it keeps only values for which the given predicate
18632 * function returns falsy. The predicate function is passed one argument: *(value)*.
18633 *
18634 * Acts as a transducer if a transformer is given in list position.
18635 * @see R.transduce
18636 *
18637 * @func
18638 * @memberOf R
18639 * @category List
18640 * @sig (a -> Boolean) -> [a] -> [a]
18641 * @param {Function} fn The function called per iteration.
18642 * @param {Array} list The collection to iterate over.
18643 * @return {Array} The new filtered array.
18644 * @example
18645 *
18646 * var isOdd = function(n) {
18647 * return n % 2 === 1;
18648 * };
18649 * R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4]
18650 */
18651 var reject = _curry2(function reject(fn, list) {
18652 return filter(_complement(fn), list);
18653 });
18654
18655 /**
18656 * Returns a fixed list of size `n` containing a specified identical value.
18657 *
18658 * @func
18659 * @memberOf R
18660 * @category List
18661 * @sig a -> n -> [a]
18662 * @param {*} value The value to repeat.
18663 * @param {Number} n The desired size of the output list.
18664 * @return {Array} A new array containing `n` `value`s.
18665 * @example
18666 *
18667 * R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi']
18668 *
18669 * var obj = {};
18670 * var repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}]
18671 * repeatedObjs[0] === repeatedObjs[1]; //=> true
18672 */
18673 var repeat = _curry2(function repeat(value, n) {
18674 return times(always(value), n);
18675 });
18676
18677 /**
18678 * Returns a list containing the elements of `xs` from `fromIndex` (inclusive)
18679 * to `toIndex` (exclusive).
18680 *
18681 * @func
18682 * @memberOf R
18683 * @category List
18684 * @sig Number -> Number -> [a] -> [a]
18685 * @param {Number} fromIndex The start index (inclusive).
18686 * @param {Number} toIndex The end index (exclusive).
18687 * @param {Array} xs The list to take elements from.
18688 * @return {Array} The slice of `xs` from `fromIndex` to `toIndex`.
18689 * @example
18690 *
18691 * var xs = R.range(0, 10);
18692 * R.slice(2, 5)(xs); //=> [2, 3, 4]
18693 */
18694 var slice = _curry3(_checkForMethod('slice', function slice(fromIndex, toIndex, xs) {
18695 return Array.prototype.slice.call(xs, fromIndex, toIndex);
18696 }));
18697
18698 /**
18699 * Splits a string into an array of strings based on the given
18700 * separator.
18701 *
18702 * @func
18703 * @memberOf R
18704 * @category String
18705 * @sig String -> String -> [String]
18706 * @param {String} sep The separator string.
18707 * @param {String} str The string to separate into an array.
18708 * @return {Array} The array of strings from `str` separated by `str`.
18709 * @example
18710 *
18711 * var pathComponents = R.split('/');
18712 * R.tail(pathComponents('/usr/local/bin/node')); //=> ['usr', 'local', 'bin', 'node']
18713 *
18714 * R.split('.', 'a.b.c.xyz.d'); //=> ['a', 'b', 'c', 'xyz', 'd']
18715 */
18716 var split = invoker(1, 'split');
18717
18718 /**
18719 * Returns a string containing the characters of `str` from `fromIndex`
18720 * (inclusive) to `toIndex` (exclusive).
18721 *
18722 * @func
18723 * @memberOf R
18724 * @category String
18725 * @sig Number -> Number -> String -> String
18726 * @param {Number} fromIndex The start index (inclusive).
18727 * @param {Number} toIndex The end index (exclusive).
18728 * @param {String} str The string to slice.
18729 * @return {String}
18730 * @see R.slice
18731 * @example
18732 *
18733 * R.substring(2, 5, 'abcdefghijklm'); //=> 'cde'
18734 */
18735 var substring = slice;
18736
18737 /**
18738 * Returns a string containing the characters of `str` from `fromIndex`
18739 * (inclusive) to the end of `str`.
18740 *
18741 * @func
18742 * @memberOf R
18743 * @category String
18744 * @sig Number -> String -> String
18745 * @param {Number} fromIndex
18746 * @param {String} str
18747 * @return {String}
18748 * @example
18749 *
18750 * R.substringFrom(3, 'Ramda'); //=> 'da'
18751 * R.substringFrom(-2, 'Ramda'); //=> 'da'
18752 */
18753 var substringFrom = substring(__, Infinity);
18754
18755 /**
18756 * Returns a string containing the first `toIndex` characters of `str`.
18757 *
18758 * @func
18759 * @memberOf R
18760 * @category String
18761 * @sig Number -> String -> String
18762 * @param {Number} toIndex
18763 * @param {String} str
18764 * @return {String}
18765 * @example
18766 *
18767 * R.substringTo(3, 'Ramda'); //=> 'Ram'
18768 * R.substringTo(-2, 'Ramda'); //=> 'Ram'
18769 */
18770 var substringTo = substring(0);
18771
18772 /**
18773 * Adds together all the elements of a list.
18774 *
18775 * @func
18776 * @memberOf R
18777 * @category Math
18778 * @sig [Number] -> Number
18779 * @param {Array} list An array of numbers
18780 * @return {Number} The sum of all the numbers in the list.
18781 * @see reduce
18782 * @example
18783 *
18784 * R.sum([2,4,6,8,100,1]); //=> 121
18785 */
18786 var sum = reduce(_add, 0);
18787
18788 /**
18789 * Returns all but the first element of a list. If the list provided has the `tail` method,
18790 * it will instead return `list.tail()`.
18791 *
18792 * @func
18793 * @memberOf R
18794 * @category List
18795 * @sig [a] -> [a]
18796 * @param {Array} list The array to consider.
18797 * @return {Array} A new array containing all but the first element of the input list, or an
18798 * empty list if the input list is empty.
18799 * @example
18800 *
18801 * R.tail(['fi', 'fo', 'fum']); //=> ['fo', 'fum']
18802 */
18803 var tail = _checkForMethod('tail', function (list) {
18804 return _slice(list, 1);
18805 });
18806
18807 /**
18808 * Returns a new list containing the first `n` elements of the given list. If
18809 * `n > * list.length`, returns a list of `list.length` elements.
18810 *
18811 * Acts as a transducer if a transformer is given in list position.
18812 * @see R.transduce
18813 *
18814 * @func
18815 * @memberOf R
18816 * @category List
18817 * @sig Number -> [a] -> [a]
18818 * @param {Number} n The number of elements to return.
18819 * @param {Array} list The array to query.
18820 * @return {Array} A new array containing the first elements of `list`.
18821 * @example
18822 *
18823 * R.take(3,[1,2,3,4,5]); //=> [1,2,3]
18824 *
18825 * var members= [ "Paul Desmond","Bob Bates","Joe Dodge","Ron Crotty","Lloyd Davis","Joe Morello","Norman Bates",
18826 * "Eugene Wright","Gerry Mulligan","Jack Six","Alan Dawson","Darius Brubeck","Chris Brubeck",
18827 * "Dan Brubeck","Bobby Militello","Michael Moore","Randy Jones"];
18828 * var takeFive = R.take(5);
18829 * takeFive(members); //=> ["Paul Desmond","Bob Bates","Joe Dodge","Ron Crotty","Lloyd Davis"]
18830 */
18831 var take = _curry2(_dispatchable('take', _xtake, function take(n, list) {
18832 return _slice(list, 0, n);
18833 }));
18834
18835 /**
18836 * Returns a new list containing the first `n` elements of a given list, passing each value
18837 * to the supplied predicate function, and terminating when the predicate function returns
18838 * `false`. Excludes the element that caused the predicate function to fail. The predicate
18839 * function is passed one argument: *(value)*.
18840 *
18841 * Acts as a transducer if a transformer is given in list position.
18842 * @see R.transduce
18843 *
18844 * @func
18845 * @memberOf R
18846 * @category List
18847 * @sig (a -> Boolean) -> [a] -> [a]
18848 * @param {Function} fn The function called per iteration.
18849 * @param {Array} list The collection to iterate over.
18850 * @return {Array} A new array.
18851 * @example
18852 *
18853 * var isNotFour = function(x) {
18854 * return !(x === 4);
18855 * };
18856 *
18857 * R.takeWhile(isNotFour, [1, 2, 3, 4]); //=> [1, 2, 3]
18858 */
18859 var takeWhile = _curry2(_dispatchable('takeWhile', _xtakeWhile, function takeWhile(fn, list) {
18860 var idx = -1, len = list.length;
18861 while (++idx < len && fn(list[idx])) {
18862 }
18863 return _slice(list, 0, idx);
18864 }));
18865
18866 /**
18867 * The lower case version of a string.
18868 *
18869 * @func
18870 * @memberOf R
18871 * @category String
18872 * @sig String -> String
18873 * @param {String} str The string to lower case.
18874 * @return {String} The lower case version of `str`.
18875 * @example
18876 *
18877 * R.toLower('XYZ'); //=> 'xyz'
18878 */
18879 var toLower = invoker(0, 'toLowerCase');
18880
18881 /**
18882 * The upper case version of a string.
18883 *
18884 * @func
18885 * @memberOf R
18886 * @category String
18887 * @sig String -> String
18888 * @param {String} str The string to upper case.
18889 * @return {String} The upper case version of `str`.
18890 * @example
18891 *
18892 * R.toUpper('abc'); //=> 'ABC'
18893 */
18894 var toUpper = invoker(0, 'toUpperCase');
18895
18896 /**
18897 * Initializes a transducer using supplied iterator function. Returns a single item by
18898 * iterating through the list, successively calling the transformed iterator function and
18899 * passing it an accumulator value and the current value from the array, and then passing
18900 * the result to the next call.
18901 *
18902 * The iterator function receives two values: *(acc, value)*. It will be wrapped as a
18903 * transformer to initialize the transducer. A transformer can be passed directly in place
18904 * of an iterator function.
18905 *
18906 * A transducer is a function that accepts a transformer and returns a transformer and can
18907 * be composed directly.
18908 *
18909 * A transformer is an an object that provides a 2-arity reducing iterator function, step,
18910 * 0-arity initial value function, init, and 1-arity result extraction function, result.
18911 * The step function is used as the iterator function in reduce. The result function is used
18912 * to convert the final accumulator into the return type and in most cases is R.identity.
18913 * The init function can be used to provide an initial accumulator, but is ignored by transduce.
18914 *
18915 * The iteration is performed with R.reduce after initializing the transducer.
18916 *
18917 * @func
18918 * @memberOf R
18919 * @category List
18920 * @sig (c -> c) -> (a,b -> a) -> a -> [b] -> a
18921 * @param {Function} xf The transducer function. Receives a transformer and returns a transformer.
18922 * @param {Function} fn The iterator function. Receives two values, the accumulator and the
18923 * current element from the array. Wrapped as transformer, if necessary, and used to
18924 * initialize the transducer
18925 * @param {*} acc The initial accumulator value.
18926 * @param {Array} list The list to iterate over.
18927 * @see R.into
18928 * @return {*} The final, accumulated value.
18929 * @example
18930 *
18931 * var numbers = [1, 2, 3, 4];
18932 * var transducer = R.compose(R.map(R.add(1)), R.take(2));
18933 *
18934 * R.transduce(transducer, R.flip(R.append), [], numbers); //=> [2, 3]
18935 */
18936 var transduce = curryN(4, function (xf, fn, acc, list) {
18937 return _reduce(xf(typeof fn === 'function' ? _xwrap(fn) : fn), acc, list);
18938 });
18939
18940 /**
18941 * Combines two lists into a set (i.e. no duplicates) composed of the elements of each list. Duplication is
18942 * determined according to the value returned by applying the supplied predicate to two list elements.
18943 *
18944 * @func
18945 * @memberOf R
18946 * @category Relation
18947 * @sig (a,a -> Boolean) -> [a] -> [a] -> [a]
18948 * @param {Function} pred A predicate used to test whether two items are equal.
18949 * @param {Array} list1 The first list.
18950 * @param {Array} list2 The second list.
18951 * @return {Array} The first and second lists concatenated, with
18952 * duplicates removed.
18953 * @see R.union
18954 * @example
18955 *
18956 * function cmp(x, y) { return x.a === y.a; }
18957 * var l1 = [{a: 1}, {a: 2}];
18958 * var l2 = [{a: 1}, {a: 4}];
18959 * R.unionWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}, {a: 4}]
18960 */
18961 var unionWith = _curry3(function unionWith(pred, list1, list2) {
18962 return uniqWith(pred, _concat(list1, list2));
18963 });
18964
18965 /**
18966 * Returns a new list containing only one copy of each element in the original list.
18967 * Equality is strict here, meaning reference equality for objects and non-coercing equality
18968 * for primitives.
18969 *
18970 * @func
18971 * @memberOf R
18972 * @category List
18973 * @sig [a] -> [a]
18974 * @param {Array} list The array to consider.
18975 * @return {Array} The list of unique items.
18976 * @example
18977 *
18978 * R.uniq([1, 1, 2, 1]); //=> [1, 2]
18979 * R.uniq([{}, {}]); //=> [{}, {}]
18980 * R.uniq([1, '1']); //=> [1, '1']
18981 */
18982 var uniq = uniqWith(eq);
18983
18984 /**
18985 * Returns a new list by pulling every item at the first level of nesting out, and putting
18986 * them in a new array.
18987 *
18988 * @func
18989 * @memberOf R
18990 * @category List
18991 * @sig [a] -> [b]
18992 * @param {Array} list The array to consider.
18993 * @return {Array} The flattened list.
18994 * @example
18995 *
18996 * R.unnest([1, [2], [[3]]]); //=> [1, 2, [3]]
18997 * R.unnest([[1, 2], [3, 4], [5, 6]]); //=> [1, 2, 3, 4, 5, 6]
18998 */
18999 var unnest = _curry1(_makeFlat(false));
19000
19001 /**
19002 * Accepts a function `fn` and any number of transformer functions and returns a new
19003 * function. When the new function is invoked, it calls the function `fn` with parameters
19004 * consisting of the result of calling each supplied handler on successive arguments to the
19005 * new function.
19006 *
19007 * If more arguments are passed to the returned function than transformer functions, those
19008 * arguments are passed directly to `fn` as additional parameters. If you expect additional
19009 * arguments that don't need to be transformed, although you can ignore them, it's best to
19010 * pass an identity function so that the new function reports the correct arity.
19011 *
19012 * @func
19013 * @memberOf R
19014 * @category Function
19015 * @sig (x1 -> x2 -> ... -> z) -> ((a -> x1), (b -> x2), ...) -> (a -> b -> ... -> z)
19016 * @param {Function} fn The function to wrap.
19017 * @param {...Function} transformers A variable number of transformer functions
19018 * @return {Function} The wrapped function.
19019 * @example
19020 *
19021 * // Example 1:
19022 *
19023 * // Number -> [Person] -> [Person]
19024 * var byAge = R.useWith(R.filter, R.propEq('age'), R.identity);
19025 *
19026 * var kids = [
19027 * {name: 'Abbie', age: 6},
19028 * {name: 'Brian', age: 5},
19029 * {name: 'Chris', age: 6},
19030 * {name: 'David', age: 4},
19031 * {name: 'Ellie', age: 5}
19032 * ];
19033 *
19034 * byAge(5, kids); //=> [{name: 'Brian', age: 5}, {name: 'Ellie', age: 5}]
19035 *
19036 * // Example 2:
19037 *
19038 * var double = function(y) { return y * 2; };
19039 * var square = function(x) { return x * x; };
19040 * var add = function(a, b) { return a + b; };
19041 * // Adds any number of arguments together
19042 * var addAll = function() {
19043 * return R.reduce(add, 0, arguments);
19044 * };
19045 *
19046 * // Basic example
19047 * var addDoubleAndSquare = R.useWith(addAll, double, square);
19048 *
19049 * //≅ addAll(double(10), square(5));
19050 * addDoubleAndSquare(10, 5); //=> 45
19051 *
19052 * // Example of passing more arguments than transformers
19053 * //≅ addAll(double(10), square(5), 100);
19054 * addDoubleAndSquare(10, 5, 100); //=> 145
19055 *
19056 * // If there are extra _expected_ arguments that don't need to be transformed, although
19057 * // you can ignore them, it might be best to pass in the identity function so that the new
19058 * // function correctly reports arity.
19059 * var addDoubleAndSquareWithExtraParams = R.useWith(addAll, double, square, R.identity);
19060 * // addDoubleAndSquareWithExtraParams.length //=> 3
19061 * //≅ addAll(double(10), square(5), R.identity(100));
19062 * addDoubleAndSquare(10, 5, 100); //=> 145
19063 */
19064 /*, transformers */
19065 var useWith = curry(function useWith(fn) {
19066 var transformers = _slice(arguments, 1);
19067 var tlen = transformers.length;
19068 return curry(arity(tlen, function () {
19069 var args = [], idx = -1;
19070 while (++idx < tlen) {
19071 args[idx] = transformers[idx](arguments[idx]);
19072 }
19073 return fn.apply(this, args.concat(_slice(arguments, tlen)));
19074 }));
19075 });
19076
19077 /**
19078 * Returns a list of all the enumerable own properties of the supplied object.
19079 * Note that the order of the output array is not guaranteed across
19080 * different JS platforms.
19081 *
19082 * @func
19083 * @memberOf R
19084 * @category Object
19085 * @sig {k: v} -> [v]
19086 * @param {Object} obj The object to extract values from
19087 * @return {Array} An array of the values of the object's own properties.
19088 * @example
19089 *
19090 * R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3]
19091 */
19092 var values = _curry1(function values(obj) {
19093 var props = keys(obj);
19094 var len = props.length;
19095 var vals = [];
19096 var idx = -1;
19097 while (++idx < len) {
19098 vals[idx] = obj[props[idx]];
19099 }
19100 return vals;
19101 });
19102
19103 /**
19104 * Takes a spec object and a test object; returns true if the test satisfies
19105 * the spec, false otherwise. An object satisfies the spec if, for each of the
19106 * spec's own properties, accessing that property of the object gives the same
19107 * value (in `R.eq` terms) as accessing that property of the spec.
19108 *
19109 * `whereEq` is a specialization of [`where`](#where).
19110 *
19111 * @func
19112 * @memberOf R
19113 * @category Object
19114 * @sig {String: *} -> {String: *} -> Boolean
19115 * @param {Object} spec
19116 * @param {Object} testObj
19117 * @return {Boolean}
19118 * @see R.where
19119 * @example
19120 *
19121 * // pred :: Object -> Boolean
19122 * var pred = R.where({a: 1, b: 2});
19123 *
19124 * pred({a: 1}); //=> false
19125 * pred({a: 1, b: 2}); //=> true
19126 * pred({a: 1, b: 2, c: 3}); //=> true
19127 * pred({a: 1, b: 1}); //=> false
19128 */
19129 var whereEq = _curry2(function whereEq(spec, testObj) {
19130 return where(mapObj(eq, spec), testObj);
19131 });
19132
19133 // The algorithm used to handle cyclic structures is
19134 // inspired by underscore's isEqual
19135 // RegExp equality algorithm: http://stackoverflow.com/a/10776635
19136 var _eqDeep = function _eqDeep(a, b, stackA, stackB) {
19137 var typeA = type(a);
19138 if (typeA !== type(b)) {
19139 return false;
19140 }
19141 if (eq(a, b)) {
19142 return true;
19143 }
19144 if (typeA == 'RegExp') {
19145 // RegExp equality algorithm: http://stackoverflow.com/a/10776635
19146 return a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.sticky === b.sticky && a.unicode === b.unicode;
19147 }
19148 if (Object(a) === a) {
19149 if (typeA === 'Date' && a.getTime() != b.getTime()) {
19150 return false;
19151 }
19152 var keysA = keys(a);
19153 if (keysA.length !== keys(b).length) {
19154 return false;
19155 }
19156 var idx = stackA.length;
19157 while (--idx >= 0) {
19158 if (stackA[idx] === a) {
19159 return stackB[idx] === b;
19160 }
19161 }
19162 stackA[stackA.length] = a;
19163 stackB[stackB.length] = b;
19164 idx = keysA.length;
19165 while (--idx >= 0) {
19166 var key = keysA[idx];
19167 if (!_has(key, b) || !_eqDeep(b[key], a[key], stackA, stackB)) {
19168 return false;
19169 }
19170 }
19171 stackA.pop();
19172 stackB.pop();
19173 return true;
19174 }
19175 return false;
19176 };
19177
19178 /**
19179 * Assigns own enumerable properties of the other object to the destination
19180 * object preferring items in other.
19181 *
19182 * @private
19183 * @memberOf R
19184 * @category Object
19185 * @param {Object} destination The destination object.
19186 * @param {Object} other The other object to merge with destination.
19187 * @return {Object} The destination object.
19188 * @example
19189 *
19190 * _extend({ 'name': 'fred', 'age': 10 }, { 'age': 40 });
19191 * //=> { 'name': 'fred', 'age': 40 }
19192 */
19193 var _extend = function _extend(destination, other) {
19194 var props = keys(other);
19195 var idx = -1, length = props.length;
19196 while (++idx < length) {
19197 destination[props[idx]] = other[props[idx]];
19198 }
19199 return destination;
19200 };
19201
19202 var _pluck = function _pluck(p, list) {
19203 return map(prop(p), list);
19204 };
19205
19206 /**
19207 * Create a predicate wrapper which will call a pick function (all/any) for each predicate
19208 *
19209 * @private
19210 * @see R.all
19211 * @see R.any
19212 */
19213 // Call function immediately if given arguments
19214 // Return a function which will call the predicates with the provided arguments
19215 var _predicateWrap = function _predicateWrap(predPicker) {
19216 return function (preds) {
19217 var predIterator = function () {
19218 var args = arguments;
19219 return predPicker(function (predicate) {
19220 return predicate.apply(null, args);
19221 }, preds);
19222 };
19223 return arguments.length > 1 ? // Call function immediately if given arguments
19224 predIterator.apply(null, _slice(arguments, 1)) : // Return a function which will call the predicates with the provided arguments
19225 arity(max(_pluck('length', preds)), predIterator);
19226 };
19227 };
19228
19229 // Function, RegExp, user-defined types
19230 var _toString = function _toString(x, seen) {
19231 var recur = function recur(y) {
19232 var xs = seen.concat([x]);
19233 return _indexOf(xs, y) >= 0 ? '<Circular>' : _toString(y, xs);
19234 };
19235 switch (Object.prototype.toString.call(x)) {
19236 case '[object Arguments]':
19237 return '(function() { return arguments; }(' + _map(recur, x).join(', ') + '))';
19238 case '[object Array]':
19239 return '[' + _map(recur, x).join(', ') + ']';
19240 case '[object Boolean]':
19241 return typeof x === 'object' ? 'new Boolean(' + recur(x.valueOf()) + ')' : x.toString();
19242 case '[object Date]':
19243 return 'new Date(' + _quote(_toISOString(x)) + ')';
19244 case '[object Null]':
19245 return 'null';
19246 case '[object Number]':
19247 return typeof x === 'object' ? 'new Number(' + recur(x.valueOf()) + ')' : 1 / x === -Infinity ? '-0' : x.toString(10);
19248 case '[object String]':
19249 return typeof x === 'object' ? 'new String(' + recur(x.valueOf()) + ')' : _quote(x);
19250 case '[object Undefined]':
19251 return 'undefined';
19252 default:
19253 return typeof x.constructor === 'function' && x.constructor.name !== 'Object' && typeof x.toString === 'function' && x.toString() !== '[object Object]' ? x.toString() : // Function, RegExp, user-defined types
19254 '{' + _map(function (k) {
19255 return _quote(k) + ': ' + recur(x[k]);
19256 }, keys(x).sort()).join(', ') + '}';
19257 }
19258 };
19259
19260 /**
19261 * Given a list of predicates, returns a new predicate that will be true exactly when all of them are.
19262 *
19263 * @func
19264 * @memberOf R
19265 * @category Logic
19266 * @sig [(*... -> Boolean)] -> (*... -> Boolean)
19267 * @param {Array} list An array of predicate functions
19268 * @param {*} optional Any arguments to pass into the predicates
19269 * @return {Function} a function that applies its arguments to each of
19270 * the predicates, returning `true` if all are satisfied.
19271 * @example
19272 *
19273 * var gt10 = function(x) { return x > 10; };
19274 * var even = function(x) { return x % 2 === 0};
19275 * var f = R.allPass([gt10, even]);
19276 * f(11); //=> false
19277 * f(12); //=> true
19278 */
19279 var allPass = curry(_predicateWrap(_all));
19280
19281 /**
19282 * Given a list of predicates returns a new predicate that will be true exactly when any one of them is.
19283 *
19284 * @func
19285 * @memberOf R
19286 * @category Logic
19287 * @sig [(*... -> Boolean)] -> (*... -> Boolean)
19288 * @param {Array} list An array of predicate functions
19289 * @param {*} optional Any arguments to pass into the predicates
19290 * @return {Function} A function that applies its arguments to each of the predicates, returning
19291 * `true` if all are satisfied.
19292 * @example
19293 *
19294 * var gt10 = function(x) { return x > 10; };
19295 * var even = function(x) { return x % 2 === 0};
19296 * var f = R.anyPass([gt10, even]);
19297 * f(11); //=> true
19298 * f(8); //=> true
19299 * f(9); //=> false
19300 */
19301 var anyPass = curry(_predicateWrap(_any));
19302
19303 /**
19304 * ap applies a list of functions to a list of values.
19305 *
19306 * @func
19307 * @memberOf R
19308 * @category Function
19309 * @sig [f] -> [a] -> [f a]
19310 * @param {Array} fns An array of functions
19311 * @param {Array} vs An array of values
19312 * @return {Array} An array of results of applying each of `fns` to all of `vs` in turn.
19313 * @example
19314 *
19315 * R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6]
19316 */
19317 var ap = _curry2(function ap(fns, vs) {
19318 return _hasMethod('ap', fns) ? fns.ap(vs) : _reduce(function (acc, fn) {
19319 return _concat(acc, map(fn, vs));
19320 }, [], fns);
19321 });
19322
19323 /**
19324 * Returns the result of calling its first argument with the remaining
19325 * arguments. This is occasionally useful as a converging function for
19326 * `R.converge`: the left branch can produce a function while the right
19327 * branch produces a value to be passed to that function as an argument.
19328 *
19329 * @func
19330 * @memberOf R
19331 * @category Function
19332 * @sig (*... -> a),*... -> a
19333 * @param {Function} fn The function to apply to the remaining arguments.
19334 * @param {...*} args Any number of positional arguments.
19335 * @return {*}
19336 * @example
19337 *
19338 * var indentN = R.pipe(R.times(R.always(' ')),
19339 * R.join(''),
19340 * R.replace(/^(?!$)/gm));
19341 *
19342 * var format = R.converge(R.call,
19343 * R.pipe(R.prop('indent'), indentN),
19344 * R.prop('value'));
19345 *
19346 * format({indent: 2, value: 'foo\nbar\nbaz\n'}); //=> ' foo\n bar\n baz\n'
19347 */
19348 var call = curry(function call(fn) {
19349 return fn.apply(this, _slice(arguments, 1));
19350 });
19351
19352 /**
19353 * `chain` maps a function over a list and concatenates the results.
19354 * This implementation is compatible with the
19355 * Fantasy-land Chain spec, and will work with types that implement that spec.
19356 * `chain` is also known as `flatMap` in some libraries
19357 *
19358 * @func
19359 * @memberOf R
19360 * @category List
19361 * @sig (a -> [b]) -> [a] -> [b]
19362 * @param {Function} fn
19363 * @param {Array} list
19364 * @return {Array}
19365 * @example
19366 *
19367 * var duplicate = function(n) {
19368 * return [n, n];
19369 * };
19370 * R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3]
19371 */
19372 var chain = _curry2(_checkForMethod('chain', function chain(f, list) {
19373 return unnest(_map(f, list));
19374 }));
19375
19376 /**
19377 * Turns a list of Functors into a Functor of a list, applying
19378 * a mapping function to the elements of the list along the way.
19379 *
19380 * Note: `commuteMap` may be more useful to convert a list of non-Array Functors (e.g.
19381 * Maybe, Either, etc.) to Functor of a list.
19382 *
19383 * @func
19384 * @memberOf R
19385 * @category List
19386 * @see R.commute
19387 * @sig (a -> (b -> c)) -> (x -> [x]) -> [[*]...]
19388 * @param {Function} fn The transformation function
19389 * @param {Function} of A function that returns the data type to return
19390 * @param {Array} list An Array (or other Functor) of Arrays (or other Functors)
19391 * @return {Array}
19392 * @example
19393 *
19394 * var plus10map = R.map(function(x) { return x + 10; });
19395 * var as = [[1], [3, 4]];
19396 * R.commuteMap(R.map(function(x) { return x + 10; }), R.of, as); //=> [[11, 13], [11, 14]]
19397 *
19398 * var bs = [[1, 2], [3]];
19399 * R.commuteMap(plus10map, R.of, bs); //=> [[11, 13], [12, 13]]
19400 *
19401 * var cs = [[1, 2], [3, 4]];
19402 * R.commuteMap(plus10map, R.of, cs); //=> [[11, 13], [12, 13], [11, 14], [12, 14]]
19403 */
19404 var commuteMap = _curry3(function commuteMap(fn, of, list) {
19405 function consF(acc, ftor) {
19406 return ap(map(append, fn(ftor)), acc);
19407 }
19408 return _reduce(consF, of([]), list);
19409 });
19410
19411 /**
19412 * Wraps a constructor function inside a curried function that can be called with the same
19413 * arguments and returns the same type. The arity of the function returned is specified
19414 * to allow using variadic constructor functions.
19415 *
19416 * @func
19417 * @memberOf R
19418 * @category Function
19419 * @sig Number -> (* -> {*}) -> (* -> {*})
19420 * @param {Number} n The arity of the constructor function.
19421 * @param {Function} Fn The constructor function to wrap.
19422 * @return {Function} A wrapped, curried constructor function.
19423 * @example
19424 *
19425 * // Variadic constructor function
19426 * var Widget = function() {
19427 * this.children = Array.prototype.slice.call(arguments);
19428 * // ...
19429 * };
19430 * Widget.prototype = {
19431 * // ...
19432 * };
19433 * var allConfigs = {
19434 * // ...
19435 * };
19436 * R.map(R.constructN(1, Widget), allConfigs); // a list of Widgets
19437 */
19438 var constructN = _curry2(function constructN(n, Fn) {
19439 if (n > 10) {
19440 throw new Error('Constructor with greater than ten arguments');
19441 }
19442 if (n === 0) {
19443 return function () {
19444 return new Fn();
19445 };
19446 }
19447 return curry(nAry(n, function ($0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
19448 switch (arguments.length) {
19449 case 1:
19450 return new Fn($0);
19451 case 2:
19452 return new Fn($0, $1);
19453 case 3:
19454 return new Fn($0, $1, $2);
19455 case 4:
19456 return new Fn($0, $1, $2, $3);
19457 case 5:
19458 return new Fn($0, $1, $2, $3, $4);
19459 case 6:
19460 return new Fn($0, $1, $2, $3, $4, $5);
19461 case 7:
19462 return new Fn($0, $1, $2, $3, $4, $5, $6);
19463 case 8:
19464 return new Fn($0, $1, $2, $3, $4, $5, $6, $7);
19465 case 9:
19466 return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8);
19467 case 10:
19468 return new Fn($0, $1, $2, $3, $4, $5, $6, $7, $8, $9);
19469 }
19470 }));
19471 });
19472
19473 /**
19474 * Returns a new list without any consecutively repeating elements. Equality is
19475 * determined by applying the supplied predicate two consecutive elements.
19476 * The first element in a series of equal element is the one being preserved.
19477 *
19478 * Acts as a transducer if a transformer is given in list position.
19479 * @see R.transduce
19480 *
19481 * @func
19482 * @memberOf R
19483 * @category List
19484 * @sig (a, a -> Boolean) -> [a] -> [a]
19485 * @param {Function} pred A predicate used to test whether two items are equal.
19486 * @param {Array} list The array to consider.
19487 * @return {Array} `list` without repeating elements.
19488 * @example
19489 *
19490 * function lengthEq(x, y) { return Math.abs(x) === Math.abs(y); };
19491 * var l = [1, -1, 1, 3, 4, -4, -4, -5, 5, 3, 3];
19492 * R.dropRepeatsWith(lengthEq, l); //=> [1, 3, 4, -5, 3]
19493 */
19494 var dropRepeatsWith = _curry2(_dispatchable('dropRepeatsWith', _xdropRepeatsWith, function dropRepeatsWith(pred, list) {
19495 var result = [];
19496 var idx = 0;
19497 var len = list.length;
19498 if (len !== 0) {
19499 result[0] = list[0];
19500 while (++idx < len) {
19501 if (!pred(last(result), list[idx])) {
19502 result[result.length] = list[idx];
19503 }
19504 }
19505 }
19506 return result;
19507 }));
19508
19509 /**
19510 * Performs a deep test on whether two items are equal.
19511 * Equality implies the two items are semmatically equivalent.
19512 * Cyclic structures are handled as expected
19513 *
19514 * @func
19515 * @memberOf R
19516 * @category Relation
19517 * @sig a -> b -> Boolean
19518 * @param {*} a
19519 * @param {*} b
19520 * @return {Boolean}
19521 * @example
19522 *
19523 * var o = {};
19524 * R.eqDeep(o, o); //=> true
19525 * R.eqDeep(o, {}); //=> true
19526 * R.eqDeep(1, 1); //=> true
19527 * R.eqDeep(1, '1'); //=> false
19528 *
19529 * var a = {}; a.v = a;
19530 * var b = {}; b.v = b;
19531 * R.eqDeep(a, b); //=> true
19532 */
19533 var eqDeep = _curry2(function eqDeep(a, b) {
19534 return _eqDeep(a, b, [], []);
19535 });
19536
19537 /**
19538 * Creates a new object by evolving a shallow copy of `object`, according to the
19539 * `transformation` functions. All non-primitive properties are copied by reference.
19540 *
19541 * @func
19542 * @memberOf R
19543 * @category Object
19544 * @sig {k: (v -> v)} -> {k: v} -> {k: v}
19545 * @param {Object} transformations The object specifying transformation functions to apply
19546 * to the object.
19547 * @param {Object} object The object to be transformed.
19548 * @return {Object} The transformed object.
19549 * @example
19550 *
19551 * R.evolve({ elapsed: R.add(1), remaining: R.add(-1) }, { name: 'Tomato', elapsed: 100, remaining: 1400 }); //=> { name: 'Tomato', elapsed: 101, remaining: 1399 }
19552 */
19553 var evolve = _curry2(function evolve(transformations, object) {
19554 return _extend(_extend({}, object), mapObjIndexed(function (fn, key) {
19555 return fn(object[key]);
19556 }, transformations));
19557 });
19558
19559 /**
19560 * Returns a list of function names of object's own functions
19561 *
19562 * @func
19563 * @memberOf R
19564 * @category Object
19565 * @sig {*} -> [String]
19566 * @param {Object} obj The objects with functions in it
19567 * @return {Array} A list of the object's own properties that map to functions.
19568 * @example
19569 *
19570 * R.functions(R); // returns list of ramda's own function names
19571 *
19572 * var F = function() { this.x = function(){}; this.y = 1; }
19573 * F.prototype.z = function() {};
19574 * F.prototype.a = 100;
19575 * R.functions(new F()); //=> ["x"]
19576 */
19577 var functions = _curry1(_functionsWith(keys));
19578
19579 /**
19580 * Returns all but the last element of a list.
19581 *
19582 * @func
19583 * @memberOf R
19584 * @category List
19585 * @sig [a] -> [a]
19586 * @param {Array} list The array to consider.
19587 * @return {Array} A new array containing all but the last element of the input list, or an
19588 * empty list if the input list is empty.
19589 * @example
19590 *
19591 * R.init(['fi', 'fo', 'fum']); //=> ['fi', 'fo']
19592 */
19593 var init = slice(0, -1);
19594
19595 /**
19596 * Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists.
19597 *
19598 * @func
19599 * @memberOf R
19600 * @category Relation
19601 * @sig [a] -> [a] -> [a]
19602 * @param {Array} list1 The first list.
19603 * @param {Array} list2 The second list.
19604 * @see R.intersectionWith
19605 * @return {Array} The list of elements found in both `list1` and `list2`.
19606 * @example
19607 *
19608 * R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]
19609 */
19610 var intersection = _curry2(function intersection(list1, list2) {
19611 return uniq(_filter(flip(_contains)(list1), list2));
19612 });
19613
19614 /**
19615 * Same as R.invertObj, however this accounts for objects
19616 * with duplicate values by putting the values into an
19617 * array.
19618 *
19619 * @func
19620 * @memberOf R
19621 * @category Object
19622 * @sig {s: x} -> {x: [ s, ... ]}
19623 * @param {Object} obj The object or array to invert
19624 * @return {Object} out A new object with keys
19625 * in an array.
19626 * @example
19627 *
19628 * var raceResultsByFirstName = {
19629 * first: 'alice',
19630 * second: 'jake',
19631 * third: 'alice',
19632 * };
19633 * R.invert(raceResultsByFirstName);
19634 * //=> { 'alice': ['first', 'third'], 'jake':['second'] }
19635 */
19636 var invert = _curry1(function invert(obj) {
19637 var props = keys(obj);
19638 var len = props.length;
19639 var idx = -1;
19640 var out = {};
19641 while (++idx < len) {
19642 var key = props[idx];
19643 var val = obj[key];
19644 var list = _has(val, out) ? out[val] : out[val] = [];
19645 list[list.length] = key;
19646 }
19647 return out;
19648 });
19649
19650 /**
19651 * Returns a new object with the keys of the given object
19652 * as values, and the values of the given object as keys.
19653 *
19654 * @func
19655 * @memberOf R
19656 * @category Object
19657 * @sig {s: x} -> {x: s}
19658 * @param {Object} obj The object or array to invert
19659 * @return {Object} out A new object
19660 * @example
19661 *
19662 * var raceResults = {
19663 * first: 'alice',
19664 * second: 'jake'
19665 * };
19666 * R.invertObj(raceResults);
19667 * //=> { 'alice': 'first', 'jake':'second' }
19668 *
19669 * // Alternatively:
19670 * var raceResults = ['alice', 'jake'];
19671 * R.invertObj(raceResults);
19672 * //=> { 'alice': '0', 'jake':'1' }
19673 */
19674 var invertObj = _curry1(function invertObj(obj) {
19675 var props = keys(obj);
19676 var len = props.length;
19677 var idx = -1;
19678 var out = {};
19679 while (++idx < len) {
19680 var key = props[idx];
19681 out[obj[key]] = key;
19682 }
19683 return out;
19684 });
19685
19686 /**
19687 * "lifts" a function to be the specified arity, so that it may "map over" that many
19688 * lists (or other Functors).
19689 *
19690 * @func
19691 * @memberOf R
19692 * @see R.lift
19693 * @category Function
19694 * @sig Number -> (*... -> *) -> ([*]... -> [*])
19695 * @param {Function} fn The function to lift into higher context
19696 * @return {Function} The function `fn` applicable to mappable objects.
19697 * @example
19698 *
19699 * var madd3 = R.liftN(3, R.curryN(3, function() {
19700 * return R.reduce(R.add, 0, arguments);
19701 * }));
19702 * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7]
19703 */
19704 var liftN = _curry2(function liftN(arity, fn) {
19705 var lifted = curryN(arity, fn);
19706 return curryN(arity, function () {
19707 return _reduce(ap, map(lifted, arguments[0]), _slice(arguments, 1));
19708 });
19709 });
19710
19711 /**
19712 * Returns the mean of the given list of numbers.
19713 *
19714 * @func
19715 * @memberOf R
19716 * @category Math
19717 * @sig [Number] -> Number
19718 * @param {Array} list
19719 * @return {Number}
19720 * @example
19721 *
19722 * R.mean([2, 7, 9]); //=> 6
19723 * R.mean([]); //=> NaN
19724 */
19725 var mean = _curry1(function mean(list) {
19726 return sum(list) / list.length;
19727 });
19728
19729 /**
19730 * Returns the median of the given list of numbers.
19731 *
19732 * @func
19733 * @memberOf R
19734 * @category Math
19735 * @sig [Number] -> Number
19736 * @param {Array} list
19737 * @return {Number}
19738 * @example
19739 *
19740 * R.median([2, 9, 7]); //=> 7
19741 * R.median([7, 2, 10, 9]); //=> 8
19742 * R.median([]); //=> NaN
19743 */
19744 var median = _curry1(function median(list) {
19745 var len = list.length;
19746 if (len === 0) {
19747 return NaN;
19748 }
19749 var width = 2 - len % 2;
19750 var idx = (len - width) / 2;
19751 return mean(_slice(list).sort(function (a, b) {
19752 return a < b ? -1 : a > b ? 1 : 0;
19753 }).slice(idx, idx + width));
19754 });
19755
19756 /**
19757 * Create a new object with the own properties of a
19758 * merged with the own properties of object b.
19759 * This function will *not* mutate passed-in objects.
19760 *
19761 * @func
19762 * @memberOf R
19763 * @category Object
19764 * @sig {k: v} -> {k: v} -> {k: v}
19765 * @param {Object} a source object
19766 * @param {Object} b object with higher precedence in output
19767 * @return {Object} The destination object.
19768 * @example
19769 *
19770 * R.merge({ 'name': 'fred', 'age': 10 }, { 'age': 40 });
19771 * //=> { 'name': 'fred', 'age': 40 }
19772 *
19773 * var resetToDefault = R.merge(R.__, {x: 0});
19774 * resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2}
19775 */
19776 var merge = _curry2(function merge(a, b) {
19777 return _extend(_extend({}, a), b);
19778 });
19779
19780 /**
19781 * Merges a list of objects together into one object.
19782 *
19783 * @func
19784 * @memberOf R
19785 * @category List
19786 * @sig [{k: v}] -> {k: v}
19787 * @param {Array} list An array of objects
19788 * @return {Object} A merged object.
19789 * @see reduce
19790 * @example
19791 *
19792 * R.mergeAll([{foo:1},{bar:2},{baz:3}]); //=> {foo:1,bar:2,baz:3}
19793 * R.mergeAll([{foo:1},{foo:2},{bar:2}]); //=> {foo:2,bar:2}
19794 */
19795 var mergeAll = _curry1(function mergeAll(list) {
19796 return reduce(merge, {}, list);
19797 });
19798
19799 /**
19800 * Returns a new list by plucking the same named property off all objects in the list supplied.
19801 *
19802 * @func
19803 * @memberOf R
19804 * @category List
19805 * @sig String -> {*} -> [*]
19806 * @param {Number|String} key The key name to pluck off of each object.
19807 * @param {Array} list The array to consider.
19808 * @return {Array} The list of values for the given key.
19809 * @example
19810 *
19811 * R.pluck('a')([{a: 1}, {a: 2}]); //=> [1, 2]
19812 * R.pluck(0)([[1, 2], [3, 4]]); //=> [1, 3]
19813 */
19814 var pluck = _curry2(_pluck);
19815
19816 /**
19817 * Multiplies together all the elements of a list.
19818 *
19819 * @func
19820 * @memberOf R
19821 * @category Math
19822 * @sig [Number] -> Number
19823 * @param {Array} list An array of numbers
19824 * @return {Number} The product of all the numbers in the list.
19825 * @see reduce
19826 * @example
19827 *
19828 * R.product([2,4,6,8,100,1]); //=> 38400
19829 */
19830 var product = reduce(_multiply, 1);
19831
19832 /**
19833 * Reasonable analog to SQL `select` statement.
19834 *
19835 * @func
19836 * @memberOf R
19837 * @category Object
19838 * @category Relation
19839 * @sig [k] -> [{k: v}] -> [{k: v}]
19840 * @param {Array} props The property names to project
19841 * @param {Array} objs The objects to query
19842 * @return {Array} An array of objects with just the `props` properties.
19843 * @example
19844 *
19845 * var abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2};
19846 * var fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7};
19847 * var kids = [abby, fred];
19848 * R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}]
19849 */
19850 // passing `identity` gives correct arity
19851 var project = useWith(_map, pickAll, identity);
19852
19853 /**
19854 * Returns the string representation of the given value. `eval`'ing the output
19855 * should result in a value equivalent to the input value. Many of the built-in
19856 * `toString` methods do not satisfy this requirement.
19857 *
19858 * If the given value is an `[object Object]` with a `toString` method other
19859 * than `Object.prototype.toString`, this method is invoked with no arguments
19860 * to produce the return value. This means user-defined constructor functions
19861 * can provide a suitable `toString` method. For example:
19862 *
19863 * function Point(x, y) {
19864 * this.x = x;
19865 * this.y = y;
19866 * }
19867 *
19868 * Point.prototype.toString = function() {
19869 * return 'new Point(' + this.x + ', ' + this.y + ')';
19870 * };
19871 *
19872 * R.toString(new Point(1, 2)); //=> 'new Point(1, 2)'
19873 *
19874 * @func
19875 * @memberOf R
19876 * @category String
19877 * @sig * -> String
19878 * @param {*} val
19879 * @return {String}
19880 * @example
19881 *
19882 * R.toString(42); //=> '42'
19883 * R.toString('abc'); //=> '"abc"'
19884 * R.toString([1, 2, 3]); //=> '[1, 2, 3]'
19885 * R.toString({foo: 1, bar: 2, baz: 3}); //=> '{"bar": 2, "baz": 3, "foo": 1}'
19886 * R.toString(new Date('2001-02-03T04:05:06Z')); //=> 'new Date("2001-02-03T04:05:06.000Z")'
19887 */
19888 var toString = _curry1(function toString(val) {
19889 return _toString(val, []);
19890 });
19891
19892 /**
19893 * Combines two lists into a set (i.e. no duplicates) composed of the
19894 * elements of each list.
19895 *
19896 * @func
19897 * @memberOf R
19898 * @category Relation
19899 * @sig [a] -> [a] -> [a]
19900 * @param {Array} as The first list.
19901 * @param {Array} bs The second list.
19902 * @return {Array} The first and second lists concatenated, with
19903 * duplicates removed.
19904 * @example
19905 *
19906 * R.union([1, 2, 3], [2, 3, 4]); //=> [1, 2, 3, 4]
19907 */
19908 var union = _curry2(compose(uniq, _concat));
19909
19910 var _stepCat = function () {
19911 var _stepCatArray = {
19912 '@@transducer/init': Array,
19913 '@@transducer/step': function (xs, x) {
19914 return _concat(xs, [x]);
19915 },
19916 '@@transducer/result': _identity
19917 };
19918 var _stepCatString = {
19919 '@@transducer/init': String,
19920 '@@transducer/step': _add,
19921 '@@transducer/result': _identity
19922 };
19923 var _stepCatObject = {
19924 '@@transducer/init': Object,
19925 '@@transducer/step': function (result, input) {
19926 return merge(result, isArrayLike(input) ? _createMapEntry(input[0], input[1]) : input);
19927 },
19928 '@@transducer/result': _identity
19929 };
19930 return function _stepCat(obj) {
19931 if (_isTransformer(obj)) {
19932 return obj;
19933 }
19934 if (isArrayLike(obj)) {
19935 return _stepCatArray;
19936 }
19937 if (typeof obj === 'string') {
19938 return _stepCatString;
19939 }
19940 if (typeof obj === 'object') {
19941 return _stepCatObject;
19942 }
19943 throw new Error('Cannot create transformer for ' + obj);
19944 };
19945 }();
19946
19947 /**
19948 * Turns a list of Functors into a Functor of a list.
19949 *
19950 * Note: `commute` may be more useful to convert a list of non-Array Functors (e.g.
19951 * Maybe, Either, etc.) to Functor of a list.
19952 *
19953 * @func
19954 * @memberOf R
19955 * @category List
19956 * @see R.commuteMap
19957 * @sig (x -> [x]) -> [[*]...]
19958 * @param {Function} of A function that returns the data type to return
19959 * @param {Array} list An Array (or other Functor) of Arrays (or other Functors)
19960 * @return {Array}
19961 * @example
19962 *
19963 * var as = [[1], [3, 4]];
19964 * R.commute(R.of, as); //=> [[1, 3], [1, 4]]
19965 *
19966 * var bs = [[1, 2], [3]];
19967 * R.commute(R.of, bs); //=> [[1, 3], [2, 3]]
19968 *
19969 * var cs = [[1, 2], [3, 4]];
19970 * R.commute(R.of, cs); //=> [[1, 3], [2, 3], [1, 4], [2, 4]]
19971 */
19972 var commute = commuteMap(map(identity));
19973
19974 /**
19975 * Wraps a constructor function inside a curried function that can be called with the same
19976 * arguments and returns the same type.
19977 *
19978 * @func
19979 * @memberOf R
19980 * @category Function
19981 * @sig (* -> {*}) -> (* -> {*})
19982 * @param {Function} Fn The constructor function to wrap.
19983 * @return {Function} A wrapped, curried constructor function.
19984 * @example
19985 *
19986 * // Constructor function
19987 * var Widget = function(config) {
19988 * // ...
19989 * };
19990 * Widget.prototype = {
19991 * // ...
19992 * };
19993 * var allConfigs = {
19994 * // ...
19995 * };
19996 * R.map(R.construct(Widget), allConfigs); // a list of Widgets
19997 */
19998 var construct = _curry1(function construct(Fn) {
19999 return constructN(Fn.length, Fn);
20000 });
20001
20002 /**
20003 * Accepts at least three functions and returns a new function. When invoked, this new
20004 * function will invoke the first function, `after`, passing as its arguments the
20005 * results of invoking the subsequent functions with whatever arguments are passed to
20006 * the new function.
20007 *
20008 * @func
20009 * @memberOf R
20010 * @category Function
20011 * @sig (x1 -> x2 -> ... -> z) -> ((a -> b -> ... -> x1), (a -> b -> ... -> x2), ...) -> (a -> b -> ... -> z)
20012 * @param {Function} after A function. `after` will be invoked with the return values of
20013 * `fn1` and `fn2` as its arguments.
20014 * @param {...Function} functions A variable number of functions.
20015 * @return {Function} A new function.
20016 * @example
20017 *
20018 * var add = function(a, b) { return a + b; };
20019 * var multiply = function(a, b) { return a * b; };
20020 * var subtract = function(a, b) { return a - b; };
20021 *
20022 * //≅ multiply( add(1, 2), subtract(1, 2) );
20023 * R.converge(multiply, add, subtract)(1, 2); //=> -3
20024 *
20025 * var add3 = function(a, b, c) { return a + b + c; };
20026 * R.converge(add3, multiply, add, subtract)(1, 2); //=> 4
20027 */
20028 var converge = curryN(3, function (after) {
20029 var fns = _slice(arguments, 1);
20030 return curryN(max(pluck('length', fns)), function () {
20031 var args = arguments;
20032 var context = this;
20033 return after.apply(context, _map(function (fn) {
20034 return fn.apply(context, args);
20035 }, fns));
20036 });
20037 });
20038
20039 /**
20040 * Returns a new list without any consecutively repeating elements.
20041 *
20042 * Acts as a transducer if a transformer is given in list position.
20043 * @see R.transduce
20044 *
20045 * @func
20046 * @memberOf R
20047 * @category List
20048 * @sig [a] -> [a]
20049 * @param {Array} list The array to consider.
20050 * @return {Array} `list` without repeating elements.
20051 * @example
20052 *
20053 * R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]); //=> [1, 2, 3, 4, 2]
20054 */
20055 var dropRepeats = _curry1(_dispatchable('dropRepeats', _xdropRepeatsWith(_eq), dropRepeatsWith(_eq)));
20056
20057 /**
20058 * Transforms the items of the list with the transducer and appends the transformed items to
20059 * the accumulator using an appropriate iterator function based on the accumulator type.
20060 *
20061 * The accumulator can be an array, string, object or a transformer. Iterated items will
20062 * be appended to arrays and concatenated to strings. Objects will be merged directly or 2-item
20063 * arrays will be merged as key, value pairs.
20064 *
20065 * The accumulator can also be a transformer object that provides a 2-arity reducing iterator
20066 * function, step, 0-arity initial value function, init, and 1-arity result extraction function
20067 * result. The step function is used as the iterator function in reduce. The result function is
20068 * used to convert the final accumulator into the return type and in most cases is R.identity.
20069 * The init function is used to provide the initial accumulator.
20070 *
20071 * The iteration is performed with R.reduce after initializing the transducer.
20072 *
20073 * @func
20074 * @memberOf R
20075 * @category List
20076 * @sig a -> (b -> b) -> [c] -> a
20077 * @param {*} acc The initial accumulator value.
20078 * @param {Function} xf The transducer function. Receives a transformer and returns a transformer.
20079 * @param {Array} list The list to iterate over.
20080 * @return {*} The final, accumulated value.
20081 * @example
20082 *
20083 * var numbers = [1, 2, 3, 4];
20084 * var transducer = R.compose(R.map(R.add(1)), R.take(2));
20085 *
20086 * R.into([], transducer, numbers); //=> [2, 3]
20087 *
20088 * var intoArray = R.into([]);
20089 * intoArray(transducer, numbers); //=> [2, 3]
20090 */
20091 var into = _curry3(function into(acc, xf, list) {
20092 return _isTransformer(acc) ? _reduce(xf(acc), acc['@@transducer/init'](), list) : _reduce(xf(_stepCat(acc)), acc, list);
20093 });
20094
20095 /**
20096 * "lifts" a function of arity > 1 so that it may "map over" an Array or
20097 * other Functor.
20098 *
20099 * @func
20100 * @memberOf R
20101 * @see R.liftN
20102 * @category Function
20103 * @sig (*... -> *) -> ([*]... -> [*])
20104 * @param {Function} fn The function to lift into higher context
20105 * @return {Function} The function `fn` applicable to mappable objects.
20106 * @example
20107 *
20108 * var madd3 = R.lift(R.curry(function(a, b, c) {
20109 * return a + b + c;
20110 * }));
20111 * madd3([1,2,3], [1,2,3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7]
20112 *
20113 * var madd5 = R.lift(R.curry(function(a, b, c, d, e) {
20114 * return a + b + c + d + e;
20115 * }));
20116 * madd5([1,2], [3], [4, 5], [6], [7, 8]); //=> [21, 22, 22, 23, 22, 23, 23, 24]
20117 */
20118 var lift = _curry1(function lift(fn) {
20119 return liftN(fn.length, fn);
20120 });
20121
20122 /**
20123 * Creates a new function that, when invoked, caches the result of calling `fn` for a given
20124 * argument set and returns the result. Subsequent calls to the memoized `fn` with the same
20125 * argument set will not result in an additional call to `fn`; instead, the cached result
20126 * for that set of arguments will be returned.
20127 *
20128 * @func
20129 * @memberOf R
20130 * @category Function
20131 * @sig (*... -> a) -> (*... -> a)
20132 * @param {Function} fn The function to memoize.
20133 * @return {Function} Memoized version of `fn`.
20134 * @example
20135 *
20136 * var count = 0;
20137 * var factorial = R.memoize(function(n) {
20138 * count += 1;
20139 * return R.product(R.range(1, n + 1));
20140 * });
20141 * factorial(5); //=> 120
20142 * factorial(5); //=> 120
20143 * factorial(5); //=> 120
20144 * count; //=> 1
20145 */
20146 var memoize = _curry1(function memoize(fn) {
20147 var cache = {};
20148 return function () {
20149 var key = toString(arguments);
20150 if (!_has(key, cache)) {
20151 cache[key] = fn.apply(this, arguments);
20152 }
20153 return cache[key];
20154 };
20155 });
20156
20157 var R = {
20158 F: F,
20159 T: T,
20160 __: __,
20161 add: add,
20162 adjust: adjust,
20163 all: all,
20164 allPass: allPass,
20165 always: always,
20166 and: and,
20167 any: any,
20168 anyPass: anyPass,
20169 ap: ap,
20170 aperture: aperture,
20171 append: append,
20172 apply: apply,
20173 arity: arity,
20174 assoc: assoc,
20175 assocPath: assocPath,
20176 binary: binary,
20177 bind: bind,
20178 both: both,
20179 call: call,
20180 chain: chain,
20181 clone: clone,
20182 commute: commute,
20183 commuteMap: commuteMap,
20184 comparator: comparator,
20185 complement: complement,
20186 compose: compose,
20187 composeL: composeL,
20188 composeP: composeP,
20189 concat: concat,
20190 cond: cond,
20191 construct: construct,
20192 constructN: constructN,
20193 contains: contains,
20194 containsWith: containsWith,
20195 converge: converge,
20196 countBy: countBy,
20197 createMapEntry: createMapEntry,
20198 curry: curry,
20199 curryN: curryN,
20200 dec: dec,
20201 defaultTo: defaultTo,
20202 difference: difference,
20203 differenceWith: differenceWith,
20204 dissoc: dissoc,
20205 dissocPath: dissocPath,
20206 divide: divide,
20207 drop: drop,
20208 dropRepeats: dropRepeats,
20209 dropRepeatsWith: dropRepeatsWith,
20210 dropWhile: dropWhile,
20211 either: either,
20212 empty: empty,
20213 eq: eq,
20214 eqDeep: eqDeep,
20215 eqProps: eqProps,
20216 evolve: evolve,
20217 filter: filter,
20218 filterIndexed: filterIndexed,
20219 find: find,
20220 findIndex: findIndex,
20221 findLast: findLast,
20222 findLastIndex: findLastIndex,
20223 flatten: flatten,
20224 flip: flip,
20225 forEach: forEach,
20226 forEachIndexed: forEachIndexed,
20227 fromPairs: fromPairs,
20228 functions: functions,
20229 functionsIn: functionsIn,
20230 groupBy: groupBy,
20231 gt: gt,
20232 gte: gte,
20233 has: has,
20234 hasIn: hasIn,
20235 head: head,
20236 identity: identity,
20237 ifElse: ifElse,
20238 inc: inc,
20239 indexOf: indexOf,
20240 init: init,
20241 insert: insert,
20242 insertAll: insertAll,
20243 intersection: intersection,
20244 intersectionWith: intersectionWith,
20245 intersperse: intersperse,
20246 into: into,
20247 invert: invert,
20248 invertObj: invertObj,
20249 invoke: invoke,
20250 invoker: invoker,
20251 is: is,
20252 isArrayLike: isArrayLike,
20253 isEmpty: isEmpty,
20254 isNaN: isNaN,
20255 isNil: isNil,
20256 isSet: isSet,
20257 join: join,
20258 keys: keys,
20259 keysIn: keysIn,
20260 last: last,
20261 lastIndexOf: lastIndexOf,
20262 length: length,
20263 lens: lens,
20264 lensIndex: lensIndex,
20265 lensOn: lensOn,
20266 lensProp: lensProp,
20267 lift: lift,
20268 liftN: liftN,
20269 lt: lt,
20270 lte: lte,
20271 map: map,
20272 mapAccum: mapAccum,
20273 mapAccumRight: mapAccumRight,
20274 mapIndexed: mapIndexed,
20275 mapObj: mapObj,
20276 mapObjIndexed: mapObjIndexed,
20277 match: match,
20278 mathMod: mathMod,
20279 max: max,
20280 maxBy: maxBy,
20281 mean: mean,
20282 median: median,
20283 memoize: memoize,
20284 merge: merge,
20285 mergeAll: mergeAll,
20286 min: min,
20287 minBy: minBy,
20288 modulo: modulo,
20289 multiply: multiply,
20290 nAry: nAry,
20291 negate: negate,
20292 none: none,
20293 not: not,
20294 nth: nth,
20295 nthArg: nthArg,
20296 nthChar: nthChar,
20297 nthCharCode: nthCharCode,
20298 of: of,
20299 omit: omit,
20300 once: once,
20301 or: or,
20302 partial: partial,
20303 partialRight: partialRight,
20304 partition: partition,
20305 path: path,
20306 pathEq: pathEq,
20307 pick: pick,
20308 pickAll: pickAll,
20309 pickBy: pickBy,
20310 pipe: pipe,
20311 pipeL: pipeL,
20312 pipeP: pipeP,
20313 pluck: pluck,
20314 prepend: prepend,
20315 product: product,
20316 project: project,
20317 prop: prop,
20318 propEq: propEq,
20319 propOr: propOr,
20320 props: props,
20321 range: range,
20322 reduce: reduce,
20323 reduceIndexed: reduceIndexed,
20324 reduceRight: reduceRight,
20325 reduceRightIndexed: reduceRightIndexed,
20326 reject: reject,
20327 rejectIndexed: rejectIndexed,
20328 remove: remove,
20329 repeat: repeat,
20330 replace: replace,
20331 reverse: reverse,
20332 scan: scan,
20333 slice: slice,
20334 sort: sort,
20335 sortBy: sortBy,
20336 split: split,
20337 strIndexOf: strIndexOf,
20338 strLastIndexOf: strLastIndexOf,
20339 substring: substring,
20340 substringFrom: substringFrom,
20341 substringTo: substringTo,
20342 subtract: subtract,
20343 sum: sum,
20344 tail: tail,
20345 take: take,
20346 takeWhile: takeWhile,
20347 tap: tap,
20348 test: test,
20349 times: times,
20350 toLower: toLower,
20351 toPairs: toPairs,
20352 toPairsIn: toPairsIn,
20353 toString: toString,
20354 toUpper: toUpper,
20355 transduce: transduce,
20356 trim: trim,
20357 type: type,
20358 unapply: unapply,
20359 unary: unary,
20360 uncurryN: uncurryN,
20361 unfold: unfold,
20362 union: union,
20363 unionWith: unionWith,
20364 uniq: uniq,
20365 uniqWith: uniqWith,
20366 unnest: unnest,
20367 update: update,
20368 useWith: useWith,
20369 values: values,
20370 valuesIn: valuesIn,
20371 where: where,
20372 whereEq: whereEq,
20373 wrap: wrap,
20374 xprod: xprod,
20375 zip: zip,
20376 zipObj: zipObj,
20377 zipWith: zipWith
20378 };
20379
20380 /* TEST_ENTRY_POINT */
20381
20382 if (true) {
20383 module.exports = R;
20384 } else if (typeof define === 'function' && define.amd) {
20385 define(function() { return R; });
20386 } else {
20387 this.R = R;
20388 }
20389
20390 }.call(this));
20391
20392
20393/***/ },
20394/* 11 */
20395/***/ function(module, exports, __webpack_require__) {
20396
20397 module.exports = function(module) {
20398 if(!module.webpackPolyfill) {
20399 module.deprecate = function() {};
20400 module.paths = [];
20401 // module.parent = undefined by default
20402 module.children = [];
20403 module.webpackPolyfill = 1;
20404 }
20405 return module;
20406 }
20407
20408
20409/***/ },
20410/* 12 */
20411/***/ function(module, exports, __webpack_require__) {
20412
20413 var __WEBPACK_AMD_DEFINE_RESULT__;/**
20414 * This module exports functions for checking types
20415 * and throwing exceptions.
20416 */
20417
20418 /*globals define, module */
20419
20420 (function (globals) {
20421 'use strict';
20422
20423 var messages, predicates, functions, verify, maybe, not;
20424
20425 predicates = {
20426 like: like,
20427 instance: instance,
20428 emptyObject: emptyObject,
20429 nulled: nulled,
20430 defined: defined,
20431 object: object,
20432 length: length,
20433 array: array,
20434 date: date,
20435 fn: fn,
20436 webUrl: webUrl,
20437 gitUrl: gitUrl,
20438 email: email,
20439 unemptyString: unemptyString,
20440 string: string,
20441 evenNumber: evenNumber,
20442 oddNumber: oddNumber,
20443 positiveNumber: positiveNumber,
20444 negativeNumber: negativeNumber,
20445 intNumber : intNumber,
20446 floatNumber : floatNumber,
20447 number: number,
20448 bool: bool
20449 };
20450
20451 messages = {
20452 like: 'Invalid type',
20453 instance: 'Invalid type',
20454 emptyObject: 'Invalid object',
20455 nulled: 'Not null',
20456 defined: 'Not defined',
20457 object: 'Invalid object',
20458 length: 'Invalid length',
20459 array: 'Invalid array',
20460 date: 'Invalid date',
20461 fn: 'Invalid function',
20462 webUrl: 'Invalid URL',
20463 gitUrl: 'Invalid git URL',
20464 email: 'Invalid email',
20465 unemptyString: 'Invalid string',
20466 string: 'Invalid string',
20467 evenNumber: 'Invalid number',
20468 oddNumber: 'Invalid number',
20469 positiveNumber: 'Invalid number',
20470 negativeNumber: 'Invalid number',
20471 intNumber: 'Invalid number',
20472 floatNumber: 'Invalid number',
20473 number: 'Invalid number',
20474 bool: 'Invalid boolean'
20475 };
20476
20477 functions = {
20478 map: map,
20479 every: every,
20480 any: any
20481 };
20482
20483 functions = mixin(functions, predicates);
20484 verify = createModifiedPredicates(verifyModifier);
20485 maybe = createModifiedPredicates(maybeModifier);
20486 not = createModifiedPredicates(notModifier);
20487 verify.maybe = createModifiedFunctions(verifyModifier, maybe);
20488 verify.not = createModifiedFunctions(verifyModifier, not);
20489
20490 exportFunctions(mixin(functions, {
20491 verify: verify,
20492 maybe: maybe,
20493 not: not
20494 }));
20495
20496 /**
20497 * Public function `like`.
20498 *
20499 * Tests whether an object 'quacks like a duck'.
20500 * Returns `true` if the first argument has all of
20501 * the properties of the second, archetypal argument
20502 * (the 'duck'). Returns `false` otherwise. If either
20503 * argument is not an object, an exception is thrown.
20504 *
20505 * @param thing {object} The object to test.
20506 * @param duck {object} The archetypal object, or
20507 * 'duck', that the test is
20508 * against.
20509 */
20510 function like (thing, duck) {
20511 var name;
20512
20513 verify.object(thing);
20514 verify.object(duck);
20515
20516 for (name in duck) {
20517 if (duck.hasOwnProperty(name)) {
20518 if (thing.hasOwnProperty(name) === false || typeof thing[name] !== typeof duck[name]) {
20519 return false;
20520 }
20521
20522 if (object(thing[name]) && like(thing[name], duck[name]) === false) {
20523 return false;
20524 }
20525 }
20526 }
20527
20528 return true;
20529 }
20530
20531 /**
20532 * Public function `instance`.
20533 *
20534 * Returns `true` if an object is an instance of a prototype,
20535 * `false` otherwise.
20536 *
20537 * @param thing {object} The object to test.
20538 * @param prototype {function} The prototype that the
20539 * test is against.
20540 */
20541 function instance (thing, prototype) {
20542 if (!defined(thing) || nulled(thing)) {
20543 return false;
20544 }
20545
20546 if (fn(prototype) && thing instanceof prototype) {
20547 return true;
20548 }
20549
20550 return false;
20551 }
20552
20553 /**
20554 * Public function `emptyObject`.
20555 *
20556 * Returns `true` if something is an empty, non-null,
20557 * non-array object, `false` otherwise.
20558 *
20559 * @param thing The thing to test.
20560 */
20561 function emptyObject (thing) {
20562 var property;
20563
20564 if (object(thing)) {
20565 for (property in thing) {
20566 if (thing.hasOwnProperty(property)) {
20567 return false;
20568 }
20569 }
20570
20571 return true;
20572 }
20573
20574 return false;
20575 }
20576
20577 /**
20578 * Public function `nulled`.
20579 *
20580 * Returns `true` if something is null,
20581 * `false` otherwise.
20582 *
20583 * @param thing The thing to test.
20584 */
20585 function nulled (thing) {
20586 return thing === null;
20587 }
20588
20589 /**
20590 * Public function `defined`.
20591 *
20592 * Returns `true` if something is not undefined,
20593 * `false` otherwise.
20594 *
20595 * @param thing The thing to test.
20596 */
20597 function defined (thing) {
20598 return thing !== void 0;
20599 }
20600
20601 /**
20602 * Public function `object`.
20603 *
20604 * Returns `true` if something is a non-null, non-array,
20605 * non-date object, `false` otherwise.
20606 *
20607 * @param thing The thing to test.
20608 */
20609 function object (thing) {
20610 return typeof thing === 'object' && !nulled(thing) && !array(thing) && !date(thing);
20611 }
20612
20613 /**
20614 * Public function `length`.
20615 *
20616 * Returns `true` if something is has a length property
20617 * that equals `value`, `false` otherwise.
20618 *
20619 * @param thing The thing to test.
20620 * @param value The required length to test against.
20621 */
20622 function length (thing, value) {
20623 return thing && thing.length === value;
20624 }
20625
20626 /**
20627 * Public function `array`.
20628 *
20629 * Returns `true` something is an array, `false` otherwise.
20630 *
20631 * @param thing The thing to test.
20632 */
20633 function array (thing) {
20634 if (Array.isArray) {
20635 return Array.isArray(thing);
20636 }
20637
20638 return Object.prototype.toString.call(thing) === '[object Array]';
20639 }
20640
20641 /**
20642 * Public function `date`.
20643 *
20644 * Returns `true` something is a date, `false` otherwise.
20645 *
20646 * @param thing The thing to test.
20647 */
20648 function date (thing) {
20649 return Object.prototype.toString.call(thing) === '[object Date]';
20650 }
20651
20652 /**
20653 * Public function `fn`.
20654 *
20655 * Returns `true` if something is function, `false` otherwise.
20656 *
20657 * @param thing The thing to test.
20658 */
20659 function fn (thing) {
20660 return typeof thing === 'function';
20661 }
20662
20663 /**
20664 * Public function `webUrl`.
20665 *
20666 * Returns `true` if something is an HTTP or HTTPS URL,
20667 * `false` otherwise.
20668 *
20669 * @param thing The thing to test.
20670 */
20671 function webUrl (thing) {
20672 return unemptyString(thing) && /^https?:\/\/.+/.test(thing);
20673 }
20674
20675 /**
20676 * Public function `gitUrl`.
20677 *
20678 * Returns `true` if something is a git+ssh, git+http or git+https URL,
20679 * `false` otherwise.
20680 *
20681 * @param thing The thing to test.
20682 */
20683 function gitUrl (thing) {
20684 return unemptyString(thing) && /^git\+(ssh|https?):\/\/.+/.test(thing);
20685 }
20686
20687 /**
20688 * Public function `email`.
20689 *
20690 * Returns `true` if something seems like a valid email address,
20691 * `false` otherwise.
20692 *
20693 * @param thing The thing to test.
20694 */
20695 function email (thing) {
20696 return unemptyString(thing) && /\S+@\S+/.test(thing);
20697 }
20698
20699 /**
20700 * Public function `unemptyString`.
20701 *
20702 * Returns `true` if something is a non-empty string, `false`
20703 * otherwise.
20704 *
20705 * @param thing The thing to test.
20706 */
20707 function unemptyString (thing) {
20708 return string(thing) && thing !== '';
20709 }
20710
20711 /**
20712 * Public function `string`.
20713 *
20714 * Returns `true` if something is a string, `false` otherwise.
20715 *
20716 * @param thing The thing to test.
20717 */
20718 function string (thing) {
20719 return typeof thing === 'string';
20720 }
20721
20722 /**
20723 * Public function `oddNumber`.
20724 *
20725 * Returns `true` if something is an odd number,
20726 * `false` otherwise.
20727 *
20728 * @param thing The thing to test.
20729 */
20730 function oddNumber (thing) {
20731 return number(thing) && (thing % 2 === 1 || thing % 2 === -1);
20732 }
20733
20734 /**
20735 * Public function `evenNumber`.
20736 *
20737 * Returns `true` if something is an even number,
20738 * `false` otherwise.
20739 *
20740 * @param thing The thing to test.
20741 */
20742 function evenNumber (thing) {
20743 return number(thing) && thing % 2 === 0;
20744 }
20745
20746 /**
20747 * Public function `intNumber`.
20748 *
20749 * Returns `true` if something is an integer number,
20750 * `false` otherwise.
20751 *
20752 * @param thing The thing to test.
20753 */
20754 function intNumber (thing) {
20755 return number(thing) && thing % 1 === 0;
20756 }
20757
20758 /**
20759 * Public function `floatNumber`.
20760 *
20761 * Returns `true` if something is a float number,
20762 * `false` otherwise.
20763 *
20764 * @param thing The thing to test.
20765 */
20766 function floatNumber (thing) {
20767 return number(thing) && thing % 1 !== 0;
20768 }
20769
20770 /**
20771 * Public function `positiveNumber`.
20772 *
20773 * Returns `true` if something is a positive number,
20774 * `false` otherwise.
20775 *
20776 * @param thing The thing to test.
20777 */
20778 function positiveNumber (thing) {
20779 return number(thing) && thing > 0;
20780 }
20781
20782 /**
20783 * Public function `negativeNumber`.
20784 *
20785 * Returns `true` if something is a positive number,
20786 * `false` otherwise.
20787 *
20788 * @param thing The thing to test.
20789 */
20790 function negativeNumber (thing) {
20791 return number(thing) && thing < 0;
20792 }
20793
20794 /**
20795 * Public function `number`.
20796 *
20797 * Returns `true` if something is a real number,
20798 * `false` otherwise.
20799 *
20800 * @param thing The thing to test.
20801 */
20802 function number (thing) {
20803 return typeof thing === 'number' &&
20804 isNaN(thing) === false &&
20805 thing !== Number.POSITIVE_INFINITY &&
20806 thing !== Number.NEGATIVE_INFINITY;
20807 }
20808
20809 /**
20810 * Public function `bool`.
20811 *
20812 * Returns `true` if something is a bool,
20813 * `false` otherwise.
20814 *
20815 * @param thing The thing to test.
20816 */
20817 function bool (thing) {
20818 return thing === false || thing === true;
20819 }
20820
20821 /**
20822 * Public function `map`.
20823 *
20824 * Returns the results hash of mapping each predicate to the
20825 * corresponding thing's property. Similar to `like` but
20826 * with functions instead of values.
20827 *
20828 * @param things {object} The things to test.
20829 * @param predicates {object} The map of functions to call against
20830 * the corresponding properties from `things`.
20831 */
20832 function map (things, predicates) {
20833 var property, result = {}, predicate;
20834
20835 verify.object(things);
20836 verify.object(predicates);
20837
20838 for (property in predicates) {
20839 if (predicates.hasOwnProperty(property)) {
20840 predicate = predicates[property];
20841
20842 if (fn(predicate)) {
20843 result[property] = predicate(things[property]);
20844 } else if (object(predicate)) {
20845 result[property] = map(things[property], predicate);
20846 }
20847 }
20848 }
20849
20850 return result;
20851 }
20852
20853 /**
20854 * Public function `every`
20855 *
20856 * Returns the conjunction of all booleans in a hash.
20857 *
20858 * @param predicateResults {object} The hash of evaluated predicates.
20859 */
20860 function every (predicateResults) {
20861 var property, value;
20862
20863 verify.object(predicateResults);
20864
20865 for (property in predicateResults) {
20866 if (predicateResults.hasOwnProperty(property)) {
20867 value = predicateResults[property];
20868
20869 if (object(value) && every(value) === false) {
20870 return false;
20871 }
20872
20873 if (value === false) {
20874 return false;
20875 }
20876 }
20877 }
20878 return true;
20879 }
20880
20881 /**
20882 * Public function `any`
20883 *
20884 * Returns the disjunction of all booleans in a hash.
20885 *
20886 * @param predicateResults {object} The hash of evaluated predicates.
20887 */
20888 function any (predicateResults) {
20889 var property, value;
20890
20891 verify.object(predicateResults);
20892
20893 for (property in predicateResults) {
20894 if (predicateResults.hasOwnProperty(property)) {
20895 value = predicateResults[property];
20896
20897 if (object(value) && any(value)) {
20898 return true;
20899 }
20900
20901 if (value === true) {
20902 return true;
20903 }
20904 }
20905 }
20906
20907 return false;
20908 }
20909
20910 function mixin (target, source) {
20911 var property;
20912
20913 for (property in source) {
20914 if (source.hasOwnProperty(property)) {
20915 target[property] = source[property];
20916 }
20917 }
20918
20919 return target;
20920 }
20921
20922 /**
20923 * Public modifier `verify`.
20924 *
20925 * Throws if `predicate` returns `false`.
20926 */
20927 function verifyModifier (predicate, defaultMessage) {
20928 return function () {
20929 var message;
20930
20931 if (predicate.apply(null, arguments) === false) {
20932 message = arguments[arguments.length - 1];
20933 throw new Error(unemptyString(message) ? message : defaultMessage);
20934 }
20935 };
20936 }
20937
20938 /**
20939 * Public modifier `maybe`.
20940 *
20941 * Returns `true` if `predicate` is `null` or `undefined`,
20942 * otherwise propagates the return value from `predicate`.
20943 */
20944 function maybeModifier (predicate) {
20945 return function () {
20946 if (!defined(arguments[0]) || nulled(arguments[0])) {
20947 return true;
20948 }
20949
20950 return predicate.apply(null, arguments);
20951 };
20952 }
20953
20954 /**
20955 * Public modifier `not`.
20956 *
20957 * Negates `predicate`.
20958 */
20959 function notModifier (predicate) {
20960 return function () {
20961 return !predicate.apply(null, arguments);
20962 };
20963 }
20964
20965 function createModifiedPredicates (modifier) {
20966 return createModifiedFunctions(modifier, predicates);
20967 }
20968
20969 function createModifiedFunctions (modifier, functions) {
20970 var name, result = {};
20971
20972 for (name in functions) {
20973 if (functions.hasOwnProperty(name)) {
20974 result[name] = modifier(functions[name], messages[name]);
20975 }
20976 }
20977
20978 return result;
20979 }
20980
20981 function exportFunctions (functions) {
20982 if (true) {
20983 !(__WEBPACK_AMD_DEFINE_RESULT__ = function () {
20984 return functions;
20985 }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
20986 } else if (typeof module !== 'undefined' && module !== null && module.exports) {
20987 module.exports = functions;
20988 } else {
20989 globals.check = functions;
20990 }
20991 }
20992 }(this));
20993
20994
20995/***/ }
20996/******/ ])
20997});
20998;
\No newline at end of file