Skip to content

into

Summary

Transform a list into another list.

Tip

This function is curried.

Description

Reduces a list into another list (not necessarily of the same type) by applying a serie of transformations (transducer) to each value of the list in a single iteration. The transducer is defined by composing list functions together. Be aware that due to the nature of transducers the order of execution will be left to right.

Examples

Map over the elements and accumulate into a string:

1
2
into('', map(inc), [10, 20, 30]);
//=> '112131'

Map over the properties and accumulate into an array:

1
2
into([], map(inc), {a: 10, b: 20, c: 30});
//=> [11, 21, 31]

Transducer example: take only the first two elements, increment them and accumulate into a string:

1
2
into('', compose(take(2), map(inc)), [10, 20, 30]);
//=> '1121'

Parameters

Name Type Description
init Array, Object or string
transducer function
xs Array or Object

Return

Array, Object or string