Known infinite streams

Paul Sandoz paul.sandoz at
Mon Sep 17 04:52:37 PDT 2012


Please see here for an implementation of known infinite streams

This patch is based on the previous one [1] for limit.

Currently i have placed, for want of a better place, sources for infinite streams as static methods on Streams. This fills another little gap in the use-cases.

There are other infinite sources yet to be considered e.g. reading stuff from I/O.

Such implementations of StreamAccessor are currently limited:

- to pull access, since pushing cannot, currently, be short-circuited; and

- to sequential access, so it is not possible to evaluate in parallel. It remains an open question on how to do that, but it is noted that an infinite stream could be split into a finite lhs and an infinite rhs using Spliterator.

It is possible to detect certain cases that would cause non-termination of a pipeline e.g.:


Namely when the terminal operation is not short-circuiting. But it is not possible in all cases e.g.:

  Streams.cycle(Arrays.asList(1, 2, 3, 4)).allMatch(i -> i < 5)

In addition it is not currently possible to differentiate between intermediate stateful ops that need to process all the input to produce a result, e.g. SortedOp, and those which don't e.g. CumulateOp:

  // That way madness lies



More information about the lambda-dev mailing list