Introduction
Lambdas let you write small pieces of code that you can pass around and use later, like a recipe you can share and follow anytime.
val lambdaName: (InputType) -> ReturnType = { parameter -> body }val greet: (String) -> Unit = { name -> println("Hello, $name!") }
val square: (Int) -> Int = { number -> number * number }
val printHello: () -> Unit = { println("Hello!") }
fun main() { val multiply: (Int, Int) -> Int = { a, b -> a * b } val result = multiply(4, 5) println("4 times 5 is $result") }
val multiply = { x: Int, y: Int -> x * y }
println(multiply(3, 4))val greet = { name String -> "Hello, $name" }Pass the test and this pattern moves unknown