source: imaps-frontend/node_modules/lodash-es/plant.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1014 bytes
Line 
1import baseLodash from './_baseLodash.js';
2import wrapperClone from './_wrapperClone.js';
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 */
28function 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
48export default wrapperPlant;
Note: See TracBrowser for help on using the repository browser.