Created
March 11, 2018 14:21
-
-
Save ruwanka/8976b10304daadcef811d83e6c91a3b5 to your computer and use it in GitHub Desktop.
Kotlin Anonymous function
This file contains hidden or 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>) { | |
// lambda | |
println(apply(5, { it * it })) | |
// anonymous function | |
println(apply(5, fun(n: Int): Int { return n * n})) | |
} | |
fun apply(num: Int, op: (Int) -> Int): Int { | |
return op(num) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment