Is there already a helper in the StreamSupport? I failed to find one.
Or a plan to back-port it? Or a more clever / concise work-around?
Current work-around:
BitSet::stream might be a pretty rare case, I agree — I wouldn't stumble upon it were I not porting Stream of Permutations [Java Precisely, p. 139, ex. 175]. I just got misled at first by the BitSet::toLongArray's doc saying: "Returns a new long array containing all the bits in this bit set." to a naïve & incorrect:
Since the long[] returned forms in fact a bit-packed internal storage of the set, instead of ordinal positions of bits set to true as in the case of BitSet::stream.
The line has to be drawn somewhere, indeed. Most of the time, it's sufficiently painless to go via T -> U[] -> Stream<U> or via T -> Collection<U> -> Stream<U>. Exceptions are scarce and usually require a range() + map(), like in:
P.S.: Thank you very much for such a great lib! I'm using the streamsupport + retrolambda combo in a conservative (J6) production environment for about a half a year now and it helps immensely — sanity-wise! ;o)
Last edit: Anonymous 2016-07-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Nice to hear of a usage on Java 6! Sometimes I'm led to believe that streamsupport is mostly utilized by Android devs. Initially, Java 6 & Java 7 were the only target platforms I could imagine.
Cheers,
Stefan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
j.u.BitSet::stream
Is there already a helper in the StreamSupport? I failed to find one.
Or a plan to back-port it? Or a more clever / concise work-around?
Current work-around:
Or a more convoluted one:
/~Karel~/
Last edit: Anonymous 2016-07-04
No, only Collections are supported. I had to draw a line somewhere. And BitSet.stream() being useful seems to be a very rare event.
I don't think that there is way to do better than you already did. Your first workaround looks quite reasonable to me.
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
BitSet::stream
might be a pretty rare case, I agree — I wouldn't stumble upon it were I not porting Stream of Permutations [Java Precisely, p. 139, ex. 175]. I just got misled at first by theBitSet::toLongArray
's doc saying: "Returns a new long array containing all the bits in this bit set." to a naïve & incorrect:Since the
long[]
returned forms in fact a bit-packed internal storage of the set, instead of ordinal positions of bits set totrue
as in the case ofBitSet::stream
.The line has to be drawn somewhere, indeed. Most of the time, it's sufficiently painless to go via
T -> U[] -> Stream<U>
or viaT -> Collection<U> -> Stream<U>
. Exceptions are scarce and usually require arange()
+map()
, like in:/~Karel~/
P.S.: Thank you very much for such a great lib! I'm using the streamsupport + retrolambda combo in a conservative (J6) production environment for about a half a year now and it helps immensely — sanity-wise! ;o)
Last edit: Anonymous 2016-07-04
Hi Karel,
thanks for your kind words.
Nice to hear of a usage on Java 6! Sometimes I'm led to believe that streamsupport is mostly utilized by Android devs. Initially, Java 6 & Java 7 were the only target platforms I could imagine.
Cheers,
Stefan