Open
Description
Currently the specification for patterns states that a map that does not contain a key will not match. Unfortunately this means that patterns aren't able to be used to destructure JSON with optional fields.
Say we have the following schema: {"type": "location", "latlon": [number, number], "name": string?, "visits": int (defaults to 0 if unspecified)}
Matching this is not possible due to the optional fields:
json = {"type": "location", "latlon": [123.4, -56.78]};
return switch (json) {
case {"type": "location", "latlon": [lat as num, lon as num], "name": name as String?, "visits": visits as int?} => ...
};
Perhaps a ?
suffix could be used on the map key to indicate that it should be optional?