From 23c81e3b65e01a73d677bd10a01b6781700b43f9 Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam Date: Wed, 15 May 2024 05:27:09 +0530 Subject: [PATCH] [kotlin/en] Add small section for lambda functions (#4798) --- kotlin.html.markdown | 7 +++++++ 1 file changed, 7 insertions(+) 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)}