Package: effect
Module: Option
Transforms and filters an Option using a Filter callback.
When to use
Use to transform an Option’s present value and discard it when the Filter
fails.
Details
The callback returns a Result: Result.succeed keeps and transforms the
value, while Result.fail discards it.
Example (Filtering and transforming)
import { Option, Result } from "effect"
console.log(Option.filterMap(
Option.some(2),
(n) => (n % 2 === 0 ? Result.succeed(`Even: ${n}`) : Result.failVoid)
))
// Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }
See
filter for predicate-based filteringSignature
declare const filterMap: { <A, B, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>; <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>; }
Since v2.0.0