y
04/30/2025, 11:18 AMelse
case for single-expressions, for brevity/syntax-sugar? for example
if (something) {
do_thing()
} else when (somethingElse) {
A -> a()
B -> b()
C -> c()
}
Rob Elliot
04/30/2025, 11:29 AMwhen {
something -> do_thing()
else -> when (somethingElse) {
A -> a()
B -> b()
C -> c()
}
}
Youssef Shoaib [MOD]
04/30/2025, 11:29 AMRob Elliot
04/30/2025, 11:31 AMy
04/30/2025, 11:33 AMYoussef Shoaib [MOD]
04/30/2025, 11:34 AMwhen (somethingElse) {
else if something -> do_thing()
A -> a()
B -> b()
C -> c()
}
Of course, that executes somethingElse
unconditionallyy
04/30/2025, 11:34 AMwhen
guards?!y
04/30/2025, 11:35 AMYoussef Shoaib [MOD]
04/30/2025, 11:36 AMphldavies
04/30/2025, 11:37 AMYoussef Shoaib [MOD]
04/30/2025, 11:38 AMelse
because it would cause parser issues (because if (foo) x else y
vs if (foo)
makes it ambiguous)
To be frank, I didn't know about this and had been doing:
// Assuming somethingElse : T
when (somethingElse) {
is T if something -> do_thing()
A -> a()
B -> b()
C -> c()
}
y
04/30/2025, 11:42 AMy
04/30/2025, 11:42 AMy
04/30/2025, 11:44 AMwhen
-with-value syntax and the more-lenient but non-exhaustive when
-without-value syntax (edit: so this change is of course, welcome)y
04/30/2025, 11:46 AMelse
-first syntax is... jarringphldavies
04/30/2025, 12:07 PMy
04/30/2025, 12:13 PMy
04/30/2025, 12:14 PMwhen
expressions?Youssef Shoaib [MOD]
04/30/2025, 12:17 PMy
04/30/2025, 12:18 PMy
04/30/2025, 12:19 PMKlitos Kyriacou
04/30/2025, 12:42 PMif
statements is that if you have braces in the if
, put braces in the else
and vice versa.phldavies
04/30/2025, 1:03 PMelse if
is the same structure.y
05/01/2025, 4:45 AMy
05/01/2025, 4:47 AMy
05/01/2025, 4:50 AM