Function: collect()
Processes multiple Result or ResultAsync values into a single result. If all results are Success, returns a Success containing all values. If any result is a Failure, returns a Failure containing an array of all errors.
Unlike sequence, which stops at the first error and returns only that error,
collect processes all results and collects all errors.
Type Param
X
The input type (object or array of Results).
Examples
Object of Results (all succeed)
Object of Results (some fail)
Array of Results (all succeed)
Array of Results (some fail)
Using a mapper function (all succeed)
Using a mapper function (some fail)
Call Signature
collect<
X>(x):ResultFor<X[keyofX], { [K in string | number | symbol]: InferSuccess<X[K]> },InferFailure<X[keyofX]>[]>
Type Parameters
X
X extends Record<string, ResultMaybeAsync<any, any>>
Parameters
x
X
Returns
ResultFor<X[keyof X], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[keyof X]>[]>
Call Signature
collect<
X>(x):ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K]> },InferFailure<X[number]>[]>
Type Parameters
X
X extends ResultMaybeAsync<any, any>[]
Parameters
x
X
Returns
ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[number]>[]>
Call Signature
collect<
X>(x):ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K]> },InferFailure<X[number]>[]>
Type Parameters
X
X extends readonly ResultMaybeAsync<any, any>[]
Parameters
x
X
Returns
ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[number]>[]>
Call Signature
collect<
X,Fn>(x,fn):ResultFor<ReturnType<Fn>, { [K in string | number | symbol]: InferSuccess<Fn> },InferFailure<Fn>[]>
Type Parameters
X
X extends unknown[]
Fn
Fn extends (value) => ResultMaybeAsync<any, any>
Parameters
x
X
fn
Fn
Returns
ResultFor<ReturnType<Fn>, { [K in string | number | symbol]: InferSuccess<Fn> }, InferFailure<Fn>[]>
Call Signature
collect<
X,Fn>(x,fn):ResultFor<ReturnType<Fn>, { [K in string | number | symbol]: InferSuccess<Fn> },InferFailure<Fn>[]>
Type Parameters
X
X extends readonly unknown[]
Fn
Fn extends (value) => ResultMaybeAsync<any, any>
Parameters
x
X
fn
Fn
Returns
ResultFor<ReturnType<Fn>, { [K in string | number | symbol]: InferSuccess<Fn> }, InferFailure<Fn>[]>
