https://kotlinlang.org logo
s

spicyspiders

08/03/2020, 8:52 AM
What am I doing wrong here, is it not possible to use ternery inside Triple?
Copy code
return Triple((adults > 0 ? adults : null), (children > 0 ? children : null), (infants > 0 ? infants : null))
d

diesieben07

08/03/2020, 8:53 AM
Kotlin does not have the "ternary operator". Use an if expression instead:
Triple(if adults > 0 adults else null, ...
In this case you might also use
takeIf
for more readability:
Triple(adults.takeIf { it > 0 }, ...
❤️ 2
👍 2
s

spicyspiders

08/03/2020, 8:56 AM
Thanks, takeIf is definitely better.