4 ms·
I started looking at Kotlin docs [1]. For higher order functions support, fun lock(lock: Lock, body: () -> T): T { } Is there any technical reasons why norma
by crudbug 11y ago
I started looking at Kotlin docs [1]. For higher order functions support,
fun lock(lock: Lock, body: () -> T): T {
}
Is there any technical reasons why normal function declarations are not using '->' as a return operator ?
fun hello(name: String) -> String {
println(name)
}
Swift [2], Rust & others are using it.
It will just make the experience uniform with consistent Functional Types
[1] https://kotlinlang.org/docs/reference/lambdas.html https://kotlinlang.org/docs/reference/lambdas.html
[2] http://fuckingswiftblocksyntax.com http://fuckingswiftblocksyntax.com
- lmm 11y ago: T is consistent with values, it's the way of saying a thing has a type. It makes for much more consistency when refactoring a function, and (at least in Scala) supports the Uniform Access Principle style. def lock(...): T = ... val lockResult = lock(...): T In Scala at least "=> T" is the syntax for a lazy T (i.e. a function of no arguments that returns T), and so your "hello" reads like a function that returns a lazy String.