Static methods on Stream and friends
Brian Goetz
brian.goetz at oracle.com
Sun Apr 21 11:19:35 PDT 2013
I moved the following from Streams to Stream:
Stream.builder()
Stream.empty()
Stream.singleton(T)
Stream.of(T...)
Stream.iterate(T, T -> T)
Stream.generate(i -> T)
with the same on {Int,Long,Double}Stream, and also
{Int,Long,Double}Stream.range(start, end)
{Int,Long,Double}Stream.range(start, end, step)
It was suggested on lambda-dev that we should rename singleton to simply
be an overload of "of":
Stream.of(T)
Stream.of(T...)
which seems reasonable.
Remaining open issues:
- Some people are unhappy that range is half-open (which also means
people are constrained to ranges topping out at MAX_VALUE-1 rather than
MAX_VALUE). Some options:
- Add XxxStream.rangeExclusive(start, end)
- Further doc hints, such as renaming the parameters to
startInclusive / endExclusive
- Nothing
- Paul has suggested that generate be finite. While this is kind of
yucky, the practical difference between infinite and long-sized is
pretty much negligible, and the version based on
LongStream.range().map() parallellizes much better.
I propose to accept the suggestion of s/singleton/of/, go the "doc hint"
route on range, and go finite on generate.
Also never closed on whether there was value to ints() / longs() --
these show up in lots of teaching examples, though less so in real-world
code. Still, teaching people how to think about this stuff is important.
More information about the lambda-libs-spec-experts
mailing list