Package: effect
Module: Match
Represents a positive pattern matching case.
Details
A When case contains the logic to test if a value matches a specific pattern
and the function to evaluate when the pattern matches. It’s the primary
building block for pattern matching conditions.
Example (Creating positive match cases)
import { Match } from "effect"
// When creates cases that match specific patterns
const stringMatcher = Match.type<string | number>().pipe(
Match.when(Match.string, (s: string) => `Got string: ${s}`),
Match.when(Match.number, (n: number) => `Got number: ${n}`),
Match.exhaustive
)
console.log(stringMatcher("hello")) // "Got string: hello"
console.log(stringMatcher(42)) // "Got number: 42"
Signature
export interface When {
readonly _tag: "When"
guard(u: unknown): boolean
evaluate(input: unknown): any
}
Since v4.0.0