Hyperlinkv0.8.0-beta.28

Match

Match.stringconsteffect/Match.ts:1281
(a: unknown): a is string

Matches values of type string.

Details

This predicate refines unknown values to strings, allowing pattern matching on string types. It's commonly used in type-based matchers to handle string cases.

Example (Matching string values)

import { Match } from "effect"

const processValue = Match.type<string | number | boolean>().pipe(
  Match.when(Match.string, (str) => `String: ${str.toUpperCase()}`),
  Match.when(Match.number, (num) => `Number: ${num * 2}`),
  Match.when(Match.boolean, (bool) => `Boolean: ${bool ? "yes" : "no"}`),
  Match.exhaustive
)

console.log(processValue("hello")) // "String: HELLO"
console.log(processValue(42)) // "Number: 84"
console.log(processValue(true)) // "Boolean: yes"
predicates
Source effect/Match.ts:12811 lines
export const string: Predicate.Refinement<unknown, string> = Predicate.isString