To Stream.slice(fromInclusive, toExclusive) or Stream.slice(toSkip, limit) that is the question
Paul Sandoz
paul.sandoz at oracle.com
Fri Oct 11 04:41:02 PDT 2013
On Oct 11, 2013, at 12:32 PM, Stephen Colebourne <scolebourne at joda.org> wrote:
> skip() and limit() make perfect sense. I'm surprised by the notion
> that skip(60).limit(10) would be less efficient than
> skipAndLimit(60,10) - that seems like an implementation detail that
> should not drive the API.
I did not mean suggest that was driving the reason for slice (or for that matter subStream), regardless of the form of its arguments.
The main point i wanted to make is it is easy to comprehend slice as a *more concise* representation of skip immediately followed by limit (and additionally there are currently implementation reasons as to why it is beneficial to use that form, since we don't currently internally fuse operations).
Paul.
> Thus I dislike the current slice definition.
>
> More generally, my expectation from experience is that slice would be
> slice(start, endExclusive). I'd also expect slice to support negative
> indicies to refer releative to the end, otherwise I'd be wondering why
> it wasn't called subStream.
>
> Thus my preference is:
> - skip(elementsToSkip)
> - limit(elementLimit)
> - subStream(startInclusive, endExclusive)
> - make skip().limit() efficient internally
>
> I don't think anyone will be surprised by those three methods.
>
> Stephen
More information about the lambda-libs-spec-observers
mailing list