Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(patterns): export kindOf #1834

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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