reactormonk
10/21/2022, 12:53 PMwhen
statement?
Aka
when (Pair(x, y)) {
Pair(true, false) -> ...
}
rtsketo
10/21/2022, 1:08 PMwhen {
t && !f -> "."
!t && f -> ".."
else -> "..."
}
Something like that isn't ok?Youssef Shoaib [MOD]
10/21/2022, 1:13 PMenum class BoolPair {
FalseFalse
FalseTrue
TrueFalse
TrueTrue
}
infix fun Boolean.alongWith(other: Boolean) = when {
!this && !other -> FalseFalse
!this && other -> FalseTrue
this && !other -> TrueFalse
else -> TrueTrue
}
//Somewhere else
when(x alongWith y) {
TrueTrue -> doSomething()
...
//No need for else branch
}
Klitos Kyriacou
10/21/2022, 1:22 PMinfix fun Boolean.alongWith(other: Boolean) = BoolPair.values()[(if (this) 2 else 0) + (if (other) 1 else 0)]
reactormonk
10/22/2022, 7:23 AMwhen (x to y) {
true to false -> ...
}
reactormonk
10/22/2022, 7:24 AM