Skip to content

Instantly share code, notes, and snippets.

@ruwanka
Created March 11, 2018 14:21
Show Gist options
  • Save ruwanka/8976b10304daadcef811d83e6c91a3b5 to your computer and use it in GitHub Desktop.
Save ruwanka/8976b10304daadcef811d83e6c91a3b5 to your computer and use it in GitHub Desktop.
Kotlin Anonymous function
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