SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 2048 JavaScript
2016-01-28 01:16:24 -08:00
define(['./_baseWrapperValue', './_getView', './isArray'], function(baseWrapperValue, getView, isArray) {
2015-01-08 00:37:01 -08:00
/** Used to indicate the type of lazy iteratees. */
2015-12-16 17:52:15 -08:00
var LAZY_FILTER_FLAG = 1,
2015-12-16 17:48:35 -08:00
LAZY_MAP_FLAG = 2;
2015-01-08 00:37:01 -08:00
2015-12-16 17:53:20 -08:00
/* Built-in method references for those with the same name as other `lodash` methods. */
2015-01-08 00:37:01 -08:00
var nativeMin = Math.min;
/**
* Extracts the unwrapped value from its lazy wrapper.
*
* @private
* @name value
* @memberOf LazyWrapper
* @returns {*} Returns the unwrapped value.
*/
function lazyValue() {
2015-12-16 17:52:15 -08:00
var array = this.__wrapped__.value(),
dir = this.__dir__,
isArr = isArray(array),
2015-01-08 00:37:01 -08:00
isRight = dir < 0,
2015-12-16 17:52:15 -08:00
arrLength = isArr ? array.length : 0,
view = getView(0, arrLength, this.__views__),
2015-01-08 00:37:01 -08:00
start = view.start,
end = view.end,
2015-01-26 20:13:55 -08:00
length = end - start,
2015-12-16 17:48:35 -08:00
index = isRight ? end : (start - 1),
2015-12-16 17:46:22 -08:00
iteratees = this.__iteratees__,
2015-12-16 17:52:15 -08:00
iterLength = iteratees.length,
2015-01-08 00:37:01 -08:00
resIndex = 0,
2015-12-16 17:52:15 -08:00
takeCount = nativeMin(length, this.__takeCount__);
2016-12-19 17:17:56 -06:00
if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
2015-12-16 17:52:47 -08:00
return baseWrapperValue(array, this.__actions__);
2015-12-16 17:52:15 -08:00
}
var result = [];
2015-01-08 00:37:01 -08:00
outer:
while (length-- && resIndex < takeCount) {
index += dir;
var iterIndex = -1,
value = array[index];
while (++iterIndex < iterLength) {
var data = iteratees[iterIndex],
iteratee = data.iteratee,
2015-12-16 17:52:15 -08:00
type = data.type,
computed = iteratee(value);
2015-01-08 00:37:01 -08:00
2015-12-16 17:52:15 -08:00
if (type == LAZY_MAP_FLAG) {
value = computed;
} else if (!computed) {
if (type == LAZY_FILTER_FLAG) {
continue outer;
} else {
break outer;
2015-01-08 00:37:01 -08:00
}
}
}
2015-12-16 17:48:35 -08:00
result[resIndex++] = value;
2015-01-08 00:37:01 -08:00
}
2015-01-26 20:13:55 -08:00
return result;
2015-01-08 00:37:01 -08:00
}
return lazyValue;
});