<Idiomatic way to assign value if not null> I want...
# stackoverflow
u
Idiomatic way to assign value if not null I want to archieve this: val foo = if (getNullableValue() != null) getNullableValue() else computeDefaultValue() What I don't like about it is the repetition of getNullableValue(). Trying to get rid of the repetion I came up with this: val foo = getNullableValue()?.also{}?: run { computeDefaultValue() } Not sure if that's considered idiomatic though. And the IDE warns about the empty body of also. Is there a better way to archive this?