function / @typed/guard

any

Runs candidates sequentially and returns the first match tagged with its key. Candidates are snapshotted from own enumerable keys when any is called. ECMAScript own-key order applies: integer-index strings, other strings, then symbols.

Package version
1.0.0-beta.7
Category
Alternative selection
Since
1.0.0

Import

import { any } from "@typed/guard";

Signatures

export declare function any<const GS extends Readonly<Record<string, GuardInput<any, any, any, any>>>>(guards: GS): Guard<AnyInput<GS>, AnyOutput<GS>, Guard.Error<GS[keyof GS]>, Guard.Services<GS[keyof GS]>>;

Why

Ordered first-match dispatch turns independently composable Guards into a deterministic tagged union without treating None as failure.

Ownership and lifetime

Construction snapshots own enumerable entries and acquires no resources; each run executes candidates sequentially until the first Some.

Examples

import { any, liftPredicate } from "@typed/guard"
const classify = any({ text: liftPredicate((u: unknown): u is string => typeof u === "string") })

Source