Skip to content

Commit

Permalink
reductions minor
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Dec 7, 2023
1 parent 5fcd525 commit 4ca081f
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/squint/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,30 +582,31 @@ export function reduce(f, arg1, arg2) {
return val;
}

function _reductions(f, arg1, arg2) {
const [init, coll] = arg2 === undefined ? [undefined, arg1]: [arg1, arg2];
function _reductions2(f, coll) {
const s = seq(coll);
return new LazySeq(function () {
return s ? _reductions3(f, first(s), rest(s)) : list(f());
});
}

function _reductions3(f, init, coll) {
const s = seq(coll);
if (init === undefined) {
// (reductions f coll)
return new LazySeq(function () {
return s ? _reductions(f, first(s), rest(s)) : list(f());
});
} else {
// (reductions f val coll)
if (reduced_QMARK_(init)) {
return list(init.value);
}
return cons(init, new LazySeq(function () {
if (s) {
return _reductions(f, f(init, first(s)), rest(s));
return _reductions3(f, f(init, first(s)), rest(s));
}
}));
}
}

export function reductions(f, arg1, arg2) {
f = toFn(f);
return _reductions(f, arg1, arg2);
if (arg2 === undefined) {
return _reductions2(f, arg1);
}
return _reductions3(f, arg1, arg2);
}

var tolr = false;
Expand Down

0 comments on commit 4ca081f

Please sign in to comment.