Say I have an operation that may return a list of things or a null (interop with a library). What would be idomatic in kotlin to do something if the result is null or do another thing (map) if the result is not null (and contains elements). I'm thinking "either-or", as in either do a "default" operation if the result is null or the "or" operation if the result is not null and the list contains elements?
d
diesieben07
08/06/2019, 8:12 AM
Without knowing more details, I think you are looking for the
?:
operator:
val result = libraryMethod()?.doStuff() ?: defaultValue()