BiIterable?

Remi Forax forax at univ-mlv.fr
Thu Jun 13 05:45:13 PDT 2013


On 06/13/2013 01:16 PM, Peter Levart wrote:
> 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?

BiIterable is a functional interface so one can write
   BiIterable<String,String> biIterable = map::forEach;

thus I don't think there is a need to put this interface in the JDK.

>
> Regards, Peter
>
>

cheers,
Rémi



More information about the lambda-dev mailing list