(no title)
dima_vm | 3 years ago
1. Lambda functions can be defined with `{}`.
2.`foo(bar, somefunc)` is the same as `foo(bar) somefunc`. In other words, if the last parameter is a function, it can be provided AFTER closing parenthesis.
3. Interfaces that require only one method can be implemented on-side with a lambda function (i.e. `{}` syntax for no-param function).
Combined those three features, the code may look like that:
routing {
static("/statics") {
files("css")
}
get("/foo") {
call.respondText("Hello world!")
}
}
So you can make a config-looking file which is just pure Kotlin, with static type checking, autocomplete, suggestions, "this" etc.It's so damned, I'm surprised author didn't mention it.
plucas|3 years ago
sirsinsalot|3 years ago
brabel|3 years ago
brabel|3 years ago
pas|3 years ago
zorr|3 years ago
still_grokking|3 years ago
Kotlin's scope injection is one of the most terrible "features" ever invented. It's dynamic scoping on steroids!
But dynamic scoping was long ago deemed a horrible bug and never ever made it again into any new language.
still_grokking|3 years ago
Directly "stolen" form Scala.
> 2.foo(bar, somefunc) is the same as foo(bar) somefunc. In other words, if the last parameter is a function, it can be provided AFTER closing parenthesis.
Just a irregular syntax quirk that tries to get around the fact that Kotlin does not support multiple parameter lists, like the language where most Kotlin features come form, Scala.
> 3. Interfaces that require only one method can be implemented on-side with a lambda function (i.e. {} syntax for no-param function).
That doesn't have anything to do with Kotlin. That's Javas SAM (Single Abstract Method) feature.
> I'm surprised author didn't mention it.
The author seems not to know any Scala. Otherwise the lists would show mostly only Scala features… ;-)