Normal vs Lambda expression or Highorder function
Lambda definition:
Kotlin has concise (short) syntax for defining lambda functions, which makes it easier to work with functional programming constructs.
Lambda Expression syntax in Kotlin:
{ argument -> businessloginwith_return }
{ a, b -> a+b }
Lambda
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
fun main(args: Array<String>) { | |
/* Normal function | |
vs | |
lambda expression | |
syntax: { a, b -> a+b } | |
*/ | |
/** Normal function **/ | |
println(add(4,5)) | |
/** Lambda function **/ | |
val ldadd = { a:Int, b:Int -> | |
a+b | |
} | |
println(ldadd(3,4)) | |
} | |
//Normal function | |
fun add(a:Int, b: Int): Int | |
{ | |
return a+b | |
} |
Comments
Post a Comment