Skip to main content

Function: toMultiple()

Returns a Reducer or OptionalReducer that reduces values to an object or array of the same shape as reducers using all of the reducers in reducers.

Returns an OptionalReducer if at least one of the input reducers is an OptionalReducer. Otherwise, returns a Reducer.

Example

console.log(
pipe(
[`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
map(string => string.length),
reduce(toMultiple([toSet(), toCount(), toJoin(`,`)])),
),
)
//=> [ Set(3) { 5, 10, 15 }, 5, '5,10,5,10,15' ]

console.log(
pipe(
[`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
map(string => string.length),
reduce(
toMultiple({
set: toSet(),
count: toCount(),
string: toJoin(`,`),
}),
),
),
)
//=> { set: Set(3) { 5, 10, 15 }, count: 5, string: '5,10,5,10,15' }

toMultiple(reducers)

toMultiple<Value, Reducers>(reducers): Reducer<Value, { -readonly [Key in string | number | symbol]: Reducers[Key] extends RawReducerWithoutFinish<Value, Acc> ? Acc : never }, { -readonly [Key in string | number | symbol]: Reducers[Key] extends RawReducerWithFinish<Value, any, Finished> ? Finished : Reducers[Key] extends RawReducerWithoutFinish<Value, Acc> ? Acc : never }>

Returns a Reducer or OptionalReducer that reduces values to an object or array of the same shape as reducers using all of the reducers in reducers.

Returns an OptionalReducer if at least one of the input reducers is an OptionalReducer. Otherwise, returns a Reducer.

Type Parameters

Value

Reducers extends readonly [RawReducerWithoutFinish<Value, any>] | readonly RawReducerWithoutFinish<Value, any>[] | Readonly<Record<string | number | symbol, RawReducerWithoutFinish<Value, any>>>

Parameters

reducers: Reducers

Returns

Reducer<Value, { -readonly [Key in string | number | symbol]: Reducers[Key] extends RawReducerWithoutFinish<Value, Acc> ? Acc : never }, { -readonly [Key in string | number | symbol]: Reducers[Key] extends RawReducerWithFinish<Value, any, Finished> ? Finished : Reducers[Key] extends RawReducerWithoutFinish<Value, Acc> ? Acc : never }>

Example

console.log(
pipe(
[`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
map(string => string.length),
reduce(toMultiple([toSet(), toCount(), toJoin(`,`)])),
),
)
//=> [ Set(3) { 5, 10, 15 }, 5, '5,10,5,10,15' ]

console.log(
pipe(
[`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
map(string => string.length),
reduce(
toMultiple({
set: toSet(),
count: toCount(),
string: toJoin(`,`),
}),
),
),
)
//=> { set: Set(3) { 5, 10, 15 }, count: 5, string: '5,10,5,10,15' }

Defined in

collections.d.ts:277

toMultiple(reducers)

toMultiple<Value, Reducers>(reducers): OptionalReducer<Value, { -readonly [Key in string | number | symbol]: Reducers[Key] extends RawReducerWithFinish<Value, any, Finished> ? Finished : Reducers[Key] extends RawOptionalReducerWithFinish<Value, Finished> ? Finished : Value }>

Returns a Reducer or OptionalReducer that reduces values to an object or array of the same shape as reducers using all of the reducers in reducers.

Returns an OptionalReducer if at least one of the input reducers is an OptionalReducer. Otherwise, returns a Reducer.

Type Parameters

Value

Reducers extends readonly [RawReducerWithoutFinish<Value, any> | RawOptionalReducerWithoutFinish<Value> | FunctionReducer<Value>] | readonly (RawReducerWithoutFinish<Value, any> | RawOptionalReducerWithoutFinish<Value> | FunctionReducer<Value>)[] | Readonly<Record<string | number | symbol, RawReducerWithoutFinish<Value, any> | RawOptionalReducerWithoutFinish<Value> | FunctionReducer<Value>>>

Parameters

reducers: Reducers

Returns

OptionalReducer<Value, { -readonly [Key in string | number | symbol]: Reducers[Key] extends RawReducerWithFinish<Value, any, Finished> ? Finished : Reducers[Key] extends RawOptionalReducerWithFinish<Value, Finished> ? Finished : Value }>

Example

console.log(
pipe(
[`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
map(string => string.length),
reduce(toMultiple([toSet(), toCount(), toJoin(`,`)])),
),
)
//=> [ Set(3) { 5, 10, 15 }, 5, '5,10,5,10,15' ]

console.log(
pipe(
[`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
map(string => string.length),
reduce(
toMultiple({
set: toSet(),
count: toCount(),
string: toJoin(`,`),
}),
),
),
)
//=> { set: Set(3) { 5, 10, 15 }, count: 5, string: '5,10,5,10,15' }

Defined in

collections.d.ts:308