Skip to content
This repository was archived by the owner on Feb 23, 2018. It is now read-only.
This repository was archived by the owner on Feb 23, 2018. It is now read-only.

Switch Matcher #15

@SoniEx2

Description

@SoniEx2

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).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions