Package: effect
Module: Either
Takes a structure of Eithers and returns an Either of values with the same structure.
Either will contain a tuple with the same length.Either will contain a struct with the same keys.Either will contain an array.Example
import * as assert from "node:assert"
import { Either } from "effect"
assert.deepStrictEqual(Either.all([Either.right(1), Either.right(2)]), Either.right([1, 2]))
assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.right("hello") }), Either.right({ right: 1, b: "hello" }))
assert.deepStrictEqual(Either.all({ right: Either.right(1), b: Either.left("error") }), Either.left("error"))
Signature
declare const all: <const I extends Iterable<Either<any, any>> | Record<string, Either<any, any>>>(input: I) => [I] extends [ReadonlyArray<Either<any, any>>] ? Either<{ -readonly [K in keyof I]: [I[K]] extends [Either<infer A, any>] ? A : never; }, I[number] extends never ? never : [I[number]] extends [Either<any, infer E>] ? E : never> : [I] extends [Iterable<Either<infer A, infer E>>] ? Either<Array<A>, E> : Either<{ -readonly [K in keyof I]: [I[K]] extends [Either<infer A, any>] ? A : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Either<any, infer E>] ? E : never>
Since v2.0.0