haxe Pattern matching


Pattern matching is the process of branching depending on provided patterns. All pattern matching is done within a switch expression, and individual case expressions represent the patterns.

The fundamental rules of pattern matching are:

  • patterns will always be matched from top to bottom;
  • the topmost pattern that matches the input value has its expression executed;
  • a _ pattern matches anything, so case _: is equal to default:.

When all possible cases are handled, the catch-all _ pattern or default case is not required.