currencyInfo = currencyInfo ?: run {
val assetData =
JsonParser.getJsonDataFromAsset(context, "country_currency.json").orEmpty()
Gson().fromJson(assetData, CurrencyInfoResponse::class.java)
}
✅ 1
➕ 1
g
gildor
01/21/2022, 7:28 AM
In our code base we do not use run for this, imo if/else is more readable and explicit
j
Joffrey
01/21/2022, 8:25 AM
IMO it's better to extract that code to a function, and use Elvis.
But using the variable itself in the RHS is a smell IMO, I'd rather initialize it with the correct value and make it val (using Elvis, if, or when expression), or use a different name for the assigned variable
☝️ 4
✅ 1
v
Vlad Krava
01/21/2022, 1:10 PM
it looks more like Java style to me.
Agree with @Joffrey, Elvis operator will fit here much better: