effect-io-ai

Package: effect
Module: Either

Either.all

Takes a structure of Eithers and returns an Either of values with the same structure.

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>

Source

Since v2.0.0