Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var baseLodash = require('../internal/baseLodash'),
2
wrapperClone = require('../internal/wrapperClone');
3
4
/**
5
* Creates a clone of the chained sequence planting `value` as the wrapped value.
6
*
7
* @name plant
8
* @memberOf _
9
* @category Chain
10
* @returns {Object} Returns the new `lodash` wrapper instance.
11
* @example
12
*
13
* var array = [1, 2];
14
* var wrapper = _(array).map(function(value) {
15
* return Math.pow(value, 2);
16
* });
17
*
18
* var other = [3, 4];
19
* var otherWrapper = wrapper.plant(other);
20
*
21
* otherWrapper.value();
22
* // => [9, 16]
23
*
24
* wrapper.value();
25
* // => [1, 4]
26
*/
27
function wrapperPlant(value) {
28
var result,
29
parent = this;
30
31
while (parent instanceof baseLodash) {
32
var clone = wrapperClone(parent);
33
if (result) {
34
previous.__wrapped__ = clone;
35
} else {
36
result = clone;
37
}
38
var previous = clone;
39
parent = parent.__wrapped__;
40
}
41
previous.__wrapped__ = value;
42
return result;
43
}
44
45
module.exports = wrapperPlant;
46
47