1 | var _clone =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_clone");
|
4 |
|
5 | var _curry3 =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_curry3");
|
8 |
|
9 | var _isTransformer =
|
10 | /*#__PURE__*/
|
11 | require("./internal/_isTransformer");
|
12 |
|
13 | var _reduce =
|
14 | /*#__PURE__*/
|
15 | require("./internal/_reduce");
|
16 |
|
17 | var _stepCat =
|
18 | /*#__PURE__*/
|
19 | require("./internal/_stepCat");
|
20 | /**
|
21 | * Transforms the items of the list with the transducer and appends the
|
22 | * transformed items to the accumulator using an appropriate iterator function
|
23 | * based on the accumulator type.
|
24 | *
|
25 | * The accumulator can be an array, string, object or a transformer. Iterated
|
26 | * items will be appended to arrays and concatenated to strings. Objects will
|
27 | * be merged directly or 2-item arrays will be merged as key, value pairs.
|
28 | *
|
29 | * The accumulator can also be a transformer object that provides a 2-arity
|
30 | * reducing iterator function, step, 0-arity initial value function, init, and
|
31 | * 1-arity result extraction function result. The step function is used as the
|
32 | * iterator function in reduce. The result function is used to convert the
|
33 | * final accumulator into the return type and in most cases is R.identity. The
|
34 | * init function is used to provide the initial accumulator.
|
35 | *
|
36 | * The iteration is performed with [`R.reduce`](#reduce) after initializing the
|
37 | * transducer.
|
38 | *
|
39 | * @func
|
40 | * @memberOf R
|
41 | * @since v0.12.0
|
42 | * @category List
|
43 | * @sig a -> (b -> b) -> [c] -> a
|
44 | * @param {*} acc The initial accumulator value.
|
45 | * @param {Function} xf The transducer function. Receives a transformer and returns a transformer.
|
46 | * @param {Array} list The list to iterate over.
|
47 | * @return {*} The final, accumulated value.
|
48 | * @see R.transduce
|
49 | * @example
|
50 | *
|
51 | * const numbers = [1, 2, 3, 4];
|
52 | * const transducer = R.compose(R.map(R.add(1)), R.take(2));
|
53 | *
|
54 | * R.into([], transducer, numbers); //=> [2, 3]
|
55 | *
|
56 | * const intoArray = R.into([]);
|
57 | * intoArray(transducer, numbers); //=> [2, 3]
|
58 | */
|
59 |
|
60 |
|
61 | var into =
|
62 | /*#__PURE__*/
|
63 | _curry3(function into(acc, xf, list) {
|
64 | return _isTransformer(acc) ? _reduce(xf(acc), acc['@@transducer/init'](), list) : _reduce(xf(_stepCat(acc)), _clone(acc, [], [], false), list);
|
65 | });
|
66 |
|
67 | module.exports = into; |
\ | No newline at end of file |