https://kotlinlang.org logo
#random
Title
# random
m

mg6maciej

04/20/2017, 2:12 PM
How would you go with matching
Add(left, Const(0))
to simplify it to
left
?
e

elizarov

04/20/2017, 2:13 PM
when { e is Add && e.right == Const(0) -> .... }
m

mg6maciej

04/20/2017, 2:14 PM
Boilerplate? 🙂
e

elizarov

04/20/2017, 2:14 PM
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

mg6maciej

04/20/2017, 2:19 PM
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.