Map Patterns
Map Patterns
We can also pattern match on Maps, and this is very similar to Records, except for some syntax changes. For example, getID let us get the ID of Wang from a map where we have to have at least Wang, Thomas and Leeming as keys.
getID :: Map String Integer -> Maybe Integer
getID #{ "Wang":= x, "Thomas" := y, "Leeming" := z } = Just x
getID _ = Nothing
> getID #{"Wang" => 10, "Thomas" => 20 , "Leeming" => 30 }
{'Just',10}
