Skip to content

Commit

Permalink
Implement together() for a post-stack all()
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxu committed Dec 23, 2024
1 parent 26cc7e2 commit 32c6728
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/core/repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ export function repl({
let pPatterns = {};
let anonymousIndex = 0;
let allTransform;
let togetherTransform;

const hush = function () {
pPatterns = {};
anonymousIndex = 0;
allTransform = undefined;
togetherTransform = undefined;
return silence;
};

Expand All @@ -88,6 +90,10 @@ export function repl({
allTransform = transform;
return silence;
};
const together = function (transform) {
togetherTransform = transform;
return silence;
};

// set pattern methods that use this repl via closure
const injectPatternMethods = () => {
Expand Down Expand Up @@ -131,6 +137,7 @@ export function repl({
});
return evalScope({
all,
together,
hush,
cpm,
setCps,
Expand Down Expand Up @@ -160,6 +167,9 @@ export function repl({
} else if (allTransform) {
pattern = allTransform(pattern);
}
if (togetherTransform) {
pattern = togetherTransform(pattern)
}
if (!isPattern(pattern)) {
const message = `got "${typeof evaluated}" instead of pattern`;
throw new Error(message + (typeof evaluated === 'function' ? ', did you forget to call a function?' : '.'));
Expand Down

0 comments on commit 32c6728

Please sign in to comment.