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

import { map, pipe, reduce, toCount, toJoin, toMultiple, toSet } from 'lfi'

console.log(
pipe(
[`sloth`, `lazy`, `sleep`],
map(word => word.length),
reduce(toMultiple([toSet(), toCount(), toJoin(`,`)])),
),
)
//=> [
//=> Set(2) { 5, 4 },
//=> 3,
//=> '5,4,5'
//=> ]

console.log(
pipe(
[`sloth`, `lazy`, `sleep`],
map(word => word.length),
reduce(
toMultiple({
set: toSet(),
count: toCount(),
string: toJoin(`,`),
}),
),
),
)
//=> {
//=> set: Set(2) { 5, 4 },
//=> count: 3,
//=> string: '5,4,5'
//=> }
Playground

Since

v2.0.0

Call Signature

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 }>

Type Parameters

Value

Reducers extends readonly [RawReducerWithoutFinish<Value, any>] | readonly RawReducerWithoutFinish<Value, any>[] | Readonly<Record<PropertyKey, 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 }>

Defined in

collections.d.ts:320

Call Signature

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 }>

Type Parameters

Value

Reducers extends readonly [RawReducerWithoutFinish<Value, any> | RawOptionalReducerWithoutFinish<Value> | FunctionReducer<Value>] | readonly (RawReducerWithoutFinish<Value, any> | RawOptionalReducerWithoutFinish<Value> | FunctionReducer<Value>)[] | Readonly<Record<PropertyKey, 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 }>

Defined in

collections.d.ts:351