Flatmap example
mohan.radhakrishnan at polarisFT.com
mohan.radhakrishnan at polarisFT.com
Mon Dec 2 20:24:51 PST 2013
That are 2 variants that compile. I mistook code folding for a new
pattern.
Mohan
From: Mohan Radhakrishnan/BSC31/polarisFT
To: lambda-dev at openjdk.java.net
Date: 12/03/2013 09:48 AM
Subject: Re: Flatmap example
I am using 113 and it compiles.. But I realized there are 3 variants.
//Style 1
patterns.stream()
.flatMap(new Function<Pattern, Stream<String>>() {
@Override
public Stream<String> apply(Pattern p) {
return source.stream()
.map(p::matcher)
.filter(Matcher::find)
.map(Matcher::group);
}
})
.forEach(System.out::println);
//Style 2
patterns.stream().flatMap(( Pattern p1 ) -> source.
stream().
map(p1::matcher).
filter(Matcher::find).map(matcher ->
matcher.group())).forEach(x -> System.out.println(x));
//Style 3
patterns.stream()
.flatMap(new Function<Pattern, Stream<String>>() {
@Override
public Stream<String> apply(Pattern p) {
return source.stream()
.map(p::matcher)
.filter(Matcher::find)
.map(Matcher::group);
}
})
.forEach(System.out::println);
Thanks,
Mohoan
From: Paul Sandoz <paul.sandoz at oracle.com>
To:
Cc: "lambda-dev at openjdk.java.net" <lambda-dev at openjdk.java.net>
Date: 12/02/2013 08:42 PM
Subject: Re: Flatmap example
Sent by: lambda-dev-bounces at openjdk.java.net
On Dec 2, 2013, at 3:31 PM, "Millies, Sebastian"
<Sebastian.Millies at softwareag.com> wrote:
> I can't get the second variant (without the inner class) to compile with
b117.
>
Compiles and runs for me against the tip of tl.
> The method reference in ".map(p::matcher)" seems illegal, and explicitly
typing the Lambda-Parameter
> "p" as "Pattern" leads to an Incompatible Types error. I have to cast
the function that goes into the flatMap
> to "Function<Pattern, Stream<String>>". Why is that?
>
I guess passing compile glitch or bug that was recently fixed.
Paul.
This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.
Visit us at http://www.polarisFT.com
More information about the lambda-dev
mailing list