https://kotlinlang.org logo
Title
k

karelpeeters

12/04/2017, 10:45 PM
For you specific use case:
if (str.isNullOrBlank()) "other" else str
s

spragg

12/04/2017, 11:51 PM
expanding on this. You can directly assign the result of an if.
val someVariable = if (str.isNullOrBlank()) "other" else str
m

madorb

12/05/2017, 12:03 AM
sure, yes i understand that can be done, but let’s say you want to perform some operation on the result. and chain it. you know, to make up for the lack of an optional type
to use a contrived example
foo.ifNullOrBlank(someOtherString).contains(…)
s

spragg

12/05/2017, 2:13 AM
In the same way if can be assigned directly. You can wrap it in brackets and use the results
(if(str.isNullOrBlank()) "other" else str).contains("t")