Hyperlinkv0.8.0-beta.28

Option

Option.zipWithconsteffect/Option.ts:1801
<B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (
  self: Option<A>
) => Option<C>
<A, B, C>(
  self: Option<A>,
  that: Option<B>,
  f: (a: A, b: B) => C
): Option<C>

Combines two Options using a provided function.

When to use

Use when you need to combine two present Option values into a computed result.

Details

  • Both Some → applies f(a, b) and wraps in Some
  • Either NoneNone

Example (Combining with a function)

import { Option } from "effect"

const person = Option.zipWith(
  Option.some("John"),
  Option.some(25),
  (name, age) => ({ name: name.toUpperCase(), age })
)

console.log(person)
// Output:
// { _id: 'Option', _tag: 'Some', value: { name: 'JOHN', age: 25 } }
Source effect/Option.ts:18018 lines
export const zipWith: {
  <B, A, C>(that: Option<B>, f: (a: A, b: B) => C): (self: Option<A>) => Option<C>
  <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C>
} = dual(
  3,
  <A, B, C>(self: Option<A>, that: Option<B>, f: (a: A, b: B) => C): Option<C> =>
    map(product(self, that), ([a, b]) => f(a, b))
)
Referenced by 1 symbols