Java 8 brought some interesting functional aspects to the Java standard library - a fairly decent support for transforming streams of data. Ruby, obviously, has its own perks to do quite more (as binding and closures are first class) but there’s no reason to be left out … on JRuby.
And so, without much fanfare,
stream helper. We’ve touched on Java streams previously, the same is
feasible using a Ruby array (block-less
each returns an enumerator) :
… or an example with an explicit
Enumerator calculating fibonacci till the end :
On a final note, using parallel streaming does not make much sense.
Although (non-blocking) thread-safe
Enumerator instances are achievable, parallelizing
iteration over such won’t provide the desired benefit until JRuby’s underlying
thread-based implementation details are synchronizing over