6.4.4 Structure matching

It is also possible to match against the fields of anonymous structures and instances:

var myStructure = {
  name: "haxe",
  rating: "awesome"
};
var value = switch (myStructure) {
    case {name: "haxe", rating: "poor"}:
      throw false;
    case {rating: "awesome", name: n}:
      n;
    case _:
      "no awesome language found";
  }
trace(value); // haxe

In the second case we bind the matched name field to identifier n if rating matches "awesome". Of course this structure could also be put into the Tree from the previous example to combine structure and enum matching.