Package: effect
Module: Option
Combines a structure of Options (tuple, struct, or iterable) into a single
Option containing the unwrapped structure.
When to use
Use when you need to combine multiple Option values into one while
preserving the input shape, with any None making the result None.
Details
Option of a tuple with the same lengthOption of a struct with the same keysOption of an ArrayNone in the input → entire result is NoneExample (Combining a tuple and a struct)
import { Option } from "effect"
const maybeName: Option.Option<string> = Option.some("John")
const maybeAge: Option.Option<number> = Option.some(25)
// ┌─── Option<[string, number]>
// ▼
const tuple = Option.all([maybeName, maybeAge])
console.log(tuple)
// Output:
// { _id: 'Option', _tag: 'Some', value: [ 'John', 25 ] }
// ┌─── Option<{ name: string; age: number; }>
// ▼
const struct = Option.all({ name: maybeName, age: maybeAge })
console.log(struct)
// Output:
// { _id: 'Option', _tag: 'Some', value: { name: 'John', age: 25 } }
See
product for combining exactly twoproductMany for a homogeneous collectionSignature
declare const all: <const I extends Iterable<Option<any>> | Record<string, Option<any>>>(input: I) => [I] extends [ReadonlyArray<Option<any>>] ? Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never; }> : [I] extends [Iterable<Option<infer A>>] ? Option<Array<A>> : Option<{ -readonly [K in keyof I]: [I[K]] extends [Option<infer A>] ? A : never; }>
Since v2.0.0