Re:Show HN: Javalin, a Java/Kotlin REST API Framework
by swsieber on Sunday May 28, 2017 @04:11PM
(#14435895)
Is "with" a keyword, or is it just convention - I haven't been able to find it documented anywhere. It seems like it's just doing a function with receiver under the hood.
[ Parent
| on HN ]
Re:Show HN: Javalin, a Java/Kotlin REST API Framework
by ptx on Sunday May 28, 2017 @04:16PM
(#14435910)
It's an ordinary function: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/with.htm...
Re:Show HN: Javalin, a Java/Kotlin REST API Framework
by swsieber on Sunday May 28, 2017 @05:51PM
(#14436229)
Thank you - searching for the word with was unfruitful for me.
Re:Show HN: Javalin, a Java/Kotlin REST API Framework
by pdpi on Sunday May 28, 2017 @06:30PM
(#14436378)
This is a recurring theme with Kotlin: inline receiver functions with a lambda parameter are an amazingly versatile tool for building functions that implement what would be a language feature/syntactic sugar in other languages. `with` here is a good example, but `let` and `use` are other good examples of this in play (`use` gives you try-with-resource, let plays nicely with the ?. safe navigation operator to execute code on non-null objects `maybeNullObject?.let { doStuffWith(it) }`)