Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / globule / node_modules / lodash / _lazyValue.js
1 var baseWrapperValue = require('./_baseWrapperValue'),
2     getView = require('./_getView'),
3     isArray = require('./isArray');
4
5 /** Used as the size to enable large array optimizations. */
6 var LARGE_ARRAY_SIZE = 200;
7
8 /** Used to indicate the type of lazy iteratees. */
9 var LAZY_FILTER_FLAG = 1,
10     LAZY_MAP_FLAG = 2;
11
12 /* Built-in method references for those with the same name as other `lodash` methods. */
13 var nativeMin = Math.min;
14
15 /**
16  * Extracts the unwrapped value from its lazy wrapper.
17  *
18  * @private
19  * @name value
20  * @memberOf LazyWrapper
21  * @returns {*} Returns the unwrapped value.
22  */
23 function lazyValue() {
24   var array = this.__wrapped__.value(),
25       dir = this.__dir__,
26       isArr = isArray(array),
27       isRight = dir < 0,
28       arrLength = isArr ? array.length : 0,
29       view = getView(0, arrLength, this.__views__),
30       start = view.start,
31       end = view.end,
32       length = end - start,
33       index = isRight ? end : (start - 1),
34       iteratees = this.__iteratees__,
35       iterLength = iteratees.length,
36       resIndex = 0,
37       takeCount = nativeMin(length, this.__takeCount__);
38
39   if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
40       (arrLength == length && takeCount == length)) {
41     return baseWrapperValue(array, this.__actions__);
42   }
43   var result = [];
44
45   outer:
46   while (length-- && resIndex < takeCount) {
47     index += dir;
48
49     var iterIndex = -1,
50         value = array[index];
51
52     while (++iterIndex < iterLength) {
53       var data = iteratees[iterIndex],
54           iteratee = data.iteratee,
55           type = data.type,
56           computed = iteratee(value);
57
58       if (type == LAZY_MAP_FLAG) {
59         value = computed;
60       } else if (!computed) {
61         if (type == LAZY_FILTER_FLAG) {
62           continue outer;
63         } else {
64           break outer;
65         }
66       }
67     }
68     result[resIndex++] = value;
69   }
70   return result;
71 }
72
73 module.exports = lazyValue;