Hyperlinkv0.8.0-beta.28

Option

Option.zipLeftconsteffect/Option.ts:1512
<_>(that: Option<_>): <A>(self: Option<A>) => Option<A>
<A, X>(self: Option<A>, that: Option<X>): Option<A>

Sequences two Options, keeping the value from the first if both are Some.

When to use

Use when you need two Option values to both be Some, then keep only the first value.

Details

  • Both Some → returns self
  • Either None → returns None

Example (Keeping the first value)

import { Option } from "effect"

console.log(Option.zipLeft(Option.some("hello"), Option.some(1)))
// Output: { _id: 'Option', _tag: 'Some', value: 'hello' }

console.log(Option.zipLeft(Option.some("hello"), Option.none()))
// Output: { _id: 'Option', _tag: 'None' }
Source effect/Option.ts:15124 lines
export const zipLeft: {
  <_>(that: Option<_>): <A>(self: Option<A>) => Option<A>
  <A, X>(self: Option<A>, that: Option<X>): Option<A>
} = dual(2, <A, X>(self: Option<A>, that: Option<X>): Option<A> => tap(self, () => that))