FuncType - v0.9.5
    Preparing search index...

    Type Alias Match<T, R>

    Pattern matching construct similar to Scala's match expressions. Supports exhaustive matching, nested patterns, and guards.

    // Basic pattern matching
    const result = Match(value)
    .case(x => x > 100, "large")
    .case(x => x > 50, "medium")
    .default("small")
    // Matching exact values
    const message = Match(status)
    .caseValue("pending", "Please wait...")
    .caseValue("success", "Completed!")
    .caseValue("error", "Failed")
    .default("Unknown")
    // Nested pattern matching
    const user = { name: "John", age: 30, role: "admin" }
    const msg = Match(user)
    .case({ role: "admin", age: n => n >= 18 }, "Adult admin")
    .case({ role: "user" }, u => `User: ${u.name}`)
    .default("Guest")
    type Match<T extends Type, R extends Type> = {
        case: (pattern: Pattern<T>, result: PatternResult<T, R>) => Match<T, R>;
        caseAny: (
            patterns: Pattern<T>[],
            result: PatternResult<T, R>,
        ) => Match<T, R>;
        caseValue: (match: T, result: R | (() => R)) => Match<T, R>;
        caseValues: (matches: T[], result: R | (() => R)) => Match<T, R>;
        default: (result: PatternResult<T, R>) => R;
        exhaustive: () => R;
        getOrThrow: (errorMessage?: string) => R;
        toOption: () => Option<R>;
        when: (
            guard: (value: T) => boolean,
            result: PatternResult<T, R>,
        ) => Match<T, R>;
    }

    Type Parameters

    Index

    Properties

    case: (pattern: Pattern<T>, result: PatternResult<T, R>) => Match<T, R>

    Match against a pattern (value, nested object, or predicate)

    caseAny: (patterns: Pattern<T>[], result: PatternResult<T, R>) => Match<T, R>

    Match multiple patterns (OR operation)

    caseValue: (match: T, result: R | (() => R)) => Match<T, R>

    Add a case that matches a specific value (backward compatibility)

    caseValues: (matches: T[], result: R | (() => R)) => Match<T, R>

    Add a case that matches multiple values (backward compatibility)

    default: (result: PatternResult<T, R>) => R

    Default case - makes match non-exhaustive

    exhaustive: () => R

    Force exhaustive matching (compile-time check for union types)

    getOrThrow: (errorMessage?: string) => R

    Get result if matched, throws if no match

    toOption: () => Option<R>

    Get result wrapped in Option

    when: (guard: (value: T) => boolean, result: PatternResult<T, R>) => Match<T, R>

    Match with a guard function (alias for readability)