1 |
3a515b92
|
cagy
|
var baseLodash = require('./_baseLodash'),
|
2 |
|
|
wrapperClone = require('./_wrapperClone');
|
3 |
|
|
|
4 |
|
|
/**
|
5 |
|
|
* Creates a clone of the chain sequence planting `value` as the wrapped value.
|
6 |
|
|
*
|
7 |
|
|
* @name plant
|
8 |
|
|
* @memberOf _
|
9 |
|
|
* @since 3.2.0
|
10 |
|
|
* @category Seq
|
11 |
|
|
* @param {*} value The value to plant.
|
12 |
|
|
* @returns {Object} Returns the new `lodash` wrapper instance.
|
13 |
|
|
* @example
|
14 |
|
|
*
|
15 |
|
|
* function square(n) {
|
16 |
|
|
* return n * n;
|
17 |
|
|
* }
|
18 |
|
|
*
|
19 |
|
|
* var wrapped = _([1, 2]).map(square);
|
20 |
|
|
* var other = wrapped.plant([3, 4]);
|
21 |
|
|
*
|
22 |
|
|
* other.value();
|
23 |
|
|
* // => [9, 16]
|
24 |
|
|
*
|
25 |
|
|
* wrapped.value();
|
26 |
|
|
* // => [1, 4]
|
27 |
|
|
*/
|
28 |
|
|
function wrapperPlant(value) {
|
29 |
|
|
var result,
|
30 |
|
|
parent = this;
|
31 |
|
|
|
32 |
|
|
while (parent instanceof baseLodash) {
|
33 |
|
|
var clone = wrapperClone(parent);
|
34 |
|
|
clone.__index__ = 0;
|
35 |
|
|
clone.__values__ = undefined;
|
36 |
|
|
if (result) {
|
37 |
|
|
previous.__wrapped__ = clone;
|
38 |
|
|
} else {
|
39 |
|
|
result = clone;
|
40 |
|
|
}
|
41 |
|
|
var previous = clone;
|
42 |
|
|
parent = parent.__wrapped__;
|
43 |
|
|
}
|
44 |
|
|
previous.__wrapped__ = value;
|
45 |
|
|
return result;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
module.exports = wrapperPlant;
|