WhenRepresents 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"models
Source effect/Match.ts:1975 lines
export interface When {
readonly When._tag: "When"_tag: "When"
When.guard(u: unknown): booleanguard(u: unknownu: unknown): boolean
When.evaluate(input: unknown): anyevaluate(input: unknowninput: unknown): any
}Referenced by 1 symbols