source: node_modules/ramda/es/into.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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