I would like to have a block after elvis ``` val ...
# announcements
s
I would like to have a block after elvis
Copy code
val bar = foo ?: {
    println("foo is null!")
    return // return for block? return for what??? I don't know.
}
Is there any discussion about this? or no one interested having this feature? I know Kotlin can do this but still I want to have a block after elvis.
Copy code
val bar = foo ?: return println("foo is null!")
val bar2 = foo2 ?: return someReturnUnitMethod()
d
shiraji: You can use
run
for an ad-hoc block:
Copy code
val bar = foo ?: run {
    // do stuff here
    valueToUseForBar // last expression in a lambda is the value of that lambda 
}
s
Interesting. I haven’t come up with using
run
z
Also
?: {doStuff()}.invoke()
or
?: {doStuff()}()
đź‘Ť 1
I also wandered why is
run
called
run
.