Substream applied to unordered streams

Georgiy Rakov georgiy.rakov at
Sat Mar 16 13:43:45 PDT 2013

On 15.03.2013 22:45, Brian Goetz wrote:
>> it seems that 'limit' and 'substream' methods applied to unordered
>> stream return result which seems to be only partially deterministic.
> Right, which makes sense.  substream (and by extension limit) are 
> defined in terms of encounter order; if the encounter order is merely 
> accidental, as it is in an unordered stream, there's not much we can 
> do there.
>> Similar thing is true for 'sorted' method provided stream contains equal
>> elements and 'sorted' uses algorithm preserving order.
> I think you're asking whether sorting is stable (for ordered streams) 
> or not?

Pardon me, yes I meant "stable sorting",
I meant that 'sorted' result becomes a bit more nondetermenistic for 
unordered streams provided they contain equal elements and 'sorted' uses 
stable sorting; actually stable sorting turns into unstable sorting (of 
course if sorting was stable originally).

In general I asked whether you see useful to show these points in spec, 
e. g. if spec contains something like:

    You should keep in mind that substream() could return stream which
    content is nondeterministic provided original stream encounter order
    is not defined, e.g. for stream returned from HashSet instance.

and for "sorted":

    You should keep in mind that sorting becomes actually unstable when
    applied to unordered stream.

The later only makes sense if "sorted()" uses stable sort, if it uses 
non stable sorting nothing changes for unordered streams.

And the question you mentioned above is relevant as well - I would 
appreciate greatly if you tell whether "sorted()" uses stable sorting.

Thank you,

More information about the lambda-dev mailing list