-
Notifications
You must be signed in to change notification settings - Fork 136
Working with Primitives in Streams
ReactiveSeq and LazyFutureStream have methods
- ints
- doubles
- longs
Which convert the current Stream to a PrimitiveStream and allow a set of user defined operations to be executed on the PrimitiveStream before it is converted back to a ReactiveSeq / LazyFutureStream
ReactiveSeq.rangeLong(1, 1000)
.longs(i->i,
s->s.map(i->i*2)
.filter(i->i<500))
.size()
Cyclops uses primitive Spliterators where appropriate, if primite Spliterators are used during Stream creation they will passed into the primitive operator (ints, longs, doubles) of the same type if it is called immediately. Otherwise a conversion function will be used to convert the data to primitive form. The specialized primitive creation operators are range, rangeLong, ofInts, ofDoubles and ofLongs. Spliterator and fromStream can also be used to pass in Primitive Spliterators.
ReactiveSeq and LazyFutureStream have methods
- foldInt
- foldLongs
- foldDoubles
These methods allow users to chain together operations over primitive Streams that result in a single reduced value (via primitive Streams terminal operators).
ReactiveSeq.range(1, 1000)
.foldInt(i->i,
s->s.map(i->i*2)
.filter(i->i<500)
.average()
.getAsDouble());
oops - my bad