summaryrefslogtreecommitdiffhomepage
path: root/kotlin.html.markdown
diff options
context:
space:
mode:
authorPratyaksh Gautam <pratyakshgautam11@gmail.com>2024-05-15 05:27:09 +0530
committerGitHub <noreply@github.com>2024-05-14 17:57:09 -0600
commit23c81e3b65e01a73d677bd10a01b6781700b43f9 (patch)
tree6e80b02ab73960f6cff68062c98cc5abb64a43a7 /kotlin.html.markdown
parent717d099842a4b133c12cfa32636634766f6bc197 (diff)
[kotlin/en] Add small section for lambda functions (#4798)
Diffstat (limited to 'kotlin.html.markdown')
-rw-r--r--kotlin.html.markdown7
1 files changed, 7 insertions, 0 deletions
diff --git a/kotlin.html.markdown b/kotlin.html.markdown
index 48abce3a..c16b5db1 100644
--- a/kotlin.html.markdown
+++ b/kotlin.html.markdown
@@ -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)}