January 2018
Intermediate to advanced
434 pages
14h 1m
English
In the following steps, we will learn about anonymous functions with the help of some examples:
fun main(args: Array<String>) { val funcMultiply = {a:Int, b:Int -> a*b} println(funcMultiply(4,3)) val funcSayHi = {name: String -> println("Hi $name")} funcSayHi("John")}
In the preceding code block, we have declared two lambdas: one (funcMultiply) that takes two integers and returns an integer, and another (funcSayHi) lambda that takes a string and returns a unit—that is, it returns nothing.
Read now
Unlock full access