Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-09 Thread Paul Sandoz
HI Stefan, On Jun 7, 2015, at 10:07 PM, Stefan Zobel wrote: > I'm still trying to wrap my head around the test logic for the (par & !ord) > && (op == WhileOp.Drop) case > in the whileResultAsserter() method in WhileOpTest. > > Wouldn't it be possible that, for an unordered parallel stream, drop

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-07 Thread Stefan Zobel
I'm still trying to wrap my head around the test logic for the (par & !ord) && (op == WhileOp.Drop) case in the whileResultAsserter() method in WhileOpTest. Wouldn't it be possible that, for an unordered parallel stream, dropWhile() won't drop anything at all (i.e., drops an empty set)? In that c

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-07 Thread Chris Hegarty
I think the original version reads better. Remember that the method summary description contains only the first sentence. I disagree with the objection about ordering. The stream has some order in which is "sees" elements. That order may be non-deterministic, but it still exists, we just don’t

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-07 Thread Paul Sandoz
On Jun 6, 2015, at 1:20 AM, Stuart Marks wrote: > On 6/3/15 9:21 AM, Paul Sandoz wrote: >> I had prepared an alternative rendition stashed away just in case this came >> up :-) >> >> I still want to retain a punchy short first paragraph. What do you think >> about the following? >> >> /

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-05 Thread Stuart Marks
On 6/3/15 9:21 AM, Paul Sandoz wrote: I had prepared an alternative rendition stashed away just in case this came up :-) I still want to retain a punchy short first paragraph. What do you think about the following? /** - * Returns a stream consisting of the longest prefix of element

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-05 Thread Remi Forax
On 06/04/2015 10:34 AM, Paul Sandoz wrote: On Jun 4, 2015, at 10:09 AM, Remi Forax wrote: On 06/04/2015 09:37 AM, Paul Sandoz wrote: On Jun 4, 2015, at 9:04 AM, Remi Forax wrote: Thinking a little more about dropWhile(), it can be written using filter() more or less like this: default Str

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-04 Thread Paul Sandoz
On Jun 4, 2015, at 10:27 AM, Peter Levart wrote: > > On 06/03/2015 08:53 PM, Peter Levart wrote: >> Hi Paul, >> >> This is a usefull addition to Stream API for sequential ordered streams. But >> does it have any utility in unordered streams at all? Wouldn't it be better >> to just throw an Ill

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-04 Thread Paul Sandoz
On Jun 4, 2015, at 10:09 AM, Remi Forax wrote: > On 06/04/2015 09:37 AM, Paul Sandoz wrote: >> On Jun 4, 2015, at 9:04 AM, Remi Forax wrote: >>> Thinking a little more about dropWhile(), >>> it can be written using filter() more or less like this: >>> default Stream dropWhile(Predicate predica

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-04 Thread Peter Levart
On 06/03/2015 08:53 PM, Peter Levart wrote: Hi Paul, This is a usefull addition to Stream API for sequential ordered streams. But does it have any utility in unordered streams at all? Wouldn't it be better to just throw an IllegalStateException or something if the stream is not ordered? I c

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-04 Thread Remi Forax
On 06/04/2015 09:37 AM, Paul Sandoz wrote: On Jun 4, 2015, at 9:04 AM, Remi Forax wrote: Thinking a little more about dropWhile(), it can be written using filter() more or less like this: default Stream dropWhile(Predicate predicate) { return filter(new Predicate<>() { private boo

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-04 Thread Paul Sandoz
On Jun 4, 2015, at 9:04 AM, Remi Forax wrote: > Thinking a little more about dropWhile(), > it can be written using filter() more or less like this: > default Stream dropWhile(Predicate predicate) { > return filter(new Predicate<>() { > private boolean noDropAnymore; > public bool

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-04 Thread Remi Forax
Thinking a little more about dropWhile(), it can be written using filter() more or less like this: default Stream dropWhile(Predicate predicate) { return filter(new Predicate<>() { private boolean noDropAnymore; public boolean test(T t) { return noDropAnymore || (noDr

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-03 Thread Peter Levart
Hi Paul, This is a usefull addition to Stream API for sequential ordered streams. But does it have any utility in unordered streams at all? Wouldn't it be better to just throw an IllegalStateException or something if the stream is not ordered? I can't imagine currently a situation where I woul

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-03 Thread Paul Sandoz
Hi Stuart, I had prepared an alternative rendition stashed away just in case this came up :-) I still want to retain a punchy short first paragraph. What do you think about the following? Stream skip(long n); /** - * Returns a stream consisting of the longest prefix of elements

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-03 Thread Paul Sandoz
On Jun 2, 2015, at 8:58 PM, Chris Hegarty wrote: > Very nice. I just looked over the spec, for now. > > * @param predicate a href="package-summary.html#NonInterference">non-interfering, > * href="package-summary.html#Statelessness">stateless > *

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-02 Thread Stuart Marks
Hi Paul, Some comments on the spec. On 6/2/15 6:13 AM, Paul Sandoz wrote: http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8071597-take-drop-while/webrev/ I opted to weight the documentation of the operations towards ordered streams in the first paragraph. That is what makes most sense in term

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-02 Thread Chris Hegarty
Very nice. I just looked over the spec, for now. * @param predicate a non-interfering, * stateless * predicate to apply elements to determine the longest * prefix of elements. Is this missing a *to*, “… predicate to apply to

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-02 Thread Paul Sandoz
On Jun 2, 2015, at 3:50 PM, Stefan Zobel wrote: > Hi Paul, > > Looks good. > > I was wondering why the truncate method in Node.OfInt / OfLong / OfDouble > did not receive the same > > > +if (to == count()) { > +spliterator.forEachRemaining(nodeBuilder); > +} else

Fwd: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-02 Thread Stefan Zobel
Hi Paul, Looks good. I was wondering why the truncate method in Node.OfInt / OfLong / OfDouble did not receive the same +if (to == count()) { +spliterator.forEachRemaining(nodeBuilder); +} else { +for (int i = 0; i < size && spliterator.tryAdvance(nodeBui

Re: RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-02 Thread Remi Forax
Nice, another example of takeWhile is how to iterate over a linked list, class Entry { private final Entry next; private final Object value; Entry getNext() { return next; } Object getValue() { return value; } } Entry head = ... Stream.iterate(head, Entry::getNext) .takeWhile(Object

RFR 8071597 Add Stream dropWhile and takeWhile operations

2015-06-02 Thread Paul Sandoz
Hi, Please review this webrev that adds take/dropWhile operations to streams: http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8071597-take-drop-while/webrev/ I opted to weight the documentation of the operations towards ordered streams in the first paragraph. That is what makes most sense in ter