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