Pattern matching is the process of branching depending on a value matching given, possibly deep patterns. In Haxe, pattern matching is primarily done within switch expressions where the individual case expressions represent the patterns. Here we will explore the syntax for different patterns using this data structure as running example:
enum Tree<T> { Leaf(v:T); Node(l:Tree<T>, r:Tree<T>); }
Some pattern matcher basics include:
_ pattern matches anything, so case _: is equal to default:.