Karlo Lozovina
02/03/2022, 4:21 PMCasey Brooks
02/03/2022, 4:30 PMval allSame = listOf(a, b, c, d).distinct().size == 1
// or
val allSame = listOf(a, b, c, d).zipWithNext().all { (first, second) -> first == second }
Otherwise, you'd have to chain the individual checks in some way (a == b && b == c
etc.)Karlo Lozovina
02/03/2022, 4:33 PMdmitriy.novozhilov
02/03/2022, 6:36 PMsetOf(a, b, c, d).size == 1
jwass
02/03/2022, 8:23 PMa
and you want to check that b
, c
and d
are equal to it, then I see no problem with (a == b && a == c && a == d)
. It’s clear what it means, maintainable (you can remove any check without having to stitch back the chain). It’s also most efficient to execute because of short-circuiting, though that probably doesn’t matter so much in this case.Jacob
02/03/2022, 9:41 PMsequenceOf(b, c, d).all{it == a}