Function: combine()

Combines multiple Result or ResultAsync values into a single result. If all inputs are Success, returns a Success with combined values. If any input is a Failure, returns a Failure with an array of all errors.

Type Param

The input type (object or array of Results).

Examples

import { Result } from '@praha/byethrow';

const result = Result.combine({
  a: Result.succeed(1),
  b: Result.succeed('hello'),
});
// { type: 'Success', value: { a: 1, b: 'hello' } }
import { Result } from '@praha/byethrow';

const result = Result.combine([
  Result.succeed(1),
  Result.succeed(2),
  Result.succeed(3),
]);
// { type: 'Success', value: [1, 2, 3] }
import { Result } from '@praha/byethrow';

const result = Result.combine([
  Result.succeed(1),
  Result.fail('error1'),
  Result.fail('error2'),
]);
// { type: 'Failure', error: ['error1', 'error2'] }

Call Signature

combine<X>(x): ResultFor<X[keyof X], { [K in string | number | symbol]: InferSuccess<X[K]> }, InferFailure<X[keyof X]>[]>

Defined in: functions/combine.ts:63

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

combine<X>(x): ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K<K>]> }, InferFailure<X[number]>[]>

Defined in: functions/combine.ts:64

Type Parameters

X

X extends ResultMaybeAsync<any, any>[]

Parameters

x

X

Returns

ResultFor<X[number], { [K in string | number | symbol]: InferSuccess<X[K<K>]> }, InferFailure<X[number]>[]>