Package: effect
Module: Option
Provides generator-based syntax for Option, similar to async/await but for
optional values. Yielding a None short-circuits the generator to None.
When to use
Use when you need generator syntax for a sequence of Option steps that
should short-circuit on None.
Details
yield* unwraps a Some value or short-circuits to NoneSomeEffect runtime is neededExample (Sequencing Option computations with generator syntax)
import { Option } from "effect"
const maybeName: Option.Option<string> = Option.some("John")
const maybeAge: Option.Option<number> = Option.some(25)
const person = Option.gen(function*() {
const name = (yield* maybeName).toUpperCase()
const age = yield* maybeAge
return { name, age }
})
console.log(person)
// Output:
// { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }
See
Do / bind for the do notation alternativeSignature
declare const gen: Gen.Gen<OptionTypeLambda>
Since v2.0.0