flatMap (was: Updated Java 8 Stream examples in GS Collections Kata) (original) (raw)

Paul Sandoz paul.sandoz at oracle.com
Wed Nov 14 01:21:42 PST 2012


On Nov 13, 2012, at 4:42 PM, Brian Goetz <brian.goetz at Oracle.COM> wrote:

The things I found awkward using in the kata were flatMap This is a complaint we received over and over again in the "Hack Day" sessions -- it is pretty clear we are not there yet on flatMap. 1. It is not obvious flatMap is the best name, as it sets expectations for Scala users that will not be met. Perhaps mapMulti? explode?

I would like to, but obviously cannot, call it "map*" to signify zero or more.

If there were static helper methods available for use in conjunction with flatMap that might help.

public class Yields { public static <T, R> FlatMapper<Collection, R> fromCollection((Mapper<T, Collection> m) { ... } }

...flatMap(Yields.fromCollection(Customer::getName))...

Perhaps a bit verbose. The connection to the static methods may not be obvious to developers.

If/when there are static methods supported on interfaces they could be declared in Stream.

Paul.



More information about the lambda-libs-spec-observers mailing list