chunk<A> static method

Conveyor<From<A>, IVector<A>> chunk<A>(
  1. int n
)

Implementation

static Conveyor<From<A>, IVector<A>> chunk<A>(int n) {
  Conveyor<From<A>, IVector<A>> go(int i, IVector<A> sofar) =>
      consume(
          (a) => i > 1 ? go(i-1, sofar.appendElement(a)) : produce(sofar.appendElement(a), go(n, emptyVector()))
          ,() => sofar.length() == 0 ? halt() : produce(sofar));
  return go(n, emptyVector());
}