This message was deleted.
# announcements
s
This message was deleted.
n
You mean I guess, why is the lambda in
{}
outside of the parentheses of the call to
someFunction
?
@samuel well, someFunction is just a function that accepts another function, right
it accepts that function, and having done that, it can do what it wants with the passed function (
action
) including call it
So, it calls it 🙂
c
It’s a lambda function. The Kotlin syntax is not so common, but the concept exists in pretty much all modern programming languages. The documentation here goes into all the nitty-gritty details https://kotlinlang.org/docs/lambdas.html
👍 1
n
Just to clarify, only the
{ }
part is the lambda function. Your follow up made it seem like you were more trying to understand
someFunction
itself, which doesn't involve any lambdas.
c
Right, my bad.
someFunction
is a “higher-order function”, since it operates on a “lambda”
n
You may want to start with this example:
Copy code
fun myAction(x: Int, y: Float): Unit {
       println("first param = $x, second param = $y")
}

fun someFunction(
    someParam: Int,
    action: (someOtherParam: Int, lastParam: Float) -> Unit
) {
    action(0, 9f)
}

fun main() {
       someFunction(2, ::myAction)
}
🙏 1
here you only need to learn/know about higher order functions
once this example makes sense, you can also learn lambdas
np