effect-io-ai

Package: effect
Module: Option

Option.tap

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

Example (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

Signature

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>; }

Source

Since v2.0.0