diff --git a/lodash.js b/lodash.js index 7d81a7106..19023f4e2 100644 --- a/lodash.js +++ b/lodash.js @@ -4982,6 +4982,12 @@ * // => [3, 2, 1] */ function wrapperReverse() { + var wrapped = this.__wrapped__; + + if(wrapped instanceof LazyWrapper) { + return wrapped.reverse(); + } + return this.thru(function(value) { return value.reverse(); }); diff --git a/test/test.js b/test/test.js index 12b77eb05..3431def75 100644 --- a/test/test.js +++ b/test/test.js @@ -12941,6 +12941,27 @@ skipTest(2); } }); + + + test('should be lazy when in a lazy chain sequence', 1, function() { + if (!isNpm) { + var spy = { + toString: function () { + throw new Error("Spy was revealed"); + } + }; + + var actual = _(["a", spy]) + .map(String) + .reverse() + .last(); + + strictEqual(actual, "a"); + } + else { + skipTest(1); + } + }); }()); /*--------------------------------------------------------------------------*/