forceOnAll will catch exception from resolving Stream element #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The expectation from forceOnAll is to force an attempt of execution of an operation on all elements. This works as intended when the elements are already resolved, as they are when passed as an array. But a
Stream
may resolve it's elements from any source, also sources which can typically fail, e.g. if the element are sourced from an API request. By default, an exception occurring when the Stream tries to yield an element for the pipeline of filters, maps, etc, will abort the Stream terminal operation, and be immediately thrown.In order to "tap into" the resolving logic, the approach of flatmapping to a (potential) exception using the regular Stream API has now been replaced with a bit more "low-level" use of a Spliterator which will invoke the intended side-effect, and catch any exception which can happen for both trying to advance to the next element, and from the operation itself on wishes to execute on a successfully resolved element.
This subtly changes the behavior of
forceOnAll
, but I consider this an alignment to what one expects fromforceOnAll
.I also added
DiggStreams.describeCharacteristics
to get a String description of the characteristics of a Spliterator, which is represented as a bit-string, and difficult to resolve which actual characteristics are enabled. It is not used by any other code in Digg, but was useful when implementing/debugging theFlatMapToExceptionSpliterator
, so I decided to include it. It does what it says on the tin, yields a text description, and you should not rely on the String for anything other than information.