Package: effect
Module: Option
Runs a side-effecting Option-returning function on the value of a Some,
returning the original Option if the function returns Some, or None
if it returns None.
When to use
Use to validate an Option’s present value without transforming it, such as
adding a side-condition check in a pipeline.
Details
None → NoneSome → calls f(value); if result is Some, returns original self; if None, returns NoneExample (Validating without transforming)
import { Option } from "effect"
const getInteger = (n: number) =>
Number.isInteger(n) ? Option.some(n) : Option.none()
console.log(Option.tap(Option.some(1), getInteger))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
console.log(Option.tap(Option.some(1.14), getInteger))
// Output: { _id: 'Option', _tag: 'None' }
See
flatMap when you want to transform the valuefilter for predicate-based filteringSignature
declare const tap: { <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>; <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>; }
Since v2.0.0