This Week I Learned: Kotlin’s when is neat [2022–02–28]
Jan 28, 2022
I’m learning Kotlin, and I the when expression syntax strikes me as really neat. It reads fluently, it’s compact and reveals complexity gracefully.
Some points that I find especially pleasing:
- the
->
feels like the nicest syntaxes of functional programming - the
else
is optional if the conditions exhaustively test all values - my IDE complains if I omit the
else
and I haven’t tested all values, and otherwise let’s me omit it - multiple values can be grouped together by putting commas between them
in
andis
read especially fluently (when foo in bah…)