Hyperlinkv0.8.0-beta.28

Match

Match.Matchertypeeffect/Match.ts:57
Matcher<Input, Filters, RemainingApplied, Result, Provided, Return>

Union type for matchers created by Match.type and Match.value.

Details

A Matcher carries the input type, accumulated filters, remaining cases, result type, and, for value matchers, the provided value being matched.

Example (Matching string and number values)

import { Match } from "effect"

// Simulated dynamic input that can be a string or a number
const input: string | number = "some input"

//      ┌─── string
//      ▼
const result = Match.value(input).pipe(
  // Match if the value is a number
  Match.when(Match.number, (n) => `number: ${n}`),
  // Match if the value is a string
  Match.when(Match.string, (s) => `string: ${s}`),
  // Ensure all possible cases are covered
  Match.exhaustive
)

console.log(result)
// Output: "string: some input"
models
Source effect/Match.ts:573 lines
export type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any> =
  | TypeMatcher<Input, Filters, RemainingApplied, Result, Return>
  | ValueMatcher<Input, Filters, RemainingApplied, Result, Provided, Return>
Referenced by 20 symbols