Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Incremental Cell
public class DuelCell<A,DA> {
private final A initA;
private final Stream<DA> sda;
private final BiFunction<A,DA,A> patchA;
private final Cell<A> ca;
public DuelCell(
A initA,
Stream<DA> sda,
BiFunction<A,DA,A> patchA
) {
this.initA = initA;
this.sda = sda;
this.patchA = patchA; = sda.accum(initA, (DA da, A a) -> patchA.apply(a, da));
public <B,DB> DuelCell<B,DB> incMap(BiFunction<B,DB,B> patchB, Function<A,B> nonIncrementalFn, BiFunction<Tuple2<A,DA>,B,DB> incrementalFn) {
B initB = nonIncrementalFn.apply(ca.sample());
StreamLoop<Tuple2<B,DB>> slDuelB = new StreamLoop<>();
Cell<B> cb =<B,DB> duelB) -> patchB.apply(duelB.a, duelB.b)).hold(initB);
DuelCell<B,DB> dcb = new DuelCell<>(
sda.snapshot(ca, (DA da, A a) -> new Tuple2<>(a, da)).snapshot(cb, incrementalFn::apply),
slDuelB.loop(dcb.sda.snapshot(, (DB db, B b) -> new Tuple2<>(b, db)));
return dcb;
public Cell<A> cell() {
return ca;
public Stream<DA> deltaStream() {
return sda;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.