effect-io-ai

Package: effect
Module: Option

Option.lift2

Lifts a binary function to work with Option values, allowing the function to operate on two Options.

Details

This function takes a binary function f and returns a new function that applies f to the values of two Options (self and that). If both Options are Some, the binary function f is applied to their values, and the result is wrapped in a new Some. If either Option is None, the result is None.

Example

import { Option } from "effect"

// A binary function to add two numbers
const add = (a: number, b: number): number => a + b

// Lift the `add` function to work with `Option` values
const addOptions = Option.lift2(add)

// Both `Option`s are `Some`
console.log(addOptions(Option.some(2), Option.some(3)))
// Output: { _id: 'Option', _tag: 'Some', value: 5 }

// One `Option` is `None`
console.log(addOptions(Option.some(2), Option.none()))
// Output: { _id: 'Option', _tag: 'None' }

Signature

declare const lift2: <A, B, C>(f: (a: A, b: B) => C) => { (that: Option<B>): (self: Option<A>) => Option<C>; (self: Option<A>, that: Option<B>): Option<C>; }

Source

Since v2.0.0