To Stream.slice(fromInclusive, toExclusive) or Stream.slice(toSkip, limit) that is the question
Joe Bowbeer
joe.bowbeer at gmail.com
Fri Oct 11 13:12:32 PDT 2013
Thanks for the example.
In terms of readability, I think skip(offset).limit(size) works well in
this case.
I think slice(offset, offset+size) works fine here, as well.
By the way, slice(start, end) has another potential advantage in that
negative values for the 'end' argument can be interpreted as an offset from
the end -- skipping the final x entries.
--Joe
On Fri, Oct 11, 2013 at 10:34 AM, Brian Goetz <brian.goetz at oracle.com>wrote:
> If you have a non-indexed stream, why would you ever
>> skip(start).limit(count) instead of simply limit(count)?
>>
>
> Here's one use case: Paging. You've got a stream of results, and you want
> to display them by pages.
>
> Stream results = input.skip((pageNo-1)***pageSize).limit(pageSize);
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20131011/ec600539/attachment.html
More information about the lambda-libs-spec-experts
mailing list