Ensure length hit of for lazy eval is checked on initial lazy call. [closes #997]

This commit is contained in:
jdalton
2015-03-05 22:47:32 -08:00
parent 1dfaa30520
commit 9cdf013933
2 changed files with 56 additions and 17 deletions

View File

@@ -11674,12 +11674,13 @@
chainAll = this.__chain__,
value = this.__wrapped__,
isHybrid = !!this.__actions__.length,
isLazy = value instanceof LazyWrapper;
isLazy = value instanceof LazyWrapper,
iteratee = args[0],
useLazy = isLazy || isArray(value);
if (isLazy && checkIteratee) {
if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
// avoid lazy use if the iteratee has a `length` other than `1`
var iteratee = args[0];
isLazy = !(typeof iteratee == 'function' && iteratee.length != 1);
isLazy = useLazy = false;
}
var onlyLazy = isLazy && !isHybrid;
if (retUnwrapped && !chainAll) {
@@ -11692,7 +11693,7 @@
push.apply(otherArgs, args);
return lodashFunc.apply(lodash, otherArgs);
};
if (isLazy || isArray(value)) {
if (useLazy) {
var wrapper = onlyLazy ? value : new LazyWrapper(this),
result = func.apply(wrapper, args);

View File

@@ -3986,11 +3986,17 @@
}
});
test('should provide the correct `predicate` arguments in a lazy chain sequence', 4, function() {
test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() {
if (!isNpm) {
var args,
expected = [16, 3, [1, 4, 9 ,16]];
_(array).dropRightWhile(function(value, index, array) {
args = slice.call(arguments);
}).value();
deepEqual(args, [4, 3, array]);
_(array).map(square).dropRightWhile(function(value, index, array) {
args = slice.call(arguments);
}).value();
@@ -4016,7 +4022,7 @@
deepEqual(args, expected);
}
else {
skipTest(4);
skipTest(5);
}
});
}());
@@ -4102,11 +4108,17 @@
}
});
test('should provide the correct `predicate` arguments in a lazy chain sequence', 4, function() {
test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() {
if (!isNpm) {
var args,
expected = [1, 0, [1, 4, 9, 16]];
_(array).dropWhile(function(value, index, array) {
args = slice.call(arguments);
}).value();
deepEqual(args, [1, 0, array]);
_(array).map(square).dropWhile(function(value, index, array) {
args = slice.call(arguments);
}).value();
@@ -4132,7 +4144,7 @@
deepEqual(args, expected);
}
else {
skipTest(4);
skipTest(5);
}
});
}());
@@ -4936,11 +4948,17 @@
}
});
test('should provide the correct `predicate` arguments in a lazy chain sequence', 4, function() {
test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() {
if (!isNpm) {
var args,
expected = [16, 3, [1, 4, 9 , 16]];
_(array).takeRightWhile(function(value, index, array) {
args = slice.call(arguments)
}).value();
deepEqual(args, [4, 3, array]);
_(array).map(square).takeRightWhile(function(value, index, array) {
args = slice.call(arguments)
}).value();
@@ -4966,7 +4984,7 @@
deepEqual(args, expected);
}
else {
skipTest(4);
skipTest(5);
}
});
}());
@@ -5051,11 +5069,17 @@
}
});
test('should provide the correct `predicate` arguments in a lazy chain sequence', 4, function() {
test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() {
if (!isNpm) {
var args,
expected = [1, 0, [1, 4, 9, 16]];
_(array).takeWhile(function(value, index, array) {
args = slice.call(arguments);
}).value();
deepEqual(args, [1, 0, array]);
_(array).map(square).takeWhile(function(value, index, array) {
args = slice.call(arguments);
}).value();
@@ -5081,7 +5105,7 @@
deepEqual(args, expected);
}
else {
skipTest(4);
skipTest(5);
}
});
}());
@@ -9223,11 +9247,18 @@
}
});
test('should provide the correct `predicate` arguments in a lazy chain sequence', 4, function() {
test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() {
if (!isNpm) {
var args,
expected = [1, 0, [1, 4, 9]];
_(array).map(function(value, index, array) {
args || (args = slice.call(arguments));
}).value();
deepEqual(args, [1, 0, array]);
args = null;
_(array).map(square).map(function(value, index, array) {
args || (args = slice.call(arguments));
}).value();
@@ -9256,7 +9287,7 @@
deepEqual(args, expected);
}
else {
skipTest(4);
skipTest(5);
}
});
@@ -12210,11 +12241,18 @@
}
});
test('`_.' + methodName + '` should provide the correct `predicate` arguments in a lazy chain sequence', 4, function() {
test('`_.' + methodName + '` should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() {
if (!isNpm) {
var args,
expected = [1, 0, [1, 4, 9, 16]];
_(array)[methodName](function(value, index, array) {
args || (args = slice.call(arguments));
}).value();
deepEqual(args, [1, 0, array]);
args = null;
_(array).map(square)[methodName](function(value, index, array) {
args || (args = slice.call(arguments));
}).value();
@@ -12243,7 +12281,7 @@
deepEqual(args, expected);
}
else {
skipTest(4);
skipTest(5);
}
});
});