"flat" map method

Stefan Springer stefan.springer1 at googlemail.com
Wed Jun 22 12:43:43 PDT 2011


The "classical" map method on a Collection<T> receives a closure { T => U }
giving a Collection<U>. What I am missing in all discussions is some kind of
a "flat" map method receiving a closure { T => Collection<T> } resulting in
a concatenation Collection<T> of all individual Collection<T> results for
each member of the original Collection<T>. I know that could be realized by
combining the map method with a reduce method, but for easy coding I think
such a "flatMap" method would be very nice. I know this pattern from the
XML/SGML transformation language MetaMorphosis where such a "flattening" is
very appropriate. Would vote for adding such a method for collections in
Java 8.


More information about the lambda-dev mailing list