Skip to content

Commit

Permalink
Make all() post-stack again, and add each() for pre-stack (#1229)
Browse files Browse the repository at this point in the history
* Rename `all` to `each`, re-instating old `all`
  • Loading branch information
yaxu authored Dec 29, 2024
1 parent 26cc7e2 commit 9bf0f62
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 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 eachTransform;

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

Expand All @@ -88,6 +90,10 @@ export function repl({
allTransform = transform;
return silence;
};
const each = function (transform) {
eachTransform = 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,
each,
hush,
cpm,
setCps,
Expand All @@ -153,11 +160,14 @@ export function repl({
let { pattern, meta } = await _evaluate(code, transpiler, transpilerOptions);
if (Object.keys(pPatterns).length) {
let patterns = Object.values(pPatterns);
if (allTransform) {
patterns = patterns.map(allTransform);
if (eachTransform) {
patterns = patterns.map(eachTransform);
}
pattern = stack(...patterns);
} else if (allTransform) {
} else if (eachTransform) {
pattern = eachTransform(pattern);
}
if (allTransform) {
pattern = allTransform(pattern);
}
if (!isPattern(pattern)) {
Expand Down

0 comments on commit 9bf0f62

Please sign in to comment.