lambda expression
A short anonymous function written inline and passed to other code, such as a condition for a filter.
In more detail
Lambdas let you hand behaviour, such as a filter condition, to a method without declaring a named function. Many languages write them with an arrow, such as x => x * 2 in C# or x -> x * 2 in Java.
Examples
Java: name -> name.startsWith("A"); a lambda implements a functional interface such as Predicate.() -> 6 * 7Related terms
- delegate — A type that holds a reference to a method, so a method can be stored in a variable and called later.
- predicate — A function or condition that answers true or false about a value, used to filter, search or check data.
- expression tree — A data structure that describes code, such as a lambda, as a tree of operations that another program can inspect and translate.
- LINQ — Language Integrated Query: a set of C# operators such as Where, Select and OrderBy for filtering, shaping and combining sequences of data.
- method reference — A compact way to pass an existing method as a function, written Type::method, such as String::toUpperCase or User::active.
- functional interface — An interface with exactly one abstract method, such as Runnable, Supplier or Predicate, which a lambda or method reference can implement.
- Stream API — The standard-library toolkit for describing a sequence of data-processing steps, such as filter, map and collect, over a source like a list.
Taught in
- Collections, Generics, and LINQ — Modern .NET Core, C# & Enterprise Microservices
- The ASP.NET Core Middleware Pipeline — Modern .NET Core, C# & Enterprise Microservices
- Querying, Change Tracking, and Saving Data — Modern .NET Core, C# & Enterprise Microservices
- The Streams API — Modern Java: Virtual Threads & High-Throughput Services
- Advanced Stream Operations — Modern Java: Virtual Threads & High-Throughput Services
- Concurrency Basics: Threads And Runnable — Modern Java: Virtual Threads & High-Throughput Services
- The ExecutorService — Modern Java: Virtual Threads & High-Throughput Services
- Lambdas, Functional Interfaces And Method References — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
References
- Lambda expressions
- Java Tutorials: Lambda Expressions
- dev.java: Lambda Expressions
- Java Language Specification, chapter 15: Expressions