@@ -50,6 +50,8 @@ module Data.HashMap.Strict.Refined
50 , FromTraversableProof(..)
50 , FromTraversableProof(..)
51 -- * Insertion
51 -- * Insertion
53 , InsertProof(..)
55 , InsertProof(..)
54 , reinsert
56 , reinsert
55 , insertLookupWithKey
57 , insertLookupWithKey
@@ -206,6 +208,35 @@ insert
206insert k v (HashMap m) = SomeHashMapWith (HashMap $ HashMap.insert k v m)
208insert k v (HashMap m) = SomeHashMapWith (HashMap $ HashMap.insert k v m)
207 $ InsertProof (unsafeKey k) unsafeSubset
209 $ InsertProof (unsafeKey k) unsafeSubset
211+-- | Insert a key-value pair into the map to obtain a potentially larger map,
212+-- guaranteed to contain the given key. If the key was already present, the
213+-- supplied function is used to combine the new value with the old (in that
216+ :: forall s k a. Hashable k
221+ -> SomeHashMapWith (InsertProof 'Hashed k s) k a
222+insertWith f k v (HashMap m) = SomeHashMapWith
223+ (HashMap $ HashMap.insertWith f k v m)
224+ $ InsertProof (unsafeKey k) unsafeSubset
226+-- | Insert a key-value pair into the map to obtain a potentially larger map,
227+-- guaranteed to contain the given key. Like 'insertWith', but the combining
228+-- function has access to the key, which is guaranteed to be in the old map.
230+ :: forall s k a. Hashable k
231+ => (Key s k -> a -> a -> a)
235+ -> SomeHashMapWith (InsertProof 'Hashed k s) k a
236+insertWithKey f k v (HashMap m) = SomeHashMapWith
237+ (HashMap $ HashMap.insertWith (f $ unsafeKey k) k v m)
238+ $ InsertProof (unsafeKey k) unsafeSubset
209-- | Overwrite a key-value pair that is known to already be in the map. The set
240-- | Overwrite a key-value pair that is known to already be in the map. The set
210-- of keys remains the same.
241-- of keys remains the same.