Merge pull request #790 from FilipZawada/lazy-first-last

Fix non-lazy calls not executed before `first` & `last`.
This commit is contained in:
John-David Dalton
2014-11-21 14:02:42 -08:00
2 changed files with 20 additions and 10 deletions

View File

@@ -2140,7 +2140,7 @@
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/ */
function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) { function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) {
var result = customizer && !stackA ? customizer(value, other) : undefined; var result = (customizer && !stackA) ? customizer(value, other) : undefined;
if (typeof result != 'undefined') { if (typeof result != 'undefined') {
return !!result; return !!result;
} }
@@ -10208,7 +10208,7 @@
}); });
// Add `LazyWrapper` methods for `_.pluck` and `_.where`. // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
arrayEach(['pluck', 'where'], function (methodName, index) { arrayEach(['pluck', 'where'], function(methodName, index) {
var operationName = index ? 'filter' : 'map', var operationName = index ? 'filter' : 'map',
createCallback = index ? matches : property; createCallback = index ? matches : property;
@@ -10258,18 +10258,18 @@
var args = arguments, var args = arguments,
chainAll = this.__chain__, chainAll = this.__chain__,
value = this.__wrapped__, value = this.__wrapped__,
isLazy = value instanceof LazyWrapper; isLazy = value instanceof LazyWrapper,
noQueue = !this.__queue__.length,
unwrap = retUnwrapped && !chainAll;
if (retUnwrapped && !chainAll) { if (unwrap && !isLazy) {
return isLazy return lodash[methodName](this.value());
? func.call(value)
: lodash[methodName](this.value());
} }
if (isLazy || isArray(value)) { if (isLazy || isArray(value)) {
var wrapper = (isLazy && !this.__queue__.length) ? value : new LazyWrapper(this), var wrapper = (isLazy && noQueue) ? value : new LazyWrapper(this),
result = func.apply(wrapper, args); result = func.apply(wrapper, args);
return new LodashWrapper(result, chainAll); return unwrap ? result : new LodashWrapper(result, chainAll);
} }
return this.thru(function(value) { return this.thru(function(value) {
var otherArgs = [value]; var otherArgs = [value];

View File

@@ -2390,7 +2390,7 @@
strictEqual(callback('a'), true); strictEqual(callback('a'), true);
var fn = function () {}, var fn = function() {},
bound = fn.bind && fn.bind(object); bound = fn.bind && fn.bind(object);
if (bound) { if (bound) {
@@ -12702,6 +12702,16 @@
skipTest(2); skipTest(2);
} }
}); });
test('should work when in a lazy chain sequence, before `.last`', 1, function() {
if (!isNpm) {
var actual = _([1, 2, 3]).map().xor([4]).last();
strictEqual(actual, 4);
}
else {
skipTest(2);
}
});
}(1, 2, 3)); }(1, 2, 3));
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/