Package: effect
Module: Option
Applies a function that returns an Option to the value of a Some,
flattening the result. Returns None if the input is None.
When to use
Use when you need to chain dependent Option computations where each step
may return None.
Details
Some → applies f to the value and returns its Option resultNone → returns None without calling fmap followed by flattenExample (Chaining optional lookups)
import { Option } from "effect"
interface User {
readonly name: string
readonly address: Option.Option<{ readonly street: Option.Option<string> }>
}
const user: User = {
name: "John",
address: Option.some({ street: Option.some("123 Main St") })
}
const street = user.address.pipe(
Option.flatMap((addr) => addr.street)
)
console.log(street)
// Output: { _id: 'Option', _tag: 'Some', value: '123 Main St' }
See
map when f returns a plain valueandThen for a more flexible variantflatten to unwrap a nested Option<Option<A>>Signature
declare const flatMap: { <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>; <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>; }
Since v2.0.0