来自枚举的无限流

Infinite stream from enumeration

在 functional-java 中,我希望创建一个无限流:

Stream.forever(Enumerator.booleanEnumerator, false);

但是在一个完整的枚举之后它停止了。 javadoc 证实了这一点,指出它只能在枚举耗尽之前流式传输。

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.

那么,如何制作无限流?

您可以查看 Stream.cycle,它从输入流中生成无限流

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