mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
[kotlin/en] Add small section for lambda functions (#4798)
This commit is contained in:
parent
717d099842
commit
23c81e3b65
@ -120,6 +120,13 @@ fun helloWorld(val name : String) {
|
|||||||
println(even(6)) // => true
|
println(even(6)) // => true
|
||||||
println(even(7)) // => false
|
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.
|
// Functions can take functions as arguments and return functions.
|
||||||
fun not(f: (Int) -> Boolean): (Int) -> Boolean {
|
fun not(f: (Int) -> Boolean): (Int) -> Boolean {
|
||||||
return {n -> !f.invoke(n)}
|
return {n -> !f.invoke(n)}
|
||||||
|
Loading…
Reference in New Issue
Block a user