Hyperlinkv0.8.0-beta.28

Option

Option.makeCombinerFailFastfunctioneffect/Option.ts:2612
<A>(combiner: Combiner.Combiner<A>): Combiner.Combiner<Option<A>>

Creates a Combiner for Option<A> with fail-fast semantics: returns None if either operand is None.

When to use

Use when you need an Option combiner that returns None unless both operands are Some.

Details

  • None + anything → None
  • anything + NoneNone
  • Some(a) + Some(b)Some(combine(a, b))

Example (Fail-fast combining)

import { Number, Option } from "effect"

const combiner = Option.makeCombinerFailFast(Number.ReducerSum)
console.log(combiner.combine(Option.some(1), Option.some(2)))
// Output: { _id: 'Option', _tag: 'Some', value: 3 }

console.log(combiner.combine(Option.some(1), Option.none()))
// Output: { _id: 'Option', _tag: 'None' }
Source effect/Option.ts:26126 lines
export function makeCombinerFailFast<A>(combiner: Combiner.Combiner<A>): Combiner.Combiner<Option<A>> {
  return Combiner.make((self, that) => {
    if (isNone(self) || isNone(that)) return none()
    return some(combiner.combine(self.value, that.value))
  })
}
Referenced by 1 symbols