|
|
|
|
|
by RedNifre
1739 days ago
|
|
No, the idea is that {} denotes executable blocks, which lamdas are. In Kotlin, if the last parameter of a function is a lambda, you can close the parenthesis before the lambda: f(5, { square(it) }
can be written as f(5) { square(it) }
which makes constructs like if(condition) { foo() }
Look like if(condition, { foo() } )
as in a function that takes a boolean and a lambda and only executes the lambda if the boolean is true.It's a neat reinterpretation of what {} means. |
|
I’m not opposed to using some smarts to infer/simplify the expression when possible. I.e. if it’s a closure with inferable parameter and return types the “it” construct could be used (in swift they use $0, $1, $2 etc for unnamed parameters). Just the only thing inside an executable block {} should be code that gets executed - not type information about that block