Hyperlinkv0.8.0-beta.28

Match

Match.anyconsteffect/Match.ts:1375
SafeRefinement<unknown, any>

Matches any value without restrictions.

When to use

Use to define an explicit catch-all pattern when the handler should receive the unmatched value.

Details

This predicate matches every input, including undefined, null, objects, primitives, and functions.

Gotchas

Match.any should usually be last because cases are checked in order and the first matching case wins.

Example (Matching any remaining value)

import { Match } from "effect"

const describeValue = Match.type<unknown>()
  .pipe(
    Match.when(Match.string, (str) => `String: ${str}`),
    Match.when(Match.number, (num) => `Number: ${num}`),
    Match.when(Match.boolean, (bool) => `Boolean: ${bool}`),
    Match.when(Match.any, (value) => `Other: ${typeof value}`),
    Match.exhaustive
  )

console.log(describeValue("hello"))
// Output: "String: hello"

console.log(describeValue(42))
// Output: "Number: 42"

console.log(describeValue([1, 2, 3]))
// Output: "Other: object"

console.log(describeValue(null))
// Output: "Other: object"
predicatesdefinedorElse
Source effect/Match.ts:13751 lines
export const any: SafeRefinement<unknown, any> = internal.any