Added a new function, filterMapByKey, to the Utils module

This commit is contained in:
Neil Brown 2009-02-05 15:52:43 +00:00
parent 2ecd91e36f
commit 56a10b403f

View File

@ -346,6 +346,9 @@ mapMapWithKeyM f m = liftM Map.fromAscList $ mapM f' $ Map.toAscList m
f' (x,y) = do y' <- f x y
return (x, y')
filterMapByKey :: Ord k => (k -> Bool) -> Map.Map k v -> Map.Map k v
filterMapByKey f = Map.filterWithKey (\k _ -> f k)
-- | Transforms an Either into a Maybe. If it's a Left value, it is transformed
-- into Nothing. If it is a Right value, it is transformed into Just.
eitherToMaybe :: Either a b -> Maybe b