Maybe +containers

mapMaybe :: (a -> Maybe b) -> IntMap a -> IntMap b
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(n). Map values and collect the Just results. > let f x = if x == "a" then Just "new a" else Nothing > mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
mapMaybe :: (a -> Maybe b) -> Map k a -> Map k b
containers Data.Map.Lazy, containers Data.Map.Strict
O(n). Map values and collect the Just results. > let f x = if x == "a" then Just "new a" else Nothing > mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
mapMaybeWithKey :: (Key -> a -> Maybe b) -> IntMap a -> IntMap b
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(n). Map keys/values and collect the Just results. > let f k _ = if k < 5 then Just ("key (:) " ++ (show k)) else Nothing > mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key (:) 3"
mapMaybeWithKey :: (k -> a -> Maybe b) -> Map k a -> Map k b
containers Data.Map.Lazy, containers Data.Map.Strict
O(n). Map keys/values and collect the Just results. > let f k _ = if k < 5 then Just ("key (:) " ++ (show k)) else Nothing > mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key (:) 3"