So currently I have this:
val a = obj.a // a is nullable type val b = obj.b // b is nullable type if (a != null && b != null) f(a, b) // f only takes non-null args
For a single property I can use a?.let { f(it) }
, and for two properties I could use do something similar with (a to b).takeIf { a != null && b != null }.let { ... }
(which isn’t any better than just using if
imo, especially since I still need to !!
the args in the let
).
Is there some idiomatic way of doing this in kotlin without if
?
submitted by /u/reallymakesyouthonk
[link] [comments]