mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Bump to v3.0.0.
This commit is contained in:
71
internal/lazyValue.js
Normal file
71
internal/lazyValue.js
Normal file
@@ -0,0 +1,71 @@
|
||||
import baseWrapperValue from './baseWrapperValue';
|
||||
import getView from './getView';
|
||||
import isArray from '../lang/isArray';
|
||||
|
||||
/** Used to indicate the type of lazy iteratees. */
|
||||
var LAZY_FILTER_FLAG = 0,
|
||||
LAZY_MAP_FLAG = 1;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeMin = Math.min;
|
||||
|
||||
/**
|
||||
* Extracts the unwrapped value from its lazy wrapper.
|
||||
*
|
||||
* @private
|
||||
* @name value
|
||||
* @memberOf LazyWrapper
|
||||
* @returns {*} Returns the unwrapped value.
|
||||
*/
|
||||
function lazyValue() {
|
||||
var array = this.wrapped.value();
|
||||
if (!isArray(array)) {
|
||||
return baseWrapperValue(array, this.actions);
|
||||
}
|
||||
var dir = this.dir,
|
||||
isRight = dir < 0,
|
||||
length = array.length,
|
||||
view = getView(0, length, this.views),
|
||||
start = view.start,
|
||||
end = view.end,
|
||||
dropCount = this.dropCount,
|
||||
takeCount = nativeMin(end - start, this.takeCount - dropCount),
|
||||
index = isRight ? end : start - 1,
|
||||
iteratees = this.iteratees,
|
||||
iterLength = iteratees ? iteratees.length : 0,
|
||||
resIndex = 0,
|
||||
result = [];
|
||||
|
||||
outer:
|
||||
while (length-- && resIndex < takeCount) {
|
||||
index += dir;
|
||||
|
||||
var iterIndex = -1,
|
||||
value = array[index];
|
||||
|
||||
while (++iterIndex < iterLength) {
|
||||
var data = iteratees[iterIndex],
|
||||
iteratee = data.iteratee,
|
||||
computed = iteratee(value, index, array),
|
||||
type = data.type;
|
||||
|
||||
if (type == LAZY_MAP_FLAG) {
|
||||
value = computed;
|
||||
} else if (!computed) {
|
||||
if (type == LAZY_FILTER_FLAG) {
|
||||
continue outer;
|
||||
} else {
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dropCount) {
|
||||
dropCount--;
|
||||
} else {
|
||||
result[resIndex++] = value;
|
||||
}
|
||||
}
|
||||
return isRight ? result.reverse() : result;
|
||||
}
|
||||
|
||||
export default lazyValue;
|
||||
Reference in New Issue
Block a user