Skip to content

Commit

Permalink
feat(patterns): export kindOf (#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
erights authored Oct 29, 2023
1 parent 746974b commit f746e99
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/patterns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export {
getInterfaceMethodKeys,
assertInterfaceGuard,
getInterfaceGuardPayload,
kindOf,
} from './src/patterns/patternMatchers.js';

// ////////////////// Temporary, until these find their proper home ////////////
Expand Down
13 changes: 13 additions & 0 deletions packages/patterns/src/patterns/internal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
/** @typedef {import('../types').AllLimits} AllLimits */
/** @typedef {import('../types').GetRankCover} GetRankCover */

/**
* @typedef {Exclude<PassStyle, 'tagged'> |
* 'copySet' | 'copyBag' | 'copyMap' |
* `match:${any}` | `guard:${any}`
* } Kind
* It is either a PassStyle other than 'tagged', or, if the underlying
* PassStyle is 'tagged', then the `getTag` value for tags that are
* recognized at the @endo/patterns level of abstraction. For each of those
* tags, a tagged record only has that kind if it satisfies the invariants
* that the @endo/patterns level associates with that kind.
*/

/**
* @typedef {object} MatchHelper
* This factors out only the parts specific to each kind of Matcher. It is
Expand Down Expand Up @@ -85,4 +97,5 @@
* @property {(patt: Passable) => boolean} isPattern
* @property {GetRankCover} getRankCover
* @property {MatcherNamespace} M
* @property {(specimen: Passable, check?: Checker) => Kind | undefined} kindOf
*/
13 changes: 2 additions & 11 deletions packages/patterns/src/patterns/patternMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,6 @@ const makePatternKit = () => {
// eslint-disable-next-line no-use-before-define
GuardPayloadShapes[tag];

/**
* @typedef {Exclude<PassStyle, 'tagged'> |
* 'copySet' | 'copyBag' | 'copyMap' | keyof HelpersByMatchTag
* } Kind
* It is either a PassStyle other than 'tagged', or, if the underlying
* PassStyle is 'tagged', then the `getTag` value for tags that are
* recognized at the store level of abstraction. For each of those
* tags, a tagged record only has that kind if it satisfies the invariants
* that the store level associates with that kind.
*/

/** @type {Map<Kind, unknown>} */
const singletonKinds = new Map([
['null', null],
Expand Down Expand Up @@ -1719,6 +1708,7 @@ const makePatternKit = () => {
isPattern,
getRankCover,
M,
kindOf,
});
};

Expand All @@ -1736,6 +1726,7 @@ export const {
isPattern,
getRankCover,
M,
kindOf,
} = makePatternKit();

MM = M;
Expand Down

0 comments on commit f746e99

Please sign in to comment.