BiIterable?

Peter Levart peter.levart at gmail.com
Thu Jun 13 04:16:59 PDT 2013


With the advent of new functional types in java.util.function and new 
default method Map.forEach(), I wonder if it has been considered to add 
the following interface to standard library:

public interface BiIterable<T, U> {
     void forEach(BiConsumer<? super T, ? super U> action);
}


Which could be used as a super-interface for Map:

public interface Map<K,V> extends BiIterable<K, V> { ...


... in analogous way that Iterable<T> is super-interface of Collection<T>.

Iterable<T> supports external iteration from day one, and now it also 
supports internal iteration by the way of default method with optimized 
implementations in JDK classes that show improved performance. For 
BiIterable<T, U> internal iteration is actually the only alternative, 
since it avoids boxing of arguments into a Pair.


What do you think?

Regards, Peter



More information about the lambda-dev mailing list