diff --git a/lodash.src.js b/lodash.src.js index d9930dc21..344396608 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -1162,22 +1162,25 @@ * @returns {*} Returns the unwrapped value. */ function lazyValue() { - var array = this.__wrapped__.value(); - if (!isArray(array)) { - return baseWrapperValue(array, this.__actions__); - } - var dir = this.__dir__, + var array = this.__wrapped__.value(), + dir = this.__dir__, + isArr = isArray(array), isRight = dir < 0, - view = getView(0, array.length, this.__views__), + arrLength = isArr ? array.length : 0, + view = getView(0, arrLength, this.__views__), start = view.start, end = view.end, length = end - start, index = isRight ? end : (start - 1), - takeCount = nativeMin(length, this.__takeCount__), iteratees = this.__iteratees__, iterLength = iteratees.length, resIndex = 0, - result = []; + takeCount = nativeMin(length, this.__takeCount__); + + if (!isArr || (iterLength < 2 && arrLength == length && takeCount == length)) { + return baseWrapperValue(isRight ? array.reverse() : array, this.__actions__); + } + var result = []; outer: while (length-- && resIndex < takeCount) { @@ -3419,12 +3422,14 @@ } } return function() { - var args = arguments; - if (wrapper && args.length == 1 && isArray(args[0])) { - return wrapper.plant(args[0]).value(); + var args = arguments, + value = args[0]; + + if (wrapper && args.length == 1 && isArray(value)) { + return wrapper.plant(value).value(); } var index = 0, - result = length ? funcs[index].apply(this, args) : args[0]; + result = length ? funcs[index].apply(this, args) : value; while (++index < length) { result = funcs[index].call(this, result); @@ -6167,15 +6172,16 @@ var value = this.__wrapped__; var interceptor = function(value) { - return value.reverse(); + return (wrapped && wrapped.__dir__ < 0) ? value : value.reverse(); }; if (value instanceof LazyWrapper) { + var wrapped = value; if (this.__actions__.length) { - value = new LazyWrapper(this); + wrapped = new LazyWrapper(this); } - value = value.reverse(); - value.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash }); - return new LodashWrapper(value, this.__chain__); + wrapped = wrapped.reverse(); + wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash }); + return new LodashWrapper(wrapped, this.__chain__); } return this.thru(interceptor); } diff --git a/test/test.js b/test/test.js index d151692e2..fa3f83d42 100644 --- a/test/test.js +++ b/test/test.js @@ -2240,7 +2240,7 @@ : fn(take2, _.compact, filter2, map2); filterCount = mapCount = 0; - deepEqual(combined(_.range(100)), [4, 16]); + deepEqual(combined(_.range(200)), [4, 16]); if (!isNpm && WeakMap && WeakMap.name) { strictEqual(filterCount, 5, 'filterCount'); @@ -4050,7 +4050,7 @@ args = slice.call(arguments); }).value(); - deepEqual(args, [16]); + deepEqual(args, expected); _(array).map(square).dropRightWhile(function() { args = slice.call(arguments);