Updated State of the Collections
Jose
jgetino at telefonica.net
Fri Nov 16 01:40:43 PST 2012
So flatMap function has two arguments. For the second one you provide a
List of authors that you defined previously.
But what about the first argument?, sink is just a variable, it has not
being initialized at any place
I find this like defining the square function as:
sq=(x,y)->y*y
and then using it in this way
sq(x,3)==9
-----Mensaje original-----
De: Michael Hixson [mailto:michael.hixson at gmail.com]
Enviado el: viernes, 16 de noviembre de 2012 8:30
Para: Jose
CC: lambda-dev at openjdk.java.net
Asunto: Re: Updated State of the Collections
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