Rebuild lodash.

This commit is contained in:
jdalton
2015-02-09 01:14:55 -08:00
parent 954b4d8075
commit 3b805f1a24
2 changed files with 367 additions and 187 deletions

397
lodash.js
View File

@@ -728,7 +728,6 @@
setTimeout = context.setTimeout,
splice = arrayProto.splice,
Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
unshift = arrayProto.unshift,
WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap;
/** Used to clone array buffers. */
@@ -780,7 +779,7 @@
/*------------------------------------------------------------------------*/
/**
* Creates a `lodash` object which wraps `value` to enable intuitive chaining.
* Creates a `lodash` object which wraps `value` to enable implicit chaining.
* Methods that operate on and return arrays, collections, and functions can
* be chained together. Methods that return a boolean or single value will
* automatically end the chain returning the unwrapped value. Explicit chaining
@@ -806,20 +805,21 @@
*
* The chainable wrapper functions are:
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
* `callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`,
* `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`,
* `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`,
* `flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`,
* `forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`,
* `initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`,
* `mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`,
* `omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`,
* `pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`,
* `rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
* `sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`,
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`,
* `where`, `without`, `wrap`, `xor`, `zip`, and `zipObject`
* `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
* `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
* `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
* `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
* `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
* `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
* `keysIn`, `map`, `mapValues`, `matches`, `memoize`, `merge`, `mixin`,
* `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`,
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
* `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
* `unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`,
* `zip`, and `zipObject`
*
* The wrapper functions that are **not** chainable by default are:
* `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
@@ -843,7 +843,7 @@
* @constructor
* @category Chain
* @param {*} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns a `lodash` instance.
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var wrapped = _([1, 2, 3]);
@@ -862,12 +862,12 @@
* // => true
*/
function lodash(value) {
if (isObjectLike(value) && !isArray(value)) {
if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
if (value instanceof LodashWrapper) {
return value;
}
if (hasOwnProperty.call(value, '__wrapped__')) {
return new LodashWrapper(value.__wrapped__, value.__chain__, arrayCopy(value.__actions__));
if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
return wrapperClone(value);
}
}
return new LodashWrapper(value);
@@ -882,9 +882,9 @@
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
*/
function LodashWrapper(value, chainAll, actions) {
this.__wrapped__ = value;
this.__actions__ = actions || [];
this.__chain__ = !!chainAll;
this.__wrapped__ = value;
}
/**
@@ -1017,14 +1017,14 @@
* @param {*} value The value to wrap.
*/
function LazyWrapper(value) {
this.actions = null;
this.dir = 1;
this.dropCount = 0;
this.filtered = false;
this.iteratees = null;
this.takeCount = POSITIVE_INFINITY;
this.views = null;
this.wrapped = value;
this.__wrapped__ = value;
this.__actions__ = null;
this.__dir__ = 1;
this.__dropCount__ = 0;
this.__filtered__ = false;
this.__iteratees__ = null;
this.__takeCount__ = POSITIVE_INFINITY;
this.__views__ = null;
}
/**
@@ -1036,18 +1036,18 @@
* @returns {Object} Returns the cloned `LazyWrapper` object.
*/
function lazyClone() {
var actions = this.actions,
iteratees = this.iteratees,
views = this.views,
result = new LazyWrapper(this.wrapped);
var actions = this.__actions__,
iteratees = this.__iteratees__,
views = this.__views__,
result = new LazyWrapper(this.__wrapped__);
result.actions = actions ? arrayCopy(actions) : null;
result.dir = this.dir;
result.dropCount = this.dropCount;
result.filtered = this.filtered;
result.iteratees = iteratees ? arrayCopy(iteratees) : null;
result.takeCount = this.takeCount;
result.views = views ? arrayCopy(views) : null;
result.__actions__ = actions ? arrayCopy(actions) : null;
result.__dir__ = this.__dir__;
result.__dropCount__ = this.__dropCount__;
result.__filtered__ = this.__filtered__;
result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
result.__takeCount__ = this.__takeCount__;
result.__views__ = views ? arrayCopy(views) : null;
return result;
}
@@ -1060,13 +1060,13 @@
* @returns {Object} Returns the new reversed `LazyWrapper` object.
*/
function lazyReverse() {
if (this.filtered) {
if (this.__filtered__) {
var result = new LazyWrapper(this);
result.dir = -1;
result.filtered = true;
result.__dir__ = -1;
result.__filtered__ = true;
} else {
result = this.clone();
result.dir *= -1;
result.__dir__ *= -1;
}
return result;
}
@@ -1080,20 +1080,20 @@
* @returns {*} Returns the unwrapped value.
*/
function lazyValue() {
var array = this.wrapped.value();
var array = this.__wrapped__.value();
if (!isArray(array)) {
return baseWrapperValue(array, this.actions);
return baseWrapperValue(array, this.__actions__);
}
var dir = this.dir,
var dir = this.__dir__,
isRight = dir < 0,
view = getView(0, array.length, this.views),
view = getView(0, array.length, this.__views__),
start = view.start,
end = view.end,
length = end - start,
dropCount = this.dropCount,
takeCount = nativeMin(length, this.takeCount - dropCount),
dropCount = this.__dropCount__,
takeCount = nativeMin(length, this.__takeCount__ - dropCount),
index = isRight ? end : start - 1,
iteratees = this.iteratees,
iteratees = this.__iteratees__,
iterLength = iteratees ? iteratees.length : 0,
resIndex = 0,
result = [];
@@ -1749,7 +1749,7 @@
* @returns {number} Returns the timer id.
*/
function baseDelay(func, wait, args, fromIndex) {
if (!isFunction(func)) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
@@ -1869,6 +1869,36 @@
return result;
}
/**
* The base implementation of `_.fill` without an iteratee call guard.
*
* @private
* @param {Array} array The array to fill.
* @param {*} value The value to fill `array` with.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
*/
function baseFill(array, value, start, end) {
var length = array.length;
start = start == null ? 0 : (+start || 0);
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
if (end < 0) {
end += length;
}
length = start > end ? 0 : end >>> 0;
start >>>= 0;
while (start < length) {
array[start++] = value;
}
return array;
}
/**
* The base implementation of `_.filter` without support for callback
* shorthands or `this` binding.
@@ -2201,7 +2231,7 @@
* shorthands or `this` binding.
*
* @private
* @param {Object} source The object to inspect.
* @param {Object} object The object to inspect.
* @param {Array} props The source property names to match.
* @param {Array} values The source values to match.
* @param {Array} strictCompareFlags Strict comparison flags for source values.
@@ -3173,7 +3203,7 @@
*/
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
var isBindKey = bitmask & BIND_KEY_FLAG;
if (!isBindKey && !isFunction(func)) {
if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
var length = partials ? partials.length : 0;
@@ -3203,9 +3233,9 @@
if (bitmask == BIND_FLAG) {
var result = createBindWrapper(newData[0], newData[2]);
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
result = createPartialWrapper.apply(null, newData);
result = createPartialWrapper.apply(undefined, newData);
} else {
result = createHybridWrapper.apply(null, newData);
result = createHybridWrapper.apply(undefined, newData);
}
var setter = data ? baseSetData : setData;
return setter(result, newData);
@@ -3893,6 +3923,19 @@
return isObject(value) ? value : Object(value);
}
/**
* Creates a clone of `wrapper`.
*
* @private
* @param {Object} wrapper The wrapper to clone.
* @returns {Object} Returns the cloned wrapper.
*/
function wrapperClone(wrapper) {
return wrapper instanceof LazyWrapper
? wrapper.clone()
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
}
/*------------------------------------------------------------------------*/
/**
@@ -3904,7 +3947,7 @@
* @memberOf _
* @category Array
* @param {Array} array The array to process.
* @param {numer} [size=1] The length of each chunk.
* @param {number} [size=1] The length of each chunk.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the new array containing chunks.
* @example
@@ -3999,7 +4042,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop.
@@ -4035,7 +4077,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop.
@@ -4081,7 +4122,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
@@ -4131,7 +4171,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
@@ -4168,6 +4207,31 @@
return baseSlice(array, index);
}
/**
* Fills elements of `array` with `value` from `start` up to, but not
* including, `end`.
*
* **Note:** This method mutates `array`.
*
* @private
* @param {Array} array The array to fill.
* @param {*} value The value to fill `array` with.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
*/
function fill(array, value, start, end) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
start = 0;
end = length;
}
return baseFill(array, value, start, end);
}
/**
* This method is like `_.find` except that it returns the index of the first
* element `predicate` returns truthy for, instead of the element itself.
@@ -4782,7 +4846,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take.
@@ -4818,7 +4881,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take.
@@ -4864,7 +4926,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
@@ -4914,7 +4975,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked
@@ -5199,7 +5259,7 @@
* @memberOf _
* @category Chain
* @param {*} value The value to wrap.
* @returns {Object} Returns the new `lodash` object.
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var users = [
@@ -5275,7 +5335,7 @@
* @name chain
* @memberOf _
* @category Chain
* @returns {*} Returns the `lodash` object.
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var users = [
@@ -5298,6 +5358,74 @@
return chain(this);
}
/**
* Executes the chained sequence and returns the wrapped result.
*
* @name commit
* @memberOf _
* @category Chain
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var array = [1, 2];
* var wrapper = _(array).push(3);
*
* console.log(array);
* // => [1, 2]
*
* wrapper = wrapper.commit();
* console.log(array);
* // => [1, 2, 3]
*
* wrapper.last();
* // => 3
*
* console.log(array);
* // => [1, 2, 3]
*/
function wrapperCommit() {
return new LodashWrapper(this.value());
}
/**
* Creates a clone of the chained sequence planting `value` as the wrapped value.
*
* @name plant
* @memberOf _
* @category Chain
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var array = [1, 2];
* var wrapper = _(array).map(_.partial(Math.pow, _, 2));
*
* var other = [3, 4];
* var otherWrapper = wrapper.plant(other);
*
* otherWrapper.value();
* // => [9, 16]
*
* wrapper.value();
* // => [1, 4]
*/
function wrapperPlant(value) {
var result,
parent = this;
while (parent instanceof LodashWrapper) {
var clone = wrapperClone(parent);
if (result) {
previous.__wrapped__ = clone;
} else {
result = clone;
}
var previous = clone;
parent = parent.__wrapped__;
}
previous.__wrapped__ = value;
return result;
}
/**
* Reverses the wrapped array so the first element becomes the last, the
* second element becomes the second to last, and so on.
@@ -5307,7 +5435,7 @@
* @name reverse
* @memberOf _
* @category Chain
* @returns {Object} Returns the new reversed `lodash` object.
* @returns {Object} Returns the new reversed `lodash` wrapper instance.
* @example
*
* var array = [1, 2, 3];
@@ -5352,7 +5480,7 @@
*
* @name value
* @memberOf _
* @alias toJSON, valueOf
* @alias run, toJSON, valueOf
* @category Chain
* @returns {*} Returns the resolved unwrapped value.
* @example
@@ -6471,8 +6599,8 @@
* // => logs 'done saving!' after the two async saves have completed
*/
function after(n, func) {
if (!isFunction(func)) {
if (isFunction(n)) {
if (typeof func != 'function') {
if (typeof n == 'function') {
var temp = n;
n = func;
func = temp;
@@ -6530,8 +6658,8 @@
*/
function before(n, func) {
var result;
if (!isFunction(func)) {
if (isFunction(n)) {
if (typeof func != 'function') {
if (typeof n == 'function') {
var temp = n;
n = func;
func = temp;
@@ -6853,7 +6981,7 @@
maxWait = false,
trailing = true;
if (!isFunction(func)) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
wait = wait < 0 ? 0 : wait;
@@ -7023,7 +7151,7 @@
length = funcs.length;
if (!length) {
return function() {};
return function() { return arguments[0]; };
}
if (!arrayEvery(funcs, isFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
@@ -7068,7 +7196,7 @@
fromIndex = funcs.length - 1;
if (fromIndex < 0) {
return function() {};
return function() { return arguments[0]; };
}
if (!arrayEvery(funcs, isFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
@@ -7138,7 +7266,7 @@
* // => { 'user': 'barney' }
*/
function memoize(func, resolver) {
if (!isFunction(func) || (resolver && !isFunction(resolver))) {
if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var memoized = function() {
@@ -7176,7 +7304,7 @@
* // => [1, 3, 5]
*/
function negate(predicate) {
if (!isFunction(predicate)) {
if (typeof predicate != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
@@ -7191,7 +7319,6 @@
*
* @static
* @memberOf _
* @type Function
* @category Function
* @param {Function} func The function to restrict.
* @returns {Function} Returns the new restricted function.
@@ -7314,6 +7441,48 @@
return createWrapper(func, REARG_FLAG, null, null, null, indexes);
}
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg`
* and the array of arguments provided to the created function much like
* [Function#apply](http://es5.github.io/#x15.3.4.3).
*
* @static
* @memberOf _
* @category Function
* @param {Function} The function to spread arguments over.
* @param {*} [thisArg] The `this` binding of `func`.
* @returns {*} Returns the new function.
* @example
*
* var spread = _.spread(function(who, what) {
* return who + ' says ' + what;
* });
*
* spread(['Fred', 'hello']);
* // => 'Fred says hello'
*
* // with a Promise
* var numbers = Promise.all([
* Promise.resolve(40),
* Promise.resolve(36)
* ]);
*
* var add = function(x, y) {
* return x + y;
* };
*
* numbers.then(_.spread(add));
* // => a Promise of 76
*/
function spread(func, thisArg) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function(array) {
return func.apply(thisArg, array);
};
}
/**
* Creates a function that only invokes `func` at most once per every `wait`
* milliseconds. The created function comes with a `cancel` method to cancel
@@ -7356,7 +7525,7 @@
var leading = true,
trailing = true;
if (!isFunction(func)) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
if (options === false) {
@@ -7832,7 +8001,7 @@
* @static
* @memberOf _
* @category Lang
* @param {Object} source The object to inspect.
* @param {Object} object The object to inspect.
* @param {Object} source The object of property values to match.
* @param {Function} [customizer] The function to customize comparing values.
* @param {*} [thisArg] The `this` binding of `customizer`.
@@ -8620,7 +8789,7 @@
var Ctor = object.constructor,
index = -1,
isProto = typeof Ctor == 'function' && Ctor.prototype == object,
isProto = typeof Ctor == 'function' && Ctor.prototype === object,
result = Array(length),
skipIndexes = length > 0;
@@ -8913,7 +9082,7 @@
if (isArr) {
accumulator = isArray(object) ? new Ctor : [];
} else {
accumulator = baseCreate(typeof Ctor == 'function' && Ctor.prototype);
accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype);
}
} else {
accumulator = {};
@@ -9916,8 +10085,8 @@
/*------------------------------------------------------------------------*/
/**
* Attempts to invoke `func`, returning either the result or the caught
* error object.
* Attempts to invoke `func`, returning either the result or the caught error
* object. Any additional arguments are provided to `func` when it is invoked.
*
* @static
* @memberOf _
@@ -9927,9 +10096,9 @@
* @example
*
* // avoid throwing errors for invalid selectors
* var elements = _.attempt(function() {
* var elements = _.attempt(function(selector) {
* return document.querySelectorAll(selector);
* });
* }, '>_>');
*
* if (_.isError(elements)) {
* elements = [];
@@ -9937,17 +10106,18 @@
*/
function attempt(func) {
try {
return func();
return func.apply(undefined, baseSlice(arguments, 1));
} catch(e) {
return isError(e) ? e : Error(e);
}
}
/**
* Creates a function bound to an optional `thisArg`. If `func` is a property
* name the created callback returns the property value for a given element.
* If `func` is an object the created callback returns `true` for elements
* that contain the equivalent object properties, otherwise it returns `false`.
* Creates a function that invokes `func` with the `this` binding of `thisArg`
* and arguments of the created function. If `func` is a property name the
* created callback returns the property value for a given element. If `func`
* is an object the created callback returns `true` for elements that contain
* the equivalent object properties, otherwise it returns `false`.
*
* @static
* @memberOf _
@@ -10077,6 +10247,9 @@
* });
* }
*
* // use `_.runInContext` to avoid potential conflicts (esp. in Node.js)
* var _ = require('lodash').runInContext();
*
* _.mixin({ 'vowels': vowels });
* _.vowels('fred');
* // => ['e']
@@ -10351,7 +10524,11 @@
/*------------------------------------------------------------------------*/
// Ensure `new LodashWrapper` is an instance of `lodash`.
LodashWrapper.prototype = lodash.prototype;
LodashWrapper.prototype = baseCreate(lodash.prototype);
// Ensure `new LazyWraper` is an instance of `LodashWrapper`
LazyWrapper.prototype = baseCreate(LodashWrapper.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
// Add functions to the `Map` cache.
MapCache.prototype['delete'] = mapDelete;
@@ -10392,6 +10569,7 @@
lodash.dropRight = dropRight;
lodash.dropRightWhile = dropRightWhile;
lodash.dropWhile = dropWhile;
lodash.fill = fill;
lodash.filter = filter;
lodash.flatten = flatten;
lodash.flattenDeep = flattenDeep;
@@ -10440,6 +10618,7 @@
lodash.slice = slice;
lodash.sortBy = sortBy;
lodash.sortByAll = sortByAll;
lodash.spread = spread;
lodash.take = take;
lodash.takeRight = takeRight;
lodash.takeRightWhile = takeRightWhile;
@@ -10613,14 +10792,15 @@
// Add `LazyWrapper` methods that accept an `iteratee` value.
arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
var isFilter = index == LAZY_FILTER_FLAG;
var isFilter = index == LAZY_FILTER_FLAG,
isWhile = index == LAZY_WHILE_FLAG;
LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
var result = this.clone(),
filtered = result.filtered,
iteratees = result.iteratees || (result.iteratees = []);
filtered = result.__filtered__,
iteratees = result.__iteratees__ || (result.__iteratees__ = []);
result.filtered = filtered || isFilter || (index == LAZY_WHILE_FLAG && result.dir < 0);
result.__filtered__ = filtered || isFilter || (isWhile && result.__dir__ < 0);
iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 3), 'type': index });
return result;
};
@@ -10628,19 +10808,19 @@
// Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
arrayEach(['drop', 'take'], function(methodName, index) {
var countName = methodName + 'Count',
var countName = '__' + methodName + 'Count__',
whileName = methodName + 'While';
LazyWrapper.prototype[methodName] = function(n) {
n = n == null ? 1 : nativeMax(+n || 0, 0);
var result = this.clone();
if (result.filtered) {
if (result.__filtered__) {
var value = result[countName];
result[countName] = index ? nativeMin(value, n) : (value + n);
} else {
var views = result.views || (result.views = []);
views.push({ 'size': n, 'type': methodName + (result.dir < 0 ? 'Right' : '') });
var views = result.__views__ || (result.__views__ = []);
views.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
}
return result;
};
@@ -10683,14 +10863,9 @@
});
LazyWrapper.prototype.dropWhile = function(iteratee, thisArg) {
var done,
lastIndex,
isRight = this.dir < 0;
var done;
iteratee = getCallback(iteratee, thisArg, 3);
return this.filter(function(value, index, array) {
done = done && (isRight ? index < lastIndex : index > lastIndex);
lastIndex = index;
return done || (done = !iteratee(value, index, array));
});
};
@@ -10740,8 +10915,8 @@
var wrapper = onlyLazy ? value : new LazyWrapper(this),
result = func.apply(wrapper, args);
if (!retUnwrapped && (isHybrid || result.actions)) {
var actions = result.actions || (result.actions = []);
if (!retUnwrapped && (isHybrid || result.__actions__)) {
var actions = result.__actions__ || (result.__actions__ = []);
actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
}
return new LodashWrapper(result, chainAll);
@@ -10774,9 +10949,11 @@
// Add chaining functions to the lodash wrapper.
lodash.prototype.chain = wrapperChain;
lodash.prototype.commit = wrapperCommit;
lodash.prototype.plant = wrapperPlant;
lodash.prototype.reverse = wrapperReverse;
lodash.prototype.toString = wrapperToString;
lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
// Add function aliases to the lodash wrapper.
lodash.prototype.collect = lodash.prototype.map;