git.iko.soy/typeable/refined-containers
on main help sign in
Add differenceWith
commitc9496f396d782b5b9296d5c0b4f7d1e675e328a1 authormniip <mniip@mniip.com> dateWed 5 Mar 2025, 12:53 (2 years ago) parent89ad0ad
6 files changed+88−12
src/Data/HashMap/Refined.hs+15−2 src/Data/HashMap/Strict/Refined.hs+15−2 src/Data/IntMap/Refined.hs+14−2 src/Data/IntMap/Strict/Refined.hs+14−2 src/Data/Map/Refined.hs+15−2 src/Data/Map/Strict/Refined.hs+15−2
src/Data/HashMap/Refined.hs+15−2
@@ -82,6 +82,7 @@ module Data.HashMap.Refined
8282 , UnionProof(..)
8383 , Common.difference
8484 , DifferenceProof(..)
85+ , differenceWith
8586 , differenceWithKey
8687 , PartialDifferenceProof(..)
8788 , intersectionWithKey
@@ -359,8 +360,20 @@ unionWithKey f (HashMap m1) (HashMap m2) = SomeHashMapWith
359360 (HashMap $ HashMap.unionWithKey (f . reallyUnsafeRefine) m1 m2)
360361 $ UnionProof unsafeSubset unsafeSubsetWith2
361362
362−-- | For keys that appear in both maps, the given function decides whether the
363−-- key is removed from the first map.
363+-- | Return the first map, but for keys that appear in both maps, the given
364+-- function decides whether the key is removed.
365+differenceWith
366+ :: forall s t k a b. Hashable k
367+ => (a -> b -> Maybe a)
368+ -> HashMap s k a
369+ -> HashMap t k b
370+ -> SomeHashMapWith (PartialDifferenceProof 'Hashed s t) k a
371+differenceWith f (HashMap m1) (HashMap m2) = SomeHashMapWith
372+ (HashMap $ HashMap.differenceWith f m1 m2)
373+ $ PartialDifferenceProof unsafeSubset unsafeSubset
374+
375+-- | Return the first map, but for keys that appear in both maps, the given
376+-- function decides whether the key is removed.
364377--
365378-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
366379-- respectively.
src/Data/HashMap/Strict/Refined.hs+15−2
@@ -82,6 +82,7 @@ module Data.HashMap.Strict.Refined
8282 , UnionProof(..)
8383 , Common.difference
8484 , DifferenceProof(..)
85+ , differenceWith
8586 , differenceWithKey
8687 , PartialDifferenceProof(..)
8788 , intersectionWithKey
@@ -375,8 +376,20 @@ unionWithKey f (HashMap m1) (HashMap m2) = SomeHashMapWith
375376 (HashMap $ HashMap.unionWithKey (f . reallyUnsafeRefine) m1 m2)
376377 $ UnionProof unsafeSubset unsafeSubsetWith2
377378
378−-- | For keys that appear in both maps, the given function decides whether the
379−-- key is removed from the first map.
379+-- | Return the first map, but for keys that appear in both maps, the given
380+-- function decides whether the key is removed.
381+differenceWith
382+ :: forall s t k a b. Hashable k
383+ => (a -> b -> Maybe a)
384+ -> HashMap s k a
385+ -> HashMap t k b
386+ -> SomeHashMapWith (PartialDifferenceProof 'Hashed s t) k a
387+differenceWith f (HashMap m1) (HashMap m2) = SomeHashMapWith
388+ (HashMap $ HashMap.differenceWith f m1 m2)
389+ $ PartialDifferenceProof unsafeSubset unsafeSubset
390+
391+-- | Return the first map, but for keys that appear in both maps, the given
392+-- function decides whether the key is removed.
380393--
381394-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
382395-- respectively.
src/Data/IntMap/Refined.hs+14−2
@@ -77,6 +77,7 @@ module Data.IntMap.Refined
7777 , UnionProof(..)
7878 , Common.difference
7979 , DifferenceProof(..)
80+ , differenceWith
8081 , differenceWithKey
8182 , PartialDifferenceProof(..)
8283 , intersectionWithKey
@@ -348,8 +349,19 @@ unionWithKey f (IntMap m1) (IntMap m2)
348349 = SomeIntMapWith (IntMap $ IntMap.unionWithKey (f . reallyUnsafeRefine) m1 m2)
349350 $ UnionProof unsafeSubset unsafeSubsetWith2
350351
351−-- | For keys that appear in both maps, the given function decides whether the
352−-- key is removed from the first map.
352+-- | Return the first map, but for keys that appear in both maps, the given
353+-- function decides whether the key is removed.
354+differenceWith
355+ :: forall s t a b. (a -> b -> Maybe a)
356+ -> IntMap s a
357+ -> IntMap t b
358+ -> SomeIntMapWith (PartialDifferenceProof 'Int s t) a
359+differenceWith f (IntMap m1) (IntMap m2) = SomeIntMapWith
360+ (IntMap $ IntMap.differenceWith f m1 m2)
361+ $ PartialDifferenceProof unsafeSubset unsafeSubset
362+
363+-- | Return the first map, but for keys that appear in both maps, the given
364+-- function decides whether the key is removed.
353365--
354366-- You can use 'andLeft' and 'andRight' to obtain @'Key' s@ and @'Key' t@
355367-- respectively.
src/Data/IntMap/Strict/Refined.hs+14−2
@@ -77,6 +77,7 @@ module Data.IntMap.Strict.Refined
7777 , UnionProof(..)
7878 , Common.difference
7979 , DifferenceProof(..)
80+ , differenceWith
8081 , differenceWithKey
8182 , PartialDifferenceProof(..)
8283 , intersectionWithKey
@@ -375,8 +376,19 @@ unionWithKey f (IntMap m1) (IntMap m2)
375376 = SomeIntMapWith (IntMap $ IntMap.unionWithKey (f . reallyUnsafeRefine) m1 m2)
376377 $ UnionProof unsafeSubset unsafeSubsetWith2
377378
378−-- | For keys that appear in both maps, the given function decides whether the
379−-- key is removed from the first map.
379+-- | Return the first map, but for keys that appear in both maps, the given
380+-- function decides whether the key is removed.
381+differenceWith
382+ :: forall s t a b. (a -> b -> Maybe a)
383+ -> IntMap s a
384+ -> IntMap t b
385+ -> SomeIntMapWith (PartialDifferenceProof 'Int s t) a
386+differenceWith f (IntMap m1) (IntMap m2) = SomeIntMapWith
387+ (IntMap $ IntMap.differenceWith f m1 m2)
388+ $ PartialDifferenceProof unsafeSubset unsafeSubset
389+
390+-- | Return the first map, but for keys that appear in both maps, the given
391+-- function decides whether the key is removed.
380392--
381393-- You can use 'andLeft' and 'andRight' to obtain @'Key' s@ and @'Key' t@
382394-- respectively.
src/Data/Map/Refined.hs+15−2
@@ -86,6 +86,7 @@ module Data.Map.Refined
8686 , UnionProof(..)
8787 , Common.difference
8888 , DifferenceProof(..)
89+ , differenceWith
8990 , differenceWithKey
9091 , PartialDifferenceProof(..)
9192 , intersectionWithKey
@@ -360,8 +361,20 @@ unionWithKey f (Map m1) (Map m2)
360361 = SomeMapWith (Map $ Map.unionWithKey (f . reallyUnsafeRefine) m1 m2)
361362 $ UnionProof unsafeSubset unsafeSubsetWith2
362363
363−-- | For keys that appear in both maps, the given function decides whether the
364−-- key is removed from the first map.
364+-- | Return the first map, but for keys that appear in both maps, the given
365+-- function decides whether the key is removed.
366+differenceWith
367+ :: forall s t k a b. Ord k
368+ => (a -> b -> Maybe a)
369+ -> Map s k a
370+ -> Map t k b
371+ -> SomeMapWith (PartialDifferenceProof 'Regular s t) k a
372+differenceWith f (Map m1) (Map m2)
373+ = SomeMapWith (Map $ Map.differenceWith f m1 m2)
374+ $ PartialDifferenceProof unsafeSubset unsafeSubset
375+
376+-- | Return the first map, but for keys that appear in both maps, the given
377+-- function decides whether the key is removed.
365378--
366379-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
367380-- respectively.
src/Data/Map/Strict/Refined.hs+15−2
@@ -86,6 +86,7 @@ module Data.Map.Strict.Refined
8686 , UnionProof(..)
8787 , Common.difference
8888 , DifferenceProof(..)
89+ , differenceWith
8990 , differenceWithKey
9091 , PartialDifferenceProof(..)
9192 , intersectionWithKey
@@ -384,8 +385,20 @@ unionWithKey f (Map m1) (Map m2)
384385 = SomeMapWith (Map $ Map.unionWithKey (f . reallyUnsafeRefine) m1 m2)
385386 $ UnionProof unsafeSubset unsafeSubsetWith2
386387
387−-- | For keys that appear in both maps, the given function decides whether the
388−-- key is removed from the first map.
388+-- | Return the first map, but for keys that appear in both maps, the given
389+-- function decides whether the key is removed.
390+differenceWith
391+ :: forall s t k a b. Ord k
392+ => (a -> b -> Maybe a)
393+ -> Map s k a
394+ -> Map t k b
395+ -> SomeMapWith (PartialDifferenceProof 'Regular s t) k a
396+differenceWith f (Map m1) (Map m2)
397+ = SomeMapWith (Map $ Map.differenceWith f m1 m2)
398+ $ PartialDifferenceProof unsafeSubset unsafeSubset
399+
400+-- | Return the first map, but for keys that appear in both maps, the given
401+-- function decides whether the key is removed.
389402--
390403-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
391404-- respectively.