What is a lambda expression?

What is a lambda expression?

A concept derived from a functional language. A functional language is a language that "treats a function like a value".

A "value" is a number, a string, or a list. To be able to treat it like a value

--Can be assigned to a variable --Pass it as a function argument --Can be the return value of a function

That is.

For example, a function that takes a value as an argument, adds 10 to it, and returns it.

F(x) = x + 10

Functions like. In functional languages, this function can be handled as a value.

So how do you assign the above function to a variable? This "how to write a function that can be handled as a value" is a lambda expression.

For example, in the functional language Haskell, the above function

 f = x -> x + 10

It can be described like this.

Think of it as "[a function that receives the number x and returns the value obtained by adding 10] to a variable called f."

This writing style varies from language to language, but they are all lambda expressions. All of them define "how to write a function that can be handled as a value". It doesn't matter if there is a small difference in writing style such as-> or =>.

So far, it's a lambda expression, but the situation is a little different in Java and C #.

Because these are classes-based languages, functions can only exist in classes, that is, in the form of methods.

So, I made a function (Func in C #) interface so that it can be handled as a pseudo function.

For example in Java

Function<Integer, Integer>f = new Funciton<>(){
    public Integer apply(Integer x){
        return x + 10;
    }
}

It's just an abbreviation for.

Since it is just an instance, it can be assigned to a variable, and it can be used as both an argument and a return destination.

The above is the explanation of the lambda expression.

―― "What is a lambda expression in the first place?" ―― "How to incorporate a lambda expression (a concept derived from a functional language) into an object-oriented language?"

If you get confused, you won't be able to tell the difference at once, so it's better to think of these two separately.

Recommended Posts

What is a lambda expression?
What is a lambda expression (Java)
What is a constructor?
What is a stream
What is a Servlet?
What is a wrapper class?
What is a boolean type?
What is a Ruby module?
What is a floating point?
What is a meaningful comment?
What is a Java collection?
What is a fa⁉ enum?
What is a snippet in programming?
What is a column Boolean type?
What is a reference type variable?
[Swift] What is "inheriting a class"?
What is a Ruby 2D array?
What is Cubby
What is Docker?
What is a class in Java language (3 /?)
What is a terminal? -Absolute path & relative path-
What is a Spring Boot .original file?
What is java
What is maven?
What is Jackson?
[For programming beginners] What is a method?
What is Docker
What is self
What is Jenkins
What is ArgumentMatcher?
What is IM-Juggling?
What is a class in Java language (1 /?)
What is params
What is SLF4J?
What is a class in Java language (2 /?)
What is Facade? ??
What is Java <>?
What is Gradle?
What is POJO
What is Java
What is centOS
[Java] Lambda expression
What is RubyGem?
[Rails] What is a dot (.) Or a colon (:)?
What is programming?
What is before_action?
What is Docker
What is a request scope? Image commentary
What is Byte?
Java lambda expression
What is Tomcat
Transform from a normal class to a lambda expression
Which is faster, method reference or lambda expression
What is Maven Assembly?
What is `docker-compose up`?
What is vue cli
What is an interface?
java neutral lambda expression 1
What is Ruby's self?
What is hard coding?
Java lambda expression variations