You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 23, 2018. It is now read-only.
Can we get a switch matcher? It's a set of key-value pairs (aka a HashMap (but not necessarily)) that is much faster than alternations (O(1) vs O(n)).
First you need a pattern. This pattern will be used to lookup a pattern in the map. After matching the pattern, and looking up the result in the map, there are 2 possible outcomes:
The value is null, or the key doesn't exist.
Check for a default case, which is set by using setCase(null, pattern). This has 2 possible outcomes:
If there is no default case, the match fails.
If there is a default case, we attempt to match it.
The value is not null. Attempt to match it.
Constructing and using switch matchers could be done as in switch(pattern).setCase(string, pattern).setCase(string, pattern).setCase(null, pattern).
Removing cases could be done with setCase(string, null).