Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / lazyValue.js
1 var baseWrapperValue = require('./baseWrapperValue'),
2     getView = require('./getView'),
3     isArray = require('../lang/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 /* Native 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 || (arrLength == length && takeCount == length)) {
40     return baseWrapperValue(array, this.__actions__);
41   }
42   var result = [];
43
44   outer:
45   while (length-- && resIndex < takeCount) {
46     index += dir;
47
48     var iterIndex = -1,
49         value = array[index];
50
51     while (++iterIndex < iterLength) {
52       var data = iteratees[iterIndex],
53           iteratee = data.iteratee,
54           type = data.type,
55           computed = iteratee(value);
56
57       if (type == LAZY_MAP_FLAG) {
58         value = computed;
59       } else if (!computed) {
60         if (type == LAZY_FILTER_FLAG) {
61           continue outer;
62         } else {
63           break outer;
64         }
65       }
66     }
67     result[resIndex++] = value;
68   }
69   return result;
70 }
71
72 module.exports = lazyValue;