Ensure lazy takeWhile works with reverse and last`. [closes #990]

This commit is contained in:
jdalton
2015-02-23 01:24:04 -08:00
parent 76d3959f1a
commit 5613f60403
2 changed files with 15 additions and 8 deletions

View File

@@ -11437,7 +11437,7 @@
filtered = result.__filtered__,
iteratees = result.__iteratees__ || (result.__iteratees__ = []);
result.__filtered__ = filtered || isFilter || (isWhile && result.__dir__ < 0);
result.__filtered__ = filtered || isFilter || isWhile;
iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 3), 'type': index });
return result;
};
@@ -11504,9 +11504,14 @@
};
LazyWrapper.prototype.dropWhile = function(predicate, thisArg) {
var done;
var done,
lastIndex,
isRight = this.__dir__ < 0;
predicate = getCallback(predicate, thisArg, 3);
return this.filter(function(value, index, array) {
done = done && (isRight ? index < lastIndex : index > lastIndex);
lastIndex = index;
return done || (done = !predicate(value, index, array));
});
};

View File

@@ -3971,17 +3971,18 @@
deepEqual(_.dropWhile(objects, 'b'), objects.slice(2));
});
test('should return a wrapped value when chaining', 2, function() {
test('should work in a lazy chain sequence', 3, function() {
if (!isNpm) {
var wrapped = _(array).dropWhile(function(num) {
return num < 3;
});
ok(wrapped instanceof _);
deepEqual(wrapped.value(), [3, 4]);
deepEqual(wrapped.reverse().value(), [4, 3]);
strictEqual(wrapped.last(), 4);
}
else {
skipTest(2);
skipTest(3);
}
});
@@ -4856,17 +4857,18 @@
deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2));
});
test('should return a wrapped value when chaining', 2, function() {
test('should work in a lazy chain sequence', 3, function() {
if (!isNpm) {
var wrapped = _(array).takeWhile(function(num) {
return num < 3;
});
ok(wrapped instanceof _);
deepEqual(wrapped.value(), [1, 2]);
deepEqual(wrapped.reverse().value(), [2, 1]);
strictEqual(wrapped.last(), 2);
}
else {
skipTest(2);
skipTest(3);
}
});