What feels better/more idiomatic? ```val things = ...
# codingconventions
d
What feels better/more idiomatic?
Copy code
val things = getThings() orIfEmpty listOf(SingleThing())
or
Copy code
val things = getThings().letIfEmpty { listOf(SingleThing()) }
or does someone have a better solution?
I think the second one feels more idiomatic but the name is maybe wrong since it does not let you return anything you want like
let
generally would.
The first could even be
Copy code
val things = getThings() orIfEmpty { listOf(SingleThing()) }
instead
m
There’s already an
ifEmpty
function in stdlib.
Copy code
val things = getThings()
    .ifEmpty { listOf(SingleThing()) }
đź’Ą 3
d
Oh, I didn’t think it accepted a block 🤦
oh, it’s IF not IS
that’s why I didn’t see it
I was honestly wondering how this didn’t exist…
m
🙂
a
Urs isn’t is either
âž• 1