Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33961

Re: Lambda reference?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Lambda reference?
Date 2016-03-14 17:16 -0400
Organization A noiseless patient Spider
Message-ID <nc79gr$9e6$1@dont-email.me> (permalink)
References <nc770d$u97$1@dont-email.me>

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web