Open In App

Lambda Expression in Scala

Lambda Expression refers to an expression that uses an anonymous function instead of variable or value. Lambda expressions are more convenient when we have a simple function to be used in one place. These expressions are faster and more expressive than defining a whole function. We can make our lambda expressions reusable for any kind of transformations. It can iterate over a collection of objects and perform some kind of transformation to them.
Syntax:

val lambda_exp = (variable:Type) => Transformation_Expression

Example:



// lambda expression to find double of x
val ex = (x:Int) => x + x
Working With Lambda Expressions

Article Tags :