insertLookupWithKey +containers

insertLookupWithKey :: (Key -> a -> a -> a) -> Key -> a -> IntMap a -> (Maybe a, IntMap a)
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(min(n,W)). The expression (insertLookupWithKey f k x map) is a pair (lookup k map) and the second element equal to (insertWithKey f k x map). > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value > insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) > insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) > insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define insertLookup using insertLookupWithKey: > let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t > insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) > insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")])
insertLookupWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a)
containers Data.Map.Lazy, containers Data.Map.Strict
O(log n). Combines insert operation with old value retrieval. The expression (insertLookupWithKey f k x map) is a pair map</tt>) and the second element equal to (insertWithKey f k x map). > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value > insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) > insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) > insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define insertLookup using insertLookupWithKey: > let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t > insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) > insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")])
insertLookupWithKey' :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a)
containers Data.Map
Deprecated. As of version 0.5, replaced by insertLookupWithKey. O(log n). Same as insertLookupWithKey, but the value being inserted to the map is evaluated to WHNF beforehand.