__construct(public int $x, public int $y, public int $z) {} } $result = match ($p) is { // These will match only some Point objects, depending on their property values. Point{x: 3, y: 9, %$z} => "x is 3, y is 9, z is $z", Point{%$z, %$x, y: 4} => "x is $x, y is 4, z is $z", Point{x: 5, %$y} => "x is 5, y is $y, and z doesn't matter", // This will match any Point object. Point{%$x, %$y, %$z} => "x is $x, y is $y, z is $z", };
Item(Product product, int amount) {} var cart = List.of( new Item(new Product("餃子", new Packed(300)), 3), new Item(new Product("牛肉", new Bulk(250, 100)), 230));