Hyperlinkv0.8.0-beta.28

Boolean

Boolean.matchconsteffect/Boolean.ts:99
<A, B = A>(options: {
  readonly onFalse: LazyArg<A>
  readonly onTrue: LazyArg<B>
}): (value: boolean) => A | B
<A, B>(
  value: boolean,
  options: { readonly onFalse: LazyArg<A>; readonly onTrue: LazyArg<B> }
): A | B

Chooses between two lazy branches based on a boolean value.

When to use

Use to choose between two lazy branches based on a boolean value.

Example (Pattern matching on booleans)

import { Boolean } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(
  Boolean.match(true, {
    onFalse: () => "It's false!",
    onTrue: () => "It's true!"
  }),
  "It's true!"
)
pattern matching
Source effect/Boolean.ts:9913 lines
export const match: {
  <A, B = A>(options: {
    readonly onFalse: LazyArg<A>
    readonly onTrue: LazyArg<B>
  }): (value: boolean) => A | B
  <A, B>(value: boolean, options: {
    readonly onFalse: LazyArg<A>
    readonly onTrue: LazyArg<B>
  }): A | B
} = dual(2, <A, B>(value: boolean, options: {
  readonly onFalse: LazyArg<A>
  readonly onTrue: LazyArg<B>
}): A | B => value ? options.onTrue() : options.onFalse())