Updated State of the Collections

Michael Hixson michael.hixson at gmail.com
Thu Nov 15 23:30:04 PST 2012


flatMap caused me a lot of trouble as well.  Eventually I figured out you
can use it without casting, declaring anonymous classes, or using a helper
method like this:

List<Author> authors = ...
// Assume author.getBooks() returns List<Book>
List<Book> books = authors.stream()
    .<Book>flatMap((sink, author) -> author.getBooks().forEach(sink)
    .into(new ArrayList<Book>());
// Assume author.getDeceasedDate() returns Optional<Date>
List<Date> deceasedDates = authors.stream()
    .<Date>flatMap(sink, author) ->
author.getDeceasedDate().ifPresent(sink))
    .into(new ArrayList<Date>());

The generic for the flatMap invocations ("<Book>.flatMap" and
"<Date>flatMap" above) seem to be necessary.  I don't know if that was
because of the IDE I was using (IntelliJ 12 EAP) or because that's just how
it has to be.



On Thu, Nov 15, 2012 at 10:58 PM, Jose <jgetino at telefonica.net> wrote:

>
> Would you mind to provide an example of the use of flatMap?.
>
> I need to adapt old b56 code like this:
>
> Set<Polyline> lines(mapName){};
> namesColl.flatMap(name -> lines(name)).into(...);
>
> to the new sintax but I have no idea how to start with (do I have to
> provide
> a Block.instance?)
>
> I made some web search on flatMap and jdk8 but everyone seems to be talking
> about Optional.
> And in the repos I couln't find a single example, only discussions about
> the
> sintax.
>
>
>
>
> -----Mensaje original-----
> De: lambda-dev-bounces at openjdk.java.net
> [mailto:lambda-dev-bounces at openjdk.java.net] En nombre de Brian Goetz
> Enviado el: jueves, 15 de noviembre de 2012 19:32
> Para: lambda-dev at openjdk.java.net
> Asunto: Updated State of the Collections
>
> is here: http://cr.openjdk.java.net/~briangoetz/lambda/sotc3.html
>
>
>


More information about the lambda-dev mailing list