what do you think about ``` infix fun <T : Any...
# announcements
t
what do you think about
Copy code
infix fun <T : Any?> T.`if`(condition: Boolean): Pair<Boolean, T> =
    Pair(condition, this)

infix fun <T> Pair<Boolean, T>.`else`(block: () -> T) =
    if (component1()) component2()
    else block()
p
Do you want to achieve something like that?
Copy code
value.takeIf { it >= 0 } ?: defaultValue
t
no i thought about a slightly more readable version of
return if (condition) foo else bar
and put the
foo
in front of
if
so with the two methods i could write
Copy code
return foo `if` (condition) `else` bar
the really annoying part are the backticks of course 😉
p
Why do you think it is more readable than
return if (condition) foo else bar
?
t
because it's close to human language
2
🤷‍♂️ 1
k
I've always found this to be annoying in python, the condition is between the values making it hard to compare them.