Is there any simpler way to write it: ```if (y) x....
# announcements
y
Is there any simpler way to write it:
Copy code
if (y) x.getSomething() else null
Note that
x.getSomething().takeIf { y }
isn't identical, because it always calculate
x.getSomething()
.
🚫 2
t
note: just because its /shorter/ that doesnt mean it's better or simpler or easier to understand. i think there is absolutly nothing wrong with writing the full if/else even if there were a shorter version
☝️ 2
w
x.takeIf { y }?.getSomething()
🤣 But agree with @thana 👍
s
is this simpler??
Copy code
x::getSomething.takeIf{y}?.let{it()}
damn it, William’s is simpler 😆
k
William's is technically not equivalent, it evaluates
x
twice.