4 ms·
Another advantage of pattern matching is extensibility. Suppose you wish to add a new branch case. Under the traditional if/else (or switch) model, you'd need
by timmytokyo 10y ago
Another advantage of pattern matching is extensibility.
Suppose you wish to add a new branch case. Under the traditional if/else (or switch) model, you'd need to modify the function containing the if statements. With pattern matching, you simply introduce a new function; it decentralizes the change and acts as a sort of simple, intuitive polymorphism.