BiIterable?

Artur Biesiadowski abies at adres.pl
Thu Jun 13 07:57:50 PDT 2013


On 13/06/2013 14:40, Ali Ebrahimi wrote:
> what about Iterable<Entry<K,V>>:
>
> public interface Map<K,V> extends Iterable<Entry<K,V>> {
>         default Iterator<Entry<K,V>> iterator(){...}
> .
>
> }
>
> with Iterable<Entry<K,V>> internal iteration is not the only alternative,
> because you can now
>
> for(Entry<K,V> e:map)
>
> if we move stream and parallelStream methods to Iterable we can utilize
> from stream framework:
> map.stream().filter( e -> e.getKey().contains("somePattern")).map(e ->
> e.getValue())....
>

Some map implementations (fast ones mostly...) don't use Entry 
internally, so they have either to create a new one on each .next() or 
break a contract a bit and reuse same one over and over, hoping nobody 
will cache them (and that they are not used in parallel environment like 
your example above).

I don't suppose there is a way to do

map.stream().filter(k,v -> e.contains("somePattern")).map(k,v -> v)

?

Regards,
Artur Biesiadowski


More information about the lambda-dev mailing list