Ie. something like `String.{ trim() }` so it would...
# announcements
s
Ie. something like
String.{ trim() }
so it would have the type
String.() -> String
r
val test: String.() -> Unit = { trim() }
And if you're not using the lambda in an assignment it's probably in a function call, where type inference should make the explicit declaration unnecessary.
s
My usecase is something like this
Copy code
val foo : String.() -> Unit = when(false){
                        true -> {}
                        false -> {}
                    }
and it fails to infer
l
You are not returning your function there
Copy code
val foo : String.() -> Unit = when(false){
    true -> { {} }
    false -> { {} }
}
👍 1
m
Copy code
val foo = when (false) {
    true -> fun String.() {}
    false -> fun String.() {}
}
r
@lupajz Is right, in your example the braces are treated as block delimiters for the when-branch, not as lambdas.
l
It would be really cool if this worked sometime in future. I would love not have to write 2 sets of braces 😕
r
@lupajz You could do it this way:
Copy code
val foo : String.() -> Unit = when(false){
    true -> { -> }
    false -> { -> }
}
Same amount of characters to type, but at least it's a bit easier to read imo.
👍🏻 1
l
@robin that’s nice! never used that thanks
r
Me neither, but your comment made me wonder whether the arrow notation works even with no parameters, turns out it does 😄
s
Lovely. Thanks for the replies !