Skip to content

Commit

Permalink
fix(transducers): add "complete" step handling in scan()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 27, 2018
1 parent e1a282c commit 8e5204d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/transducers/src/xform/scan.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Reducer, Transducer } from "../api";
import { compR } from "../func/comp";
import { ensureReduced, isReduced } from "../reduced";

export function scan<A, B>(inner: Reducer<B, A>, acc?: B): Transducer<A, B> {
return (outer: Reducer<any, B>) => {
acc = acc || inner[0]();
const ri = inner[2],
ro = outer[2];
return compR(outer,
export function scan<A, B>([initi, completei, reducei]: Reducer<B, A>): Transducer<A, B> {
return ([inito, completeo, reduceo]: Reducer<any, B>) => {
let acc = initi();
return [
inito,
(_acc) => completeo(reduceo(_acc, completei(acc))),
(_acc, x) => {
acc = <any>ri(acc, x);
acc = <any>reducei(acc, x);
if (isReduced(acc)) {
return ensureReduced(ro(_acc, (<any>acc).deref()));
return ensureReduced(reduceo(_acc, (<any>acc).deref()));
}
return ro(_acc, acc);
});
return reduceo(_acc, acc);
}
];
};
}

0 comments on commit 8e5204d

Please sign in to comment.