reactormonk
when
when (Pair(x, y)) { Pair(true, false) -> ... }
rtsketo
when { t && !f -> "." !t && f -> ".." else -> "..." }
Youssef Shoaib [MOD]
enum 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
infix fun Boolean.alongWith(other: Boolean) = BoolPair.values()[(if (this) 2 else 0) + (if (other) 1 else 0)]
when (x to y) { true to false -> ... }
A modern programming language that makes developers happier.