Dividing Streams.java
Brian Goetz
brian.goetz at oracle.com
Thu Apr 11 10:51:00 PDT 2013
Joe quite correctly pointed out in the survey that Streams.java is a mix
of two things for two audiences:
- Utility methods for users to generate streams, like intRange()
- Low level methods for library writers to generate streams from
things like iterators or spliterators.
Merging them in one file is confusing, because users come away with the
idea that writing spliterators is something they're supposed to do,
whereas in reality, if we've done our jobs, they should never even be
aware that spliterators exist. So I think we should separate them into
a "high level" and "low level" bag of tricks.
Since today, Paul has added some new ones:
- singletonStream(v) (four flavors)
- builder() (four flavors)
So, we have to identify appropriate homes for the two groupings, and
separate them. Here's a first cut at separating them:
High level:
xxxRange
xxxBuilder
emptyXxxStream
singletonXxxStream
concat
zip
Low level:
all spliterator-related stream building methods
Not sure where (or even if):
iterate (given T0 and f, infinite stream of T0, f(T0), f(f(T0)), ...)
generate (infinite stream of independent applications of a generator,
good for infinite constant and random streams, though not much else,
used by impl of Random.{ints,longs,gaussians}).
Others that we've talked about adding:
ints(), longs() // to enable things like ints().filter(...).limit(n)
indexedGenerate(i -> T)
I think the high-level stuff should stay in Streams. So we need a name
for the low-level stuff. (Which also then becomes the right home for
"how do I turn my data sturcture into a stream" doc.)
What should we call that?
More information about the lambda-libs-spec-experts
mailing list