Hyperlinkv0.8.0-beta.28

Option

Option.zipRightconsteffect/Option.ts:1476
<B>(that: Option<B>): <_>(self: Option<_>) => Option<B>
<X, B>(self: Option<X>, that: Option<B>): Option<B>

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

When to use

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

Details

  • Both Some → returns that
  • Either None → returns None

Example (Keeping the second value)

import { Option } from "effect"

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

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