There are many querying operations on maps.
member :: Ord k => k -> Map k a -> Bool
yields True
if the key of type k
is in Map k a
:
> Map.member "Alex" $ Map.singleton "Alex" 31 True > Map.member "Jenny" $ Map.empty False
notMember
is similar:
> Map.notMember "Alex" $ Map.singleton "Alex" 31 False > Map.notMember "Jenny" $ Map.empty True
You can also use findWithDefault :: Ord k => a -> k -> Map k a -> a
to yield a default value if the key isn't present:
Map.findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x' Map.findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'