Created
April 23, 2020 12:34
-
-
Save sagarpatel288/4de84d7ab3fe6b0ab867b36b970ea06d to your computer and use it in GitHub Desktop.
Syntax of a lambda expression having single parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Normal function | |
fun increment (x: Int): Int { | |
return x + 1 | |
} | |
//The equivalent lambda expression for above function | |
val lambda: (Int): Int = { x -> x + 1 } | |
//The equivalent short lambda expression for above single parameter lambda | |
val lambda: (Int): Int = { it + 1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment