Package: effect
Module: Option
Adds a computed plain value to the do notation record.
When to use
Use when you need to bind a derived non-Option value in an Option do
notation pipeline.
Example (Adding a computed value)
import { Option, pipe } from "effect"
import * as assert from "node:assert"
const result = pipe(
Option.Do,
Option.bind("x", () => Option.some(2)),
Option.bind("y", () => Option.some(3)),
Option.let("sum", ({ x, y }) => x + y)
)
assert.deepStrictEqual(result, Option.some({ x: 2, y: 3, sum: 5 }))
See
Do for starting the chainbind to add Option valuesbindTo to start by naming an existing OptionSignature
declare const let: { <N extends string, A extends object, B>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => B): (self: Option<A>) => Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; <A extends object, N extends string, B>(self: Option<A>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => B): Option<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; }
Since v2.0.0