Package: effect
Module: Option
Transforms the value inside a Some using the provided function, leaving
None unchanged.
When to use
Use to apply a pure transformation to an Option’s present value, especially
when chaining transformations in a pipeline.
Details
Some → applies f and wraps the result in a new SomeNone → returns None unchangedExample (Mapping over an Option)
import { Option } from "effect"
console.log(Option.map(Option.some(2), (n) => n * 2))
// Output: { _id: 'Option', _tag: 'Some', value: 4 }
console.log(Option.map(Option.none(), (n: number) => n * 2))
// Output: { _id: 'Option', _tag: 'None' }
See
flatMap when f returns an Optionas to replace the value with a constantSignature
declare const map: { <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>; <A, B>(self: Option<A>, f: (a: A) => B): Option<B>; }
Since v2.0.0