Automatic widening of numeric types for primitive Streams #66
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 widening conversions follow the usual pattern. Float becomes
Double, Byte/Char/Short become Int. Boolean and Unit are not widened.
For Arrays, where the actual data is unboxed, widening is implemented
through custom Stepper implementations, so you can get e.g. a native
IntStepper for an Array[Byte]. The StreamConverters hierarchy is
modified to prefer these widened primitive steppers, so that, for
example, the
seqStream
extension method on an Array[Byte] returnsan IntStream.
Other collection types with a boxed representation also get the same
widening conversions (so you can still benefit from the better
performance of unboxed streams) but there are no implicitly available
widening steppers. Only the Stream extension methods fall back to
applying a widening stepper in order to produce a widening primitive
stream.
Widening narrow numeric types for streams is consistent with the Streams
API in the JDK. For example,
CharSequence.chars
returns anIntStream
instead of a
Stream[Character]
.