Skip to main content

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

collections.d.ts:172

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

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>

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

collections.d.ts:180

toGrouped(innerReducer, outerReducer)

toGrouped<Key, Value, InnerAcc, 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

InnerThis

OuterAcc

OuterThis

Parameters

innerReducer: Readonly<RawReducerWithoutFinish<Value, InnerAcc, InnerThis>>

outerReducer: Readonly<RawKeyedReducer<Key, InnerAcc, 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

collections.d.ts:190

toGrouped(innerReducer)

toGrouped<Value, InnerAcc, 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

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>

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

collections.d.ts:194

toGrouped(innerReducer, outerReducer)

toGrouped<Key, Value, 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

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>

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

collections.d.ts:200

toGrouped(innerReducer)

toGrouped<Value, 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

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>

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

collections.d.ts:208

toGrouped(innerReducer, outerReducer)

toGrouped<Key, Value, 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

InnerThis

OuterAcc

OuterThis

Parameters

innerReducer: Readonly<RawOptionalReducerWithoutFinish<Value, InnerThis>>

outerReducer: Readonly<RawKeyedReducer<Key, Value, 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

collections.d.ts:218

toGrouped(innerReducer)

toGrouped<Value, 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

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>

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

collections.d.ts:222

toGrouped(innerReducer, outerReducer)

toGrouped<Key, Value, 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

OuterAcc

OuterThis

Parameters

innerReducer: FunctionReducer<Value>

outerReducer: Readonly<RawKeyedReducer<Key, Value, 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

collections.d.ts:228

toGrouped(innerReducer)

toGrouped<Value>(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

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>

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

collections.d.ts:232