Skip to content

Commit

Permalink
[kotlin/en] Add small section for lambda functions (#4798)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-im-buggy authored May 14, 2024
1 parent 717d099 commit 23c81e3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kotlin.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down

0 comments on commit 23c81e3

Please sign in to comment.