Function: toGrouped()
Returns a Reducer that reduces key-value pairs using outerReducer
and reduces values with the same key using innerReducer
.
Example
import { map, pipe, reduce, toArray, toGrouped, toMap } from 'lfi'
console.log(
pipe(
[`sloth`, `lazy`, `sleep`],
map(word => [word.length, word]),
reduce(toGrouped(toArray(), toMap())),
),
)
//=> Map(2) {
//=> 5 => [ 'sloth', 'sleep' ],
//=> 4 => [ 'lazy' ]
//=> }
Since
v2.0.0
Call Signature
toGrouped<
Key
,Value
,InnerAcc
,InnerFinished
,InnerThis
,OuterAcc
,OuterThis
>(innerReducer
,outerReducer
):Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
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
>
Defined in
Call Signature
toGrouped<
Value
,InnerAcc
,InnerFinished
,InnerThis
>(innerReducer
): <Key
,OuterAcc
,OuterThis
>(outerReducer
) =>Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Value
• InnerAcc
• InnerFinished
• InnerThis
Parameters
innerReducer
Readonly
<RawReducerWithFinish
<Value
, InnerAcc
, InnerFinished
, InnerThis
>>
Returns
Function
Type Parameters
• Key
• OuterAcc
• OuterThis
Parameters
outerReducer
Readonly
<RawKeyedReducer
<Key
, InnerAcc
| InnerFinished
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Defined in
Call Signature
toGrouped<
Key
,Value
,InnerAcc
,InnerThis
,OuterAcc
,OuterThis
>(innerReducer
,outerReducer
):Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Key
• Value
• InnerAcc
• InnerThis
• OuterAcc
• OuterThis
Parameters
innerReducer
Readonly
<RawReducerWithoutFinish
<Value
, InnerAcc
, InnerThis
>>
outerReducer
Readonly
<RawKeyedReducer
<Key
, InnerAcc
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Defined in
Call Signature
toGrouped<
Value
,InnerAcc
,InnerThis
>(innerReducer
): <Key
,OuterAcc
,OuterThis
>(outerReducer
) =>Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Value
• InnerAcc
• InnerThis
Parameters
innerReducer
Readonly
<RawReducerWithoutFinish
<Value
, InnerAcc
, InnerThis
>>
Returns
Function
Type Parameters
• Key
• OuterAcc
• OuterThis
Parameters
outerReducer
Readonly
<RawKeyedReducer
<Key
, InnerAcc
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Defined in
Call Signature
toGrouped<
Key
,Value
,InnerFinished
,InnerThis
,OuterAcc
,OuterThis
>(innerReducer
,outerReducer
):Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Key
• Value
• InnerFinished
• InnerThis
• OuterAcc
• OuterThis
Parameters
innerReducer
Readonly
<RawOptionalReducerWithFinish
<Value
, InnerFinished
, InnerThis
>>
outerReducer
Readonly
<RawKeyedReducer
<Key
, Value
| InnerFinished
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Defined in
Call Signature
toGrouped<
Value
,InnerFinished
,InnerThis
>(innerReducer
): <Key
,OuterAcc
,OuterThis
>(outerReducer
) =>Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Value
• InnerFinished
• InnerThis
Parameters
innerReducer
Readonly
<RawOptionalReducerWithFinish
<Value
, InnerFinished
, InnerThis
>>
Returns
Function
Type Parameters
• Key
• OuterAcc
• OuterThis
Parameters
outerReducer
Readonly
<RawKeyedReducer
<Key
, Value
| InnerFinished
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Defined in
Call Signature
toGrouped<
Key
,Value
,InnerThis
,OuterAcc
,OuterThis
>(innerReducer
,outerReducer
):Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Key
• Value
• InnerThis
• OuterAcc
• OuterThis
Parameters
innerReducer
Readonly
<RawOptionalReducerWithoutFinish
<Value
, InnerThis
>>
outerReducer
Readonly
<RawKeyedReducer
<Key
, Value
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Defined in
Call Signature
toGrouped<
Value
,InnerThis
>(innerReducer
): <Key
,OuterAcc
,OuterThis
>(outerReducer
) =>Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Value
• InnerThis
Parameters
innerReducer
Readonly
<RawOptionalReducerWithoutFinish
<Value
, InnerThis
>>
Returns
Function
Type Parameters
• Key
• OuterAcc
• OuterThis
Parameters
outerReducer
Readonly
<RawKeyedReducer
<Key
, Value
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Defined in
Call Signature
toGrouped<
Key
,Value
,OuterAcc
,OuterThis
>(innerReducer
,outerReducer
):Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Key
• Value
• OuterAcc
• OuterThis
Parameters
innerReducer
FunctionReducer
<Value
>
outerReducer
Readonly
<RawKeyedReducer
<Key
, Value
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>
Defined in
Call Signature
toGrouped<
Value
>(innerReducer
): <Key
,OuterAcc
,OuterThis
>(outerReducer
) =>Reducer
<readonly [Key
,Value
],never
,OuterAcc
>
Type Parameters
• Value
Parameters
innerReducer
FunctionReducer
<Value
>
Returns
Function
Type Parameters
• Key
• OuterAcc
• OuterThis
Parameters
outerReducer
Readonly
<RawKeyedReducer
<Key
, Value
, OuterAcc
, OuterThis
>>
Returns
Reducer
<readonly [Key
, Value
], never
, OuterAcc
>