Hyperlinkv0.8.0-beta.28

Match

Match.symbolconsteffect/Match.ts:1590
(a: unknown): a is symbol

Matches values of type symbol.

Details

This predicate refines unknown values to symbols, allowing pattern matching on symbol types. Symbols are unique identifiers that are often used as object keys or for creating private properties.

Example (Matching symbol values)

import { Match } from "effect"

const mySymbol = Symbol("my-symbol")
const globalSymbol = Symbol.for("global-symbol")

const handleSymbol = Match.type<unknown>().pipe(
  Match.when(Match.symbol, (sym) => {
    const description = sym.description
    if (description) {
      return `Symbol with description: ${description}`
    }
    return "Symbol without description"
  }),
  Match.orElse(() => "Not a symbol")
)

console.log(handleSymbol(mySymbol)) // "Symbol with description: my-symbol"
console.log(handleSymbol(Symbol())) // "Symbol without description"
console.log(handleSymbol("string")) // "Not a symbol"
predicates
Source effect/Match.ts:15901 lines
export const symbol: Predicate.Refinement<unknown, symbol> = Predicate.isSymbol