Endo
    Preparing search index...

    Type Alias PatternMatchers

    Matchers for characterizing Passables and compound shapes.

    type PatternMatchers = {
        and: <P extends Pattern[]>(...subPatts: P) => MatcherOf<"and", P>;
        any: () => MatcherOf<"any">;
        array: (limits?: Limits) => MatcherOf<"arrayOf">;
        arrayOf: <P extends Pattern = Pattern>(
            subPatt?: P,
            limits?: Limits,
        ) => MatcherOf<"arrayOf", P>;
        bag: (limits?: Limits) => MatcherOf<"bagOf">;
        bagOf: <KP extends Pattern = Pattern>(
            keyPatt?: KP,
            countPatt?: Pattern,
            limits?: Limits,
        ) => MatcherOf<"bagOf", KP>;
        bigint: <T extends bigint = bigint>(
            limits?: Limits,
        ) => MatcherOf<"bigint", T>;
        boolean: () => MatcherOf<"kind", "boolean">;
        byteArray: (limits?: Limits) => MatcherOf<"byteArray">;
        containerHas: (
            elementPatt?: Pattern,
            bound?: bigint,
            limits?: Limits,
        ) => MatcherOf<"containerHas">;
        eq: (key: Key) => MatcherOf<"eq", Key>;
        eref: <P extends Pattern>(
            subPatt: P,
        ) => MatcherOf<"or", [P, MatcherOf<"promise">]>;
        error: () => MatcherOf<"kind", "error">;
        gt: (rightOperand: Key) => MatcherOf<"gt", Key>;
        gte: (rightOperand: Key) => MatcherOf<"gte", Key>;
        key: () => MatcherOf<"key">;
        kind: <K extends string>(kind: K) => MatcherOf<"kind", K>;
        lt: (rightOperand: Key) => MatcherOf<"lt", Key>;
        lte: (rightOperand: Key) => MatcherOf<"lte", Key>;
        map: (limits?: Limits) => MatcherOf<"mapOf">;
        mapOf: <KP extends Pattern = Pattern, VP extends Pattern = Pattern>(
            keyPatt?: KP,
            valuePatt?: VP,
            limits?: Limits,
        ) => MatcherOf<"mapOf", [KP, VP]>;
        nat: <T extends bigint = bigint>(limits?: Limits) => MatcherOf<"nat", T>;
        neq: (key: Key) => MatcherOf<"neq", Key>;
        not: (subPatt: Pattern) => MatcherOf<"not">;
        null: () => null;
        number: <T extends number = number>() => MatcherOf<"number", T>;
        opt: <P extends Pattern>(
            subPatt: P,
        ) => MatcherOf<"or", [P, MatcherOf<"kind", "undefined">]>;
        or: <P extends Pattern[]>(...subPatts: P) => MatcherOf<"or", P>;
        partial: (
            basePatt: CopyRecord<any> | CopyArray<any>,
            rest?: Pattern,
        ) => Matcher;
        pattern: () => MatcherOf<"pattern">;
        promise: <T extends Passable = any>(
            label?: string,
        ) => MatcherOf<"promise", T>;
        record: (limits?: Limits) => MatcherOf<"recordOf">;
        recordOf: <KP extends Pattern = Pattern, VP extends Pattern = Pattern>(
            keyPatt?: KP,
            valuePatt?: VP,
            limits?: Limits,
        ) => MatcherOf<"recordOf", [KP, VP]>;
        remotable: <
            T extends Passable = RemotableObject
            | RemotableBrand<any, any>,
        >(
            label?: string,
        ) => MatcherOf<"remotable", T>;
        scalar: () => MatcherOf<"scalar">;
        set: (limits?: Limits) => MatcherOf<"setOf">;
        setOf: <KP extends Pattern = Pattern>(
            keyPatt?: KP,
            limits?: Limits,
        ) => MatcherOf<"setOf", KP>;
        split: (
            basePatt: CopyRecord<any> | CopyArray<any>,
            rest?: Pattern,
        ) => Matcher;
        splitArray: <
            Req extends Pattern[] = Pattern[],
            Opt extends Pattern[] = [],
            Rest extends Pattern = never,
        >(
            required: [...Req],
            optional?: [...Opt],
            rest?: Rest,
        ) => MatcherOf<"splitArray", [Req, Opt, Rest]>;
        splitRecord: <
            Req extends CopyRecord<Pattern> = CopyRecord<Pattern>,
            Opt extends CopyRecord<Pattern> = {},
            Rest extends Pattern = never,
        >(
            required: Req,
            optional?: Opt,
            rest?: Rest,
        ) => MatcherOf<"splitRecord", [Req, Opt, Rest]>;
        string: <T extends string = string>(
            limits?: Limits,
        ) => MatcherOf<"string", T>;
        symbol: <T extends symbol = symbol>(
            limits?: Limits,
        ) => MatcherOf<"symbol", T>;
        tagged: <TP extends Pattern = Pattern, PP extends Pattern = Pattern>(
            tagPatt?: TP,
            payloadPatt?: PP,
        ) => MatcherOf<"tagged", [TP, PP]>;
        undefined: () => MatcherOf<"kind", "undefined">;
    }
    Index

    Properties

    and: <P extends Pattern[]>(...subPatts: P) => MatcherOf<"and", P>

    Matches against the intersection of all sub-Patterns.

    any: () => MatcherOf<"any">

    Matches any Passable.

    array: (limits?: Limits) => MatcherOf<"arrayOf">

    Matches any CopyArray, subject to limits.

    arrayOf: <P extends Pattern = Pattern>(
        subPatt?: P,
        limits?: Limits,
    ) => MatcherOf<"arrayOf", P>

    Matches any CopyArray whose elements are all matched by subPatt if defined, subject to limits.

    bag: (limits?: Limits) => MatcherOf<"bagOf">

    Matches any CopyBag, subject to limits.

    bagOf: <KP extends Pattern = Pattern>(
        keyPatt?: KP,
        countPatt?: Pattern,
        limits?: Limits,
    ) => MatcherOf<"bagOf", KP>

    Matches any CopyBag whose elements are all matched by keyPatt if defined and the cardinality of each is matched by countPatt if defined, subject to limits. countPatt is expected to rarely be useful, but is provided to minimize surprise.

    bigint: <T extends bigint = bigint>(limits?: Limits) => MatcherOf<"bigint", T>

    Matches any bigint, subject to limits.

    boolean: () => MatcherOf<"kind", "boolean">

    Matches true or false.

    byteArray: (limits?: Limits) => MatcherOf<"byteArray">

    Matches any ByteArray, subject to limits.

    containerHas: (
        elementPatt?: Pattern,
        bound?: bigint,
        limits?: Limits,
    ) => MatcherOf<"containerHas">

    Matches any array, CopySet, or CopyBag in which the bigint number of elements that match elementPatt is >= bound (which defaults to 1n).

    eq: (key: Key) => MatcherOf<"eq", Key>

    Matches any value that is equal to key.

    eref: <P extends Pattern>(
        subPatt: P,
    ) => MatcherOf<"or", [P, MatcherOf<"promise">]>

    Matches any Passable that is either matched by subPatt or is a promise object. Note that validation is immediate, so (unlike the TypeScript ERef<T> type) M.eref matches a promise object whose fulfillment value is not matched by subPatt. For describing a top-level parameter, M.callWhen(..., M.await(p), ...) is preferred over M.call(..., M.eref(p), ...) because the former always checks against the sub-Pattern (awaiting fulfillment if necessary) while the latter bypasses such checks when the relevant argument is a promise.

    error: () => MatcherOf<"kind", "error">

    Matches any error object. Error objects are Passable, but are neither Keys nor Patterns. They do not have a useful identity.

    gt: (rightOperand: Key) => MatcherOf<"gt", Key>

    Matches any value that compareKeys reports as greater than rightOperand.

    gte: (rightOperand: Key) => MatcherOf<"gte", Key>

    Matches any value that compareKeys reports as greater than or equal to rightOperand.

    key: () => MatcherOf<"key">

    Matches any value that can be a key in a CopyMap or an element in a CopySet or CopyBag. All matched values are also valid Patterns that match only themselves.

    kind: <K extends string>(kind: K) => MatcherOf<"kind", K>

    When kind specifies a PassStyle other than "tagged", matches any value having that PassStyle. Otherwise, when kind specifies a known tagged record tag (such as 'copySet', 'copyBag', 'copyMap', or 'match:scalar'), matches any CopyTagged with that tag and a valid tag-specific payload. Otherwise, does not match any value. TODO: Reject attempts to create a kind matcher with unknown kind?

    lt: (rightOperand: Key) => MatcherOf<"lt", Key>

    Matches any value that compareKeys reports as less than rightOperand.

    lte: (rightOperand: Key) => MatcherOf<"lte", Key>

    Matches any value that compareKeys reports as less than or equal to rightOperand.

    map: (limits?: Limits) => MatcherOf<"mapOf">

    Matches any CopyMap, subject to limits.

    mapOf: <KP extends Pattern = Pattern, VP extends Pattern = Pattern>(
        keyPatt?: KP,
        valuePatt?: VP,
        limits?: Limits,
    ) => MatcherOf<"mapOf", [KP, VP]>

    Matches any CopyMap whose keys are all matched by keyPatt if defined and values are all matched by valuePatt if defined, subject to limits.

    nat: <T extends bigint = bigint>(limits?: Limits) => MatcherOf<"nat", T>

    Matches any non-negative bigint, subject to limits.

    neq: (key: Key) => MatcherOf<"neq", Key>

    Matches any value that is not equal to key.

    not: (subPatt: Pattern) => MatcherOf<"not">

    Matches against the negation of the sub-Pattern.

    null: () => null

    Returns null, which matches only itself.

    number: <T extends number = number>() => MatcherOf<"number", T>

    Matches any floating point number, including NaN and either signed Infinity.

    opt: <P extends Pattern>(
        subPatt: P,
    ) => MatcherOf<"or", [P, MatcherOf<"kind", "undefined">]>

    Matches any Passable that is matched by subPatt or is the exact value undefined.

    or: <P extends Pattern[]>(...subPatts: P) => MatcherOf<"or", P>

    Matches against the union of all sub-Patterns (requiring a successful match against at least one).

    partial: (basePatt: CopyRecord<any> | CopyArray<any>, rest?: Pattern) => Matcher

    An array or record is split into the first part that is matched by basePatt, and the remainder, which is matched against rest if present. M.partial differs from M.split in the handling of data that is described in basePatt but absent in a provided specimen:

    • For a CopyRecord, M.partial ignores properties of basePatt that are not present on the specimen.
    • For a CopyArray, M.partial ignores elements of basePatt at indices beyond the maximum index of the specimen.

    Use M.splitArray or M.splitRecord instead.

    pattern: () => MatcherOf<"pattern">

    Matches any Pattern that can be used to characterize Passables. A Pattern cannot contain promises or errors, as these are not stable enough to usefully match.

    promise: <T extends Passable = any>(label?: string) => MatcherOf<"promise", T>

    Matches any promise object. Promises are Passable, but are neither Keys nor Patterns. They do not have a useful identity.

    record: (limits?: Limits) => MatcherOf<"recordOf">

    Matches any CopyRecord, subject to limits.

    recordOf: <KP extends Pattern = Pattern, VP extends Pattern = Pattern>(
        keyPatt?: KP,
        valuePatt?: VP,
        limits?: Limits,
    ) => MatcherOf<"recordOf", [KP, VP]>

    Matches any CopyRecord whose keys are all matched by keyPatt if defined and values are all matched by valuePatt if defined, subject to limits.

    remotable: <T extends Passable = RemotableObject | RemotableBrand<any, any>>(
        label?: string,
    ) => MatcherOf<"remotable", T>

    Matches a far object or its remote presence. The optional label is purely for diagnostic purposes and does not add any constraints.

    For facet-isolated return types in exo kits, pass an InterfaceGuard as the type parameter:

    const PublicI = M.interface('Public', {
    getData: M.call().returns(M.string()),
    });
    const AdminI = M.interface('Admin', {
    getPublic: M.call().returns(M.remotable<typeof PublicI>('Public')),
    });
    // TypeFromMethodGuard of getPublic → () => { getData: () => string } & RemotableObject
    scalar: () => MatcherOf<"scalar">

    Matches any Passable primitive value or Remotable. All matched values are Keys.

    set: (limits?: Limits) => MatcherOf<"setOf">

    Matches any CopySet, subject to limits.

    setOf: <KP extends Pattern = Pattern>(
        keyPatt?: KP,
        limits?: Limits,
    ) => MatcherOf<"setOf", KP>

    Matches any CopySet whose elements are all matched by keyPatt if defined, subject to limits.

    split: (basePatt: CopyRecord<any> | CopyArray<any>, rest?: Pattern) => Matcher

    An array or record is split into the first part that is matched by basePatt, and the remainder, which is matched against rest if present.

    Use M.splitArray or M.splitRecord instead.

    splitArray: <
        Req extends Pattern[] = Pattern[],
        Opt extends Pattern[] = [],
        Rest extends Pattern = never,
    >(
        required: [...Req],
        optional?: [...Opt],
        rest?: Rest,
    ) => MatcherOf<"splitArray", [Req, Opt, Rest]>

    Matches any array --- typically an arguments list --- consisting of

    • an initial portion matched by required, and
    • a middle portion of length up to the length of optional that is matched by the equal-length prefix of optional if optional is defined, and
    • a remainder that is matched by rest if rest is defined. The array must be at least as long as required but its remainder can be arbitrarily short. Any array elements beyond the summed length of required and optional are collected and matched against rest.
    splitRecord: <
        Req extends CopyRecord<Pattern> = CopyRecord<Pattern>,
        Opt extends CopyRecord<Pattern> = {},
        Rest extends Pattern = never,
    >(
        required: Req,
        optional?: Opt,
        rest?: Rest,
    ) => MatcherOf<"splitRecord", [Req, Opt, Rest]>

    Matches any CopyRecord that can be split into component CopyRecords as follows:

    • all properties corresponding with a property of required
    • all properties corresponding with a property of optional but not corresponding with a property of required
    • all other properties where the first component is matched by required, the second component is matched by the subset of optional corresponding with its properties if optional is defined, and the third component is matched by rest if defined. The CopyRecord must have all properties that appear on required, but may omit properties that appear on optional.
    string: <T extends string = string>(limits?: Limits) => MatcherOf<"string", T>

    Matches any string, subject to limits.

    symbol: <T extends symbol = symbol>(limits?: Limits) => MatcherOf<"symbol", T>

    Matches any registered or well-known symbol, subject to limits.

    tagged: <TP extends Pattern = Pattern, PP extends Pattern = Pattern>(
        tagPatt?: TP,
        payloadPatt?: PP,
    ) => MatcherOf<"tagged", [TP, PP]>

    For matching an arbitrary Passable Tagged object, whether it has a recognized kind or not. If tagPatt is omitted, it defaults to M.string(). If payloadPatt is omitted, it defaults to M.any().

    undefined: () => MatcherOf<"kind", "undefined">

    Matches the exact value undefined. All keys including undefined are already valid Patterns and so can validly represent themselves. But optional Pattern arguments (patt = undefined) => ... treat explicit undefined as omission of the argument. Thus, when a passed Pattern does not also need to be a Key, we recommend passing M.undefined() rather than undefined.