How would you go with matching `Add(left, Const(0)...
# random
m
How would you go with matching
Add(left, Const(0))
to simplify it to
left
?
e
when { e is Add && e.right == Const(0) -> .... }
m
Boilerplate? 🙂
e
Yes
Pattern match is better for some type of code, but most of the time it is used just to match by type and that is what Kotlin’s
when
is better suited for.
with pattern match get yet another way to express your conditions (in addition to
if
and regular comparisons). These implicit comparisons do hurt redability.
m
That's very true and Kotlin being pragmatic lang I have a feeling you will not decide to implement matching.
For these rare uses when it makes it much cleaner to use PM.