2 ms·
Kotlin does have trailing closures: https://kotlinlang.org/docs/reference/lambdas.html#higher-order-functions https://kotlinlang.org/docs/reference/lambdas.html
by cel1ne 10y ago
Kotlin does have trailing closures: https://kotlinlang.org/docs/reference/lambdas.html#higher-order-functions https://kotlinlang.org/docs/reference/lambdas.html#higher-or...
And some form of pattern matching via the "when" keyword: https://kotlinlang.org/docs/reference/control-flow.html#when-expression https://kotlinlang.org/docs/reference/control-flow.html#when...
- nostrademons 10y agoIt's a bit different in Swift. Kotlin lets you omit the parentheses if the closure is the only argument to the function. Swift lefts you place the lambda outside of the parentheses if the closure is the last argument to the function. That lets you construct a much larger variety of control-structure-like HOFs. Event handlers, for example, often take a functional argument plus a bunch of other data.
- cel1ne 10y agoNo, it's the same in Kotlin, from the docs: "There is a convention that if the last parameter to a function is a function, that parameter can be specified outside of the parentheses." So you can have normal arguments and specify the last parameter outside like. val col = "A" val row = 3 table.update(col, row) { it * 5 } You may have confused that with SAM-conversions (?), which are for java-interop: https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions https://kotlinlang.org/docs/reference/java-interop.html#sam-...
- nostrademons 10y agoCool. Learn something new every day. (I was confused because all the examples except for lock() are single-arg, and IntelliJ usually autocompletes with parentheses because there's often a non-functional overload.)