Hello, I am trying to return a lambda with a recei...
# announcements
m
Hello, I am trying to return a lambda with a receiver from a
when
statement, but it doesn't seem to work, the receiver does not register. How can I make this work?
I was assuming the compiler would infer the type of the lambda based on the specified variable type. But it does not.
n
try adding more `{}`s
1
☝🏼 1
☝️ 3
o
Max meant adding another layer of curly braces around the cases of your when expression.
m
Ohh, I see. Makes sense in retrospect. Thank you.
n
sorry I had a surprise call
yeah --
foo -> { println("") }
usually means "execute this multiline block", not "I'm returning a lambda" 🙂
r
I think
-> ({ copy(a = true) })
would make it more clear that you return a lambda as a value than double braces
n
ah, hadn't thought of that. good point Gael
f
So would wrapping your assignment expression in ( ) make it an expression within a higher order function!?
Please pardon my ignorance brand new to kotlin
r
Assignments are not expressions in Kotlin.