Limit operation

Paul Sandoz paul.sandoz at oracle.com
Mon Sep 17 02:16:21 PDT 2012


Hi,

Please see here for a simple implementation of the limit operation:

  http://cr.openjdk.java.net/~psandoz/lambda/limit/webrev/

Can someone with committer rights commit it?

--

This is the first intermediate type of operation that is short-circuiting. So it fills up a little gap in the use-cases.

Other potential intermediate short-circuit operations are interleave and zipmap.

This operation can be used in conjunction with a skip operation to produce a sub-stream and with streams of infinite size to limit the output to a finite size. Webrevs for those will appear in the very near future...

It is a stateful operation, so will end up slicing the pipeline for the parallel case. Currently uses a very dumb serial impl that buffers items until the limit is reached, which is bad when the limit is large. A spliterator-based parallel implementation has similarities to some of the terminal find* operations, so i will look at what Brian's is doing for those and copy where appropriate!

--

I tweaked the exerciseOps code to not test sink wrapping for short-circuit ops, since it is currently not possible to short-circuit when pushing.

I also look the liberty of cleaning up a bit the Iterator<Mapping<K, V> to MapIterator<K, V> code.

Paul.


More information about the lambda-dev mailing list