Junilu Lacar wrote:If you're really having trouble making the distinction between function vs. method, then just think of "function" as something that you can call to do something for you, including give back the result of whatever that something is. In other words, it's just another logical chunk of work/code that you can treat as a separate entity.
Junilu Lacar wrote: the "function" in "higher order function" is in the mathematical sense.
Junilu Lacar wrote:Again, you're mixing contexts. Stop doing that. You're just confusing yourself when there's really no need to be confused.
Your definition of function is not correct. Math.sqrt() is a method, right? Well, guess what: it's also a function.
Monica Shiralkar wrote:Thanks, sure. Now I have started calling Map, Reduce, Filter and other higher order functions as Functions (instead of Methods which I was earlier calling).
Junilu Lacar wrote: If I was talking about map, reduce, and filter in a more general mathematics or functional programming sense, I might prefer to call them "functions" instead..
Monica Shiralkar wrote:... is not function which does not belong to any class or object and we are passing it to higher order function?
Monica Shiralkar wrote:So is not involving functional programming
Junilu Lacar wrote:so technically it does belong to an object.
Mike Simmons wrote:it's a good idea to try to remember what group you're talking with and be somewhat consistent in terminology.
Monica Shiralkar wrote:lambda function
Stephan van Hulst wrote: a function that takes another function does not take a "lambda".
Monica Shiralkar wrote:But isn't map(a function that takes another function), not taking a lambda in
A lambda expression creates a function.
Stephan van Hulst wrote: a function that takes another function does not take a "lambda".
Stephan van Hulst wrote:
A higher order function doesn't take a "lambda". It takes a reference to a function. Whether that function was originally expressed using a lambda expression or a method or indeed a prose description like the one I wrote above is inconsequential.
Liutauras Vilda wrote:
That's exactly, right? Lambda expression creates a function which is passed on as an argument. And that is all here.
Stephan van Hulst wrote:No. Where did I say that a lambda expression is a reference to a function?
You can express a word using letters on paper, but you can also express a word using sounds from your larynx. "Word" is an abstract concept.
The same is true for a function. It's an abstract concept. You can express a function using a method definition, but you can also express it using a lambda expression.A higher order function takes a reference to a function.
A lambda expression returns a reference to the function that it expresses
Stephan van Hulst wrote:Yes, a lambda expression gets converted to a function and a reference to that function is returned. This does not mean that the lambda expression IS a function.
It's like the expression "2 + 3". It gets converted to the integer value 5 by the compiler, but the expression "2 + 3" is not the value 5 itself. It's just a piece of text in a source file.
Stephan van Hulst wrote:Yes, a lambda expression gets converted to a function and a reference to that function is returned. This does not mean that the lambda expression IS a function.
Monica Shiralkar wrote:Yes. In that case why is it wrong when I say that "We can pass lambda expression to a higher order function and this lambda internally gets converted to a function".? (I am not saying that "one can pass a function").
Junilu Lacar wrote:
In the above example, doBar(), doFoo(), getFoo(), and getBar() are higher-order functions (even though technically in Java, they are called methods).
Monica Shiralkar wrote:
In that case the below should be correct . Is it?
Lambda expression means an expression which can be referred by an object of the type functional interface.
And, a Java method which can take a Lambda expression as an argument will be instead called a Function and not method (more specifically, a higher order function). (Also, a java method which returns a Function is also called a Higher order function ).
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |