MapStream.sorted

Brian Goetz brian.goetz at oracle.com
Tue May 8 08:07:44 PDT 2012


There's a tension between having a single bi-valued stream (as we're trying to do currently, called MapStream) and having two versions, one for streams of key-value pairs (where the key is unique) and one for streams of undifferentiated pairs (such as the result of a zip() operation).  Where and how we maintain the "keys are unique" property, what operations preserve that, what operations require that, etc, is still a work in progress.  


On May 8, 2012, at 1:22 AM, Peter Levart wrote:

> Hi Mike and others,
> 
> Sorry to be picky, but the following MapStream method:
> 
>    MapStream<K, V> sorted(Comparator<? super K> comparator) default {
>        TreeMap<K,V> result = new TreeMap<>(comparator);
>        forEach( (k, v) -> { result.put(k, v); } );
> 
>        return result;
>    }
> 
> 
> ..."squashes" entries with duplicate keys (those that comparator.compare(k1, 
> k2) returns 0 for)...
> 
> The analog Iterable.sorted is more correct (uses PriorityQueue).
> 
> One still might want this behavior, but she could achieve that same by:
> 
>    mapStream.into(new TreeMap<>(comparator))
> 
> 
> Regards, Peter
> 
> 



More information about the lambda-dev mailing list