Alexander Kuklev
08/12/2025, 11:32 PMval m = list.min().when { NoSuchElement -> 0 }
someExpression.when {
it < 0 -> Int.MIN_VALUE
it > 100 -> Int.MAX_VALUE
}.doOtherStuff()
Default else branch is obviously else -> it
. We propose only allowing the anonymous parameter `it`; if you need to name it, use the ordinary when.
Chained `when`’s seem to be the perfect fit for rich errors where the elvis operator :?
is no longer, but have great applications otherwise.joseph_ivie
08/13/2025, 3:07 PMwhen
looks too much like an extension function with a lambda and it's hard to distinguish. On the other hand, this is really clean.
Come to think of it, when
as it stands bugs me a bit for the same reason. if
and the other controls don't have the same problem because they already act really closely to a function with a lambda input, but when
magically treats its curly braces differently from both class declarations AND function bodies.JP Sugarbroad
08/13/2025, 5:45 PM