Function: toGrouped()
Returns a Reducer that reduces key-value pairs using outerReducer
and reduces values with the same key using innerReducer
.
Example
console.log(
pipe(
[`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
map(string => [string.length, string]),
reduce(toGrouped(toArray(), toMap())),
),
)
//=> Map(3) {
//=> 5 => [ 'sloth', 'sleep' ],
//=> 10 => [ 'some sloth', 'more sloth' ],
//=> 15 => [ 'even more sloth' ]
//=> }
toGrouped(innerReducer, outerReducer)
toGrouped<
Key
,Value
,InnerAcc
,InnerFinished
,InnerThis
,OuterAcc
,OuterThis
>(innerReducer
,outerReducer
):Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Returns a Reducer that reduces key-value pairs using outerReducer
and reduces values with the same key using innerReducer
.
Type Parameters
• Key
• Value
• InnerAcc
• InnerFinished
• InnerThis
• OuterAcc
• OuterThis
Parameters
• innerReducer: Readonly
<RawReducerWithFinish
<Value
, InnerAcc
, InnerFinished
, InnerThis
>>
• outerReducer: Readonly
<RawKeyedReducer
<Key
, InnerAcc
| InnerFinished
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Example
console.log(
pipe(
[`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
map(string => [string.length, string]),
reduce(toGrouped(toArray(), toMap())),
),
)
//=> Map(3) {
//=> 5 => [ 'sloth', 'sleep' ],
//=> 10 => [ 'some sloth', 'more sloth' ],
//=> 15 => [ 'even more sloth' ]
//=> }
Defined in
toGrouped(innerReducer)
toGrouped<
Value
,InnerAcc
,InnerFinished
,InnerThis
>(innerReducer
): <Key
,OuterAcc
,OuterThis
>(outerReducer
) =>Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Returns a Reducer that reduces key-value pairs using outerReducer
and reduces values with the same key using innerReducer
.
Type Parameters
• Value
• InnerAcc
• InnerFinished
• InnerThis