Hyperlinkv0.8.0-beta.28

Match

Match.booleanconsteffect/Match.ts:1465
(a: unknown): a is boolean

Matches values of type boolean.

When to use

Use to match primitive boolean values.

Details

This predicate refines unknown values to booleans, allowing pattern matching on boolean types. It only matches the primitive boolean values true and false.

Example (Matching boolean values)

import { Match } from "effect"

const describeTruthiness = Match.type<unknown>().pipe(
  Match.when(
    Match.boolean,
    (bool) => bool ? "Definitely true" : "Definitely false"
  ),
  Match.when(0, () => "Falsy number"),
  Match.when("", () => "Empty string"),
  Match.when(Match.null, () => "Null value"),
  Match.orElse(() => "Some other truthy value")
)

console.log(describeTruthiness(true)) // "Definitely true"
console.log(describeTruthiness(false)) // "Definitely false"
console.log(describeTruthiness(0)) // "Falsy number"
console.log(describeTruthiness(1)) // "Some other truthy value"
predicatesis
Source effect/Match.ts:14651 lines
export const boolean: Predicate.Refinement<unknown, boolean> = Predicate.isBoolean