buffer<A> static method

Conveyor<From<A>, A> buffer<A>(
  1. Monoid<A> monoid,
  2. int n
)

Implementation

static Conveyor<From<A>, A> buffer<A>(Monoid<A> monoid, int n) {
  Conveyor<From<A>, A> go(int i, A sofar) =>
      consume(
          (a) => i > 1 ? go(i-1, monoid.append(sofar, a)) : produce(monoid.append(sofar, a), go(n, monoid.zero()))
          ,() => sofar == monoid.zero() ? halt() : produce(sofar));
  return go(n, monoid.zero());
}