mzgreen
06/18/2021, 6:25 AMval list = listOf(1,2,3,4,5)
when (list) {
all { it < 10 } -> foo()
any { it % 2 == 0 } -> bar()
else -> baz()
}
but it doesn't seem to be possible and I'm not sure why.Tobias Suchalla
06/18/2021, 6:38 AMwhen(result) {
is Success -> println("yeah!")
else -> println("oh no!")
}
You can however use when without an argument:
when {
list.all { it < 10 } -> foo()
list.any { it % 2 == 0 } -> bar()
else -> baz()
}
(I hope I got the terminology somewhat right 😬)Vadim Kapustin
06/18/2021, 7:15 AMwith(list) {
var noMatch = true
if (all { it < 10 }) {
foo()
noMatch = false
}
if (any { it % 2 == 0 }) {
bar()
noMatch = false
}
if (noMatch) baz()
}
mzgreen
06/18/2021, 7:42 AMRuckus
06/18/2021, 1:39 PMwhen
. See this one for example (as well as its related isssues): https://youtrack.jetbrains.com/issue/KT-28359