Hyperlinkv0.8.0-beta.28

Option

Option.productconsteffect/Option.ts:1634
<A, B>(self: Option<A>, that: Option<B>): Option<[A, B]>

Combines two Options into a Some containing a tuple [A, B] if both are Some.

When to use

Use when you need to require two Option values to both be Some and keep both values as a tuple.

Details

  • Both SomeSome([a, b])
  • Either NoneNone

Example (Pairing two Options)

import { Option } from "effect"

console.log(Option.product(Option.some("hello"), Option.some(42)))
// Output: { _id: 'Option', _tag: 'Some', value: ['hello', 42] }

console.log(Option.product(Option.none(), Option.some(42)))
// Output: { _id: 'Option', _tag: 'None' }
combiningzipWithall
Source effect/Option.ts:16342 lines
export const product = <A, B>(self: Option<A>, that: Option<B>): Option<[A, B]> =>
  isSome(self) && isSome(that) ? some([self.value, that.value]) : none()
Referenced by 1 symbols