You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static <A> Stream<A> iteratorStream(final Iterator<A> it)
Due to Stream's use of WeakRef, when you visit the elements of Stream you can get a different result on the 2nd pass. (Internal mutable iterator keeps its state while cache is cleared)
I think this method should be avoided at all times because its behavior is unpredictable.
Splitterators created with the correct Characteristics should be safe (unsure). Maybe Stream<->java.util.Stream can be made safe, rather than deprecated.
"Consumable. The elements of a stream are only visited once during the life of a stream. Like an Iterator, a new stream must be generated to revisit the same elements of the source."
Java 8 Streams are designed for 1 pass only. So a 2nd pass is a misuse.
The deprecation of iteratorStream also mean the deprecation of iterableStream which also mean deprecating/refactoring api/implementation of big chunks of IterableW, F1Functions and ParModule.
So... kind of a can of worms :(
I see. It does not need attention yet. Its just something noticed a year ago that caught me out. Thought I make sure its noticed.
Even a warning in the javadoc that iteratorStream, can be used for constructing single pass Streams ONLY. And throw an Exception if a 2nd pass is detected when constructed with that method?
By throwing an Exception, at least we provide Deterministic behavior.
Activity
jbgi commentedon Nov 9, 2016
👍
I am also wondering if the Stream<->java.util.Stream should be subject to the same deprecation (in the java8 module). Will have a look.
clinuxrulz commentedon Nov 9, 2016
Splitterators created with the correct Characteristics should be safe (unsure). Maybe Stream<->java.util.Stream can be made safe, rather than deprecated.
clinuxrulz commentedon Nov 9, 2016
https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html
Down the bottom.
"Consumable. The elements of a stream are only visited once during the life of a stream. Like an Iterator, a new stream must be generated to revisit the same elements of the source."
Java 8 Streams are designed for 1 pass only. So a 2nd pass is a misuse.
jbgi commentedon Nov 9, 2016
The deprecation of
iteratorStreamalso mean the deprecation ofiterableStreamwhich also mean deprecating/refactoring api/implementation of big chunks ofIterableW,F1FunctionsandParModule.So... kind of a can of worms :(
clinuxrulz commentedon Nov 9, 2016
I see. It does not need attention yet. Its just something noticed a year ago that caught me out. Thought I make sure its noticed.
Even a warning in the javadoc that
iteratorStream, can be used for constructing single pass Streams ONLY. And throw an Exception if a 2nd pass is detected when constructed with that method?By throwing an Exception, at least we provide Deterministic behavior.
clinuxrulz commentedon Nov 11, 2016
IterableWavoids this problems as its usage of streams created byiteratorStreamare all single pass.So safety by documentation? Make people aware of limitations of
iteratorStream.