Hyperlinkv0.8.0-beta.28

Match

Match.bigintconsteffect/Match.ts:1552
(a: unknown): a is bigint

Matches values of type bigint.

When to use

Use to match primitive bigint values.

Details

This predicate refines unknown values to bigints, allowing pattern matching on bigint types. BigInts are used for representing integers with arbitrary precision.

Example (Matching bigint values)

import { Match } from "effect"

const processLargeNumber = Match.type<unknown>().pipe(
  Match.when(Match.bigint, (big) => {
    if (big > 9007199254740991n) {
      return `Large integer: ${big.toString()}`
    }
    return `BigInt: ${big.toString()}`
  }),
  Match.when(Match.number, (num) => `Regular number: ${num}`),
  Match.orElse(() => "Not a numeric type")
)

console.log(processLargeNumber(123n)) // "BigInt: 123"
console.log(processLargeNumber(9007199254740992n)) // "Large integer: 9007199254740992"
console.log(processLargeNumber(123)) // "Regular number: 123"
console.log(processLargeNumber("123")) // "Not a numeric type"
predicatesnumber
Source effect/Match.ts:15521 lines
export const bigint: Predicate.Refinement<unknown, bigint> = Predicate.isBigInt