[kotlin/en] Add small section for lambda functions (#4798)

This commit is contained in:
Pratyaksh Gautam 2024-05-15 05:27:09 +05:30 committed by GitHub
parent 717d099842
commit 23c81e3b65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -120,6 +120,13 @@ fun helloWorld(val name : String) {
println(even(6)) // => true
println(even(7)) // => false
/*
You can also use lambda functions, with the '->' operator seperating
the parameters from the function body.
*/
fun fooLambda: (Int) -> Int = {n -> n + 1}
println(fooLambda(1)) // => 2
// Functions can take functions as arguments and return functions.
fun not(f: (Int) -> Boolean): (Int) -> Boolean {
return {n -> !f.invoke(n)}