Synesso
Synesso

Reputation: 38978

Infinite stream from enumeration

In functional-java, I expected the following to create an infinite stream:

Stream.forever(Enumerator.booleanEnumerator, false);

But it stops after one full enumeration. The javadoc kind of confirms this, stating that it may only stream until the enumeration is exhausted.

Returns a stream that is either infinite or bounded up to the maximum 
value of the given iterator starting at the given value and stepping at 
increments of 1.

So, how do I make an infinite stream?

Upvotes: 2

Views: 287

Answers (1)

Shlomi
Shlomi

Reputation: 4748

You could look at Stream.cycle, it makes an infinite stream out of the input stream

Stream.cycle(Stream.forever(Enumerator.booleanEnumerator, false))

Upvotes: 1

Related Questions