Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33959 > unrolled thread
| Started by | Rhino <no_offline_contact@example.com> |
|---|---|
| First post | 2016-03-14 16:32 -0400 |
| Last post | 2016-03-14 21:55 -0400 |
| Articles | 15 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
Lambda reference? Rhino <no_offline_contact@example.com> - 2016-03-14 16:32 -0400
Re: Lambda reference? Sebastian <news@seyweiler.dyndns.org> - 2016-03-14 21:50 +0100
Re: Lambda reference? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-14 17:16 -0400
Re: Lambda reference? Rhino <no_offline_contact@example.com> - 2016-03-14 18:29 -0400
Re: Lambda reference? Eric Douglas <e.d.programmer@gmail.com> - 2016-03-16 04:53 -0700
Re: Lambda reference? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-16 08:38 -0400
Re: Lambda reference? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-16 08:45 -0400
Re: Lambda reference? Sebastian <news@seyweiler.dyndns.org> - 2016-03-16 21:33 +0100
Re: Lambda reference? Robert Klemme <shortcutter@googlemail.com> - 2016-03-25 18:35 +0100
Re: Lambda reference? Eric Douglas <e.d.programmer@gmail.com> - 2016-03-28 07:06 -0700
Re: Lambda reference? Robert Klemme <shortcutter@googlemail.com> - 2016-03-31 00:09 +0200
Re: Lambda reference? Eric Douglas <e.d.programmer@gmail.com> - 2016-03-31 04:42 -0700
Re: Lambda reference? Robert Klemme <shortcutter@googlemail.com> - 2016-03-31 18:35 +0200
Re: Lambda reference? Eric Douglas <e.d.programmer@gmail.com> - 2016-03-31 11:21 -0700
Re: Lambda reference? Rhino <no_offline_contact@example.com> - 2016-03-14 21:55 -0400
| From | Rhino <no_offline_contact@example.com> |
|---|---|
| Date | 2016-03-14 16:32 -0400 |
| Subject | Lambda reference? |
| Message-ID | <nc770d$u97$1@dont-email.me> |
I'm just new to Java Lambda expressions. I'm both excited and frustrated by the Oracle tutorials describing them: the tutorial shows how powerful they are and that's got me keen to know more but I'm not finding the detailed references I need to be able to do what I want to do. For example, they give an example that involves using a stream and a filter and then printing some stuff which looks something like: roster .stream .filter .... ... System.out.println(); I'd like to know what *all* my options, not just .stream and .filter. I'm also curious to know what are all the things I can do on the last line. For example, I want to go through a collection and find out how many instances of a given agency code are in the collection but have no idea how to do that or where to look in the API. I just want to put that count in an integer for use later in the program. I assume there is a reference manual somewhere that tells me all the things I can do with my collection using Lambdas but I'm not seeing any pointer to that manual in the Oracle material. -- Rhino
[toc] | [next] | [standalone]
| From | Sebastian <news@seyweiler.dyndns.org> |
|---|---|
| Date | 2016-03-14 21:50 +0100 |
| Message-ID | <nc7879$hlf$1@news.albasani.net> |
| In reply to | #33959 |
Am 14.03.2016 21:32, schrieb Rhino: > I'm just new to Java Lambda expressions. I'm both excited and frustrated > by the Oracle tutorials describing them: the tutorial shows how powerful > they are and that's got me keen to know more but I'm not finding the > detailed references I need to be able to do what I want to do. > > For example, they give an example that involves using a stream and a > filter and then printing some stuff which looks something like: > > roster > .stream > .filter .... > ... System.out.println(); > > I'd like to know what *all* my options, not just .stream and .filter. > I'm also curious to know what are all the things I can do on the last line. > > For example, I want to go through a collection and find out how many > instances of a given agency code are in the collection but have no idea > how to do that or where to look in the API. I just want to put that > count in an integer for use later in the program. > > I assume there is a reference manual somewhere that tells me all the > things I can do with my collection using Lambdas but I'm not seeing any > pointer to that manual in the Oracle material. > The "reference manual" would be the API docs. Not just the Stream class docs, you should read very carefully the java.util.stream package documentation: http://docs.oracle.com/javase/8/docs/api/ Maurice Naftalin's Lambda FAQ is an excellent resource: http://www.lambdafaq.org/ There were two good introductory articles in the Oracle Java Magazine a while back (Oracle Java Magazine articles, which are available only to subscribers. Subscription is free): Evans, Ben, Verburg, Martijn, Using Java 8 Lambda Expressions, March/April 2013, Oracle Java Magazine Evans, Ben, Verburg, Martijn, Advanced Operations Using Java 8 Lambda Expressions, May/June 2013, Oracle Java Magazine And here's in-depth coverage of streams by Paul Sandoz from JavaOne 2013, San Francisco: https://www.youtube.com/watch?v=UKuFqAhDEN4 There's tons more, when you search for it. -- Sebastian
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-03-14 17:16 -0400 |
| Message-ID | <nc79gr$9e6$1@dont-email.me> |
| In reply to | #33959 |
On 3/14/2016 4:32 PM, Rhino wrote:
> I'm just new to Java Lambda expressions. I'm both excited and frustrated
> by the Oracle tutorials describing them: the tutorial shows how powerful
> they are and that's got me keen to know more but I'm not finding the
> detailed references I need to be able to do what I want to do.
> [...]
See Sebastian's response. I'd just like to add that lambdas and
streams are two different things, and that you may confuse yourself
if you try to conflate them. Lambda expressions are often useful with
streams, but you can use streams without them. Streams are frequent
users of lambda expressions, but lambda expressions have non-stream
uses as well.
Here's a fragment using a lambda, with no stream (or collection)
anywhere in sight:
gadget.addActionListener((evt) -> {
... do something with the ActionEvent ...
});
... which we used to have to write as:
gadget.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
... do something with the ActionEvent ...
}
});
And here's a stream operation with no lambda in the neighborhood:
Predicate<Thing> pred = new Predicate<>() {
@Override
public boolean test(Thing thing) {
... long, complicated computation ...
return answer;
}
};
List<Thing> theChosenFew = allThings.stream()
.filter(pred)
.collect(Collectors.toList());
... which we might have lambda-ized (if it's not too bulky):
List<Thing> theChosenFew = allThings.stream()
.filter((thing) -> {
... long, complicated computation ...
return answer;
})
.collect(Collectors.toList());
So: Although they are frequently used together, try to bear in
mind that there's no "necessary" connection between lambda expressions
and stream operations.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Rhino <no_offline_contact@example.com> |
|---|---|
| Date | 2016-03-14 18:29 -0400 |
| Message-ID | <nc7drr$pqt$1@dont-email.me> |
| In reply to | #33961 |
On 3/14/2016 5:16 PM, Eric Sosman wrote:
> On 3/14/2016 4:32 PM, Rhino wrote:
>> I'm just new to Java Lambda expressions. I'm both excited and frustrated
>> by the Oracle tutorials describing them: the tutorial shows how powerful
>> they are and that's got me keen to know more but I'm not finding the
>> detailed references I need to be able to do what I want to do.
>> [...]
>
> See Sebastian's response. I'd just like to add that lambdas and
> streams are two different things, and that you may confuse yourself
> if you try to conflate them. Lambda expressions are often useful with
> streams, but you can use streams without them. Streams are frequent
> users of lambda expressions, but lambda expressions have non-stream
> uses as well.
>
> Here's a fragment using a lambda, with no stream (or collection)
> anywhere in sight:
>
> gadget.addActionListener((evt) -> {
> ... do something with the ActionEvent ...
> });
>
> ... which we used to have to write as:
>
> gadget.addActionListener(new ActionListener() {
> @Override
> public void actionPerformed(ActionEvent evt) {
> ... do something with the ActionEvent ...
> }
> });
>
> And here's a stream operation with no lambda in the neighborhood:
>
> Predicate<Thing> pred = new Predicate<>() {
> @Override
> public boolean test(Thing thing) {
> ... long, complicated computation ...
> return answer;
> }
> };
> List<Thing> theChosenFew = allThings.stream()
> .filter(pred)
> .collect(Collectors.toList());
>
> ... which we might have lambda-ized (if it's not too bulky):
>
> List<Thing> theChosenFew = allThings.stream()
> .filter((thing) -> {
> ... long, complicated computation ...
> return answer;
> })
> .collect(Collectors.toList());
>
> So: Although they are frequently used together, try to bear in
> mind that there's no "necessary" connection between lambda expressions
> and stream operations.
>
Excellent point! I've just come across lambdas for the first time in a
tutorial on collections so I'm sure I *am* conflating them somewhat.
I'll make sure to treat them as separate and distinct things that may be
useful to one another.
--
Rhino
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2016-03-16 04:53 -0700 |
| Message-ID | <8bd6f2b0-75b2-43fe-93ba-650ebffc940e@googlegroups.com> |
| In reply to | #33961 |
On Monday, March 14, 2016 at 5:16:17 PM UTC-4, Eric Sosman wrote: ... Do lambdas make code execute faster or just do the same thing with fewer characters?
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-03-16 08:38 -0400 |
| Message-ID | <ncbjv3$h6s$1@dont-email.me> |
| In reply to | #33983 |
On 3/16/2016 7:53 AM, Eric Douglas wrote:
> On Monday, March 14, 2016 at 5:16:17 PM UTC-4, Eric Sosman wrote:
> ...
>
> Do lambdas make code execute faster or just do the same thing with fewer characters?
"Yes." :)
Sorry I can't offer details, but quite some time ago I saw a
video of an Oracle guy explaining how lambdas were implemented
under the hood. In some cases the compiler simply generates an
anonymous inner class and the lambda just turns out to be shorthand.
But if the lambda expression is entirely self-contained -- refers
only to its own arguments and not to variables belonging to the
caller -- some kind of JVM trickery can be employed that eliminates
a good deal of the ordinary overhead.
Sorry for the sketchy response; wish I could still find the
video.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2016-03-16 08:45 -0400 |
| Message-ID | <ncbkcc$iec$1@dont-email.me> |
| In reply to | #33984 |
On 3/16/2016 8:38 AM, Eric Sosman wrote:
> On 3/16/2016 7:53 AM, Eric Douglas wrote:
>> On Monday, March 14, 2016 at 5:16:17 PM UTC-4, Eric Sosman wrote:
>> ...
>>
>> Do lambdas make code execute faster or just do the same thing with
>> fewer characters?
>
> "Yes." :)
>
> Sorry I can't offer details, but quite some time ago I saw a
> video of an Oracle guy explaining how lambdas were implemented
> under the hood. In some cases the compiler simply generates an
> anonymous inner class and the lambda just turns out to be shorthand.
> But if the lambda expression is entirely self-contained -- refers
> only to its own arguments and not to variables belonging to the
> caller -- some kind of JVM trickery can be employed that eliminates
> a good deal of the ordinary overhead.
>
> Sorry for the sketchy response; wish I could still find the
> video.
Hah! "This just in:"
http://medianetwork.oracle.com/video/player/1785479333001
... and this one, more specifically about peformance:
http://medianetwork.oracle.com/video/player/2623576348001
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Sebastian <news@seyweiler.dyndns.org> |
|---|---|
| Date | 2016-03-16 21:33 +0100 |
| Message-ID | <nccftv$iki$1@news.albasani.net> |
| In reply to | #33985 |
Am 16.03.2016 13:45, schrieb Eric Sosman: > On 3/16/2016 8:38 AM, Eric Sosman wrote: >> On 3/16/2016 7:53 AM, Eric Douglas wrote: >>> On Monday, March 14, 2016 at 5:16:17 PM UTC-4, Eric Sosman wrote: >>> ... >>> >>> Do lambdas make code execute faster or just do the same thing with >>> fewer characters? >> >> "Yes." :) >> >> Sorry I can't offer details, but quite some time ago I saw a >> video of an Oracle guy explaining how lambdas were implemented >> under the hood. In some cases the compiler simply generates an >> anonymous inner class and the lambda just turns out to be shorthand. >> But if the lambda expression is entirely self-contained -- refers >> only to its own arguments and not to variables belonging to the >> caller -- some kind of JVM trickery can be employed that eliminates >> a good deal of the ordinary overhead. >> >> Sorry for the sketchy response; wish I could still find the >> video. > > Hah! "This just in:" > > http://medianetwork.oracle.com/video/player/1785479333001 > > ... and this one, more specifically about peformance: > > http://medianetwork.oracle.com/video/player/2623576348001 > invokedynamic allows the type representation, instance creation, and invocation strategy to be decided at runtime. You can also have "shared lambbdas", e. g. invocation of a constant static method in a constant pool, needing no new class and/or new object. -- Sebastian
[toc] | [prev] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2016-03-25 18:35 +0100 |
| Message-ID | <dllb7jF5g4nU1@mid.individual.net> |
| In reply to | #33985 |
On 16.03.2016 13:45, Eric Sosman wrote: > Hah! "This just in:" > > http://medianetwork.oracle.com/video/player/1785479333001 > > ... and this one, more specifically about peformance: > > http://medianetwork.oracle.com/video/player/2623576348001 "WE'RE SORRY You need to update your Flash Player." No way! Also, my Chromium doesn't have a "Flash Player" at all... ;-) Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2016-03-28 07:06 -0700 |
| Message-ID | <2a431747-6843-4cc8-9577-590570294250@googlegroups.com> |
| In reply to | #34021 |
On Friday, March 25, 2016 at 1:36:06 PM UTC-4, Robert Klemme wrote: > > http://medianetwork.oracle.com/video/player/1785479333001 > > > > ... and this one, more specifically about peformance: > > > > http://medianetwork.oracle.com/video/player/2623576348001 > > "WE'RE SORRY > > You need to update your Flash Player." > > No way! Also, my Chromium doesn't have a "Flash Player" at all... ;-) You're doing it wrong? Videos play fine for me in Chrome.
[toc] | [prev] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2016-03-31 00:09 +0200 |
| Message-ID | <dm3144Fke7gU1@mid.individual.net> |
| In reply to | #34040 |
On 28.03.2016 16:06, Eric Douglas wrote: > On Friday, March 25, 2016 at 1:36:06 PM UTC-4, Robert Klemme wrote: >>> http://medianetwork.oracle.com/video/player/1785479333001 >>> >>> ... and this one, more specifically about peformance: >>> >>> http://medianetwork.oracle.com/video/player/2623576348001 >> >> "WE'RE SORRY >> >> You need to update your Flash Player." >> >> No way! Also, my Chromium doesn't have a "Flash Player" at all... ;-) > > You're doing it wrong? Videos play fine for me in Chrome. Chrome != Chromium - you just discovered one of the differences. robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2016-03-31 04:42 -0700 |
| Message-ID | <8e80fcc1-1e07-4deb-a012-7d40280c97af@googlegroups.com> |
| In reply to | #34051 |
On Wednesday, March 30, 2016 at 6:09:20 PM UTC-4, Robert Klemme wrote: > Chrome != Chromium - you just discovered one of the differences. Simple fix then. 1) Install Chrome. 2) Install Flash Player. https://en.wikipedia.org/wiki/Chromium_(web_browser) "Integrated PPAPI version of Adobe Flash Player.[10] This can be downloaded and installed separately in community supported distributions of Chromium."
[toc] | [prev] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2016-03-31 18:35 +0200 |
| Message-ID | <dm51ubF5iu0U1@mid.individual.net> |
| In reply to | #34052 |
On 31.03.2016 13:42, Eric Douglas wrote: > On Wednesday, March 30, 2016 at 6:09:20 PM UTC-4, Robert Klemme wrote: >> Chrome != Chromium - you just discovered one of the differences. > > Simple fix then. 1) Install Chrome. 2) Install Flash Player. > https://en.wikipedia.org/wiki/Chromium_(web_browser) > "Integrated PPAPI version of Adobe Flash Player.[10] This can be downloaded and installed separately in community supported distributions of Chromium." Eric, you are not getting the point: I don't want Flash in my browser. robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2016-03-31 11:21 -0700 |
| Message-ID | <33b335fe-aaae-45df-90cb-8230a0f46434@googlegroups.com> |
| In reply to | #34053 |
On Thursday, March 31, 2016 at 12:35:39 PM UTC-4, Robert Klemme wrote: > Eric, you are not getting the point: I don't want Flash in my browser. > > robert So you don't want to watch the video. What was your point? A lot of the internet has gone away from Flash but it's far from dead. My company's website used to be entirely Flash, now it's a lot of Javascript. Videos used to be all Flash, now ours are going mp4. I'm sure plenty of sites out there are still using Flash, so if you don't have Flash support we can help with that, but if you don't want Flash support don't complain. If you care enough to know what those videos are about, that's up to you to find a way to get them in a different format. Chromium does support the Flash player, so you're not pointing out a problem with a browser, just with you.
[toc] | [prev] | [next] | [standalone]
| From | Rhino <no_offline_contact@example.com> |
|---|---|
| Date | 2016-03-14 21:55 -0400 |
| Message-ID | <nc7pub$1f1$1@dont-email.me> |
| In reply to | #33959 |
On 3/14/2016 7:34 PM, Stefan Ram wrote: > Rhino <no_offline_contact@example.com> writes: >> I'd like to know what *all* my options[ are], not just .stream and .filter. > > docs.oracle.com/javase/8/docs/api > > Since anyone can write new pipeline operations, the options > are unlimited. But your options are not restricted to Java, > *all* options include the possibility that you might travel > to Japan and start to work as a fisher and cook there. > How would I write that in Java? ;-) >> I'm also curious to know what are all the things I can do on the last line. > > A terminal operation, such as forEach, produces a non-stream > result, such as a primitive value (like a double value), a > collection, or in the case of forEach, no value at all. > > For example: > > Intermediate: map > Intermediate: sorted > Terminal: forEach > Terminal: reduce > Terminal: collect > Terminal: collect with multi args > Terminal: collect with groupingBy > Terminal: count > groupingBy? Very very nice; that's exactly what I'm looking for. :-) >> I assume there is a reference manual somewhere that tells me all the >> things I can do with my collection using Lambdas but I'm not seeing any >> pointer to that manual in the Oracle material. > > docs.oracle.com/javase/tutorial/collections/streams/ > Excellent! I had trouble finding this in the API. Now I've got a chance to figure this out.... Thank you, Stefan! -- Rhino
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web