X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FMap.hs;h=f0b7f6ff785c70ba89070824951f36b76c6cda06;hb=2701ac4127cbc37e6d1069e2f5240a1e0ec1e479;hp=cafb0a10f972572478e3a80664b3bb970166ac03;hpb=b959bfb92f069ebe2911d1239155fc80beceb283;p=haskell-directory.git diff --git a/Data/Map.hs b/Data/Map.hs index cafb0a1..f0b7f6f 100644 --- a/Data/Map.hs +++ b/Data/Map.hs @@ -301,11 +301,19 @@ insert kx x t EQ -> Bin sz kx x l r -- | /O(log n)/. Insert with a combining function. +-- @'insertWith' f key value mp@ +-- will insert the pair (key, value) into @mp@ if key does +-- not exist in the map. If the key does exist, the function will +-- insert @f new_value old_value@. insertWith :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a insertWith f k x m = insertWithKey (\k x y -> f x y) k x m -- | /O(log n)/. Insert with a combining function. +-- @'insertWithKey' f key value mp@ +-- will insert the pair (key, value) into @mp@ if key does +-- not exist in the map. If the key does exist, the function will +-- insert @f key new_value old_value@. insertWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a insertWithKey f kx x t = case t of