Hyperlinkv0.8.0-beta.28

Match

<
  Literals extends ReadonlyArray<
    string | number | bigint | boolean | null
  >
>(
  ...literals: Literals
): SafeRefinement<Literals[number]>

Matches a specific set of literal values (e.g., Match.is("a", 42, true)).

When to use

Use to match one of several literal primitive or null values.

Details

This function creates a predicate that matches any of the provided literal values. It's useful for matching against multiple specific values in a single pattern.

Example (Matching literal values)

import { Match } from "effect"

const handleStatus = Match.type<string | number>()
  .pipe(
    Match.when(Match.is("success", "ok", 200), () => "Operation successful"),
    Match.when(Match.is("error", "failed", 500), () => "Operation failed"),
    Match.when(Match.is(0, false, null), () => "Falsy value"),
    Match.orElse((value) => `Unknown status: ${value}`)
  )

console.log(handleStatus("success"))
// Output: "Operation successful"

console.log(handleStatus(200))
// Output: "Operation successful"

console.log(handleStatus("failed"))
// Output: "Operation failed"

console.log(handleStatus(0))
// Output: "Falsy value"

console.log(handleStatus("pending"))
// Output: "Unknown status: pending"
predicates
Source effect/Match.ts:12493 lines
export const is: <
  Literals extends ReadonlyArray<string | number | bigint | boolean | null>
>(...literals: Literals) => SafeRefinement<Literals[number]> = internal.is