git.iko.soy/typeable/refined-containers
on main help sign in
Add intersection and intersectionWith
a959064mniip
src/Data/HashMap/Common/Refined.hs+14
@@ -270,6 +270,20 @@ difference (HashMap m1) (HashMap m2)
270 = SomeHashMapWith (HashMap $ HashMap.difference m1 m2)
270 = SomeHashMapWith (HashMap $ HashMap.difference m1 m2)
271 $ DifferenceProof unsafeSubset (\f g -> unsafeSubsetWith2 f g) unsafeSubset
271 $ DifferenceProof unsafeSubset (\f g -> unsafeSubsetWith2 f g) unsafeSubset
272
272
273+-- | Return the intersection of two maps, taking values from the first map.
274+--
275+-- @
276+-- 'intersection' = intersectionWith 'const'
277+-- @
278+intersection
279+ :: forall s t k a b. Hashable k
280+ => HashMap s k a
281+ -> HashMap t k b
282+ -> SomeHashMapWith (IntersectionProof 'Hashed s t) k a
283+intersection (HashMap m1) (HashMap m2) = SomeHashMapWith
284+ (HashMap $ HashMap.intersection m1 m2)
285+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
286+
273-- | Apply a function to all values in a map, together with their corresponding
287-- | Apply a function to all values in a map, together with their corresponding
274-- keys, that are proven to be in the map. The set of keys remains the same.
288-- keys, that are proven to be in the map. The set of keys remains the same.
275mapWithKey
289mapWithKey
src/Data/HashMap/Refined.hs+13
@@ -85,6 +85,8 @@ module Data.HashMap.Refined
85 , differenceWith
85 , differenceWith
86 , differenceWithKey
86 , differenceWithKey
87 , PartialDifferenceProof(..)
87 , PartialDifferenceProof(..)
88+ , Common.intersection
89+ , intersectionWith
88 , intersectionWithKey
90 , intersectionWithKey
89 , IntersectionProof(..)
91 , IntersectionProof(..)
90 -- * Traversal
92 -- * Traversal
@@ -390,6 +392,17 @@ differenceWithKey f (HashMap m1) (HashMap m2) = SomeHashMapWith
390 (HashMap.mapWithKey (,) m2))
392 (HashMap.mapWithKey (,) m2))
391 $ PartialDifferenceProof unsafeSubset unsafeSubset
393 $ PartialDifferenceProof unsafeSubset unsafeSubset
392
394
395+-- | Return the intersection of two maps with the given combining function.
396+intersectionWith
397+ :: forall s t k a b c. Hashable k
398+ => (a -> b -> c)
399+ -> HashMap s k a
400+ -> HashMap t k b
401+ -> SomeHashMapWith (IntersectionProof 'Hashed s t) k c
402+intersectionWith f (HashMap m1) (HashMap m2) = SomeHashMapWith
403+ (HashMap $ HashMap.intersectionWith f m1 m2)
404+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
405+
393-- | Return the intersection of two maps with the given combining function.
406-- | Return the intersection of two maps with the given combining function.
394--
407--
395-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
408-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
src/Data/HashMap/Strict/Refined.hs+13
@@ -85,6 +85,8 @@ module Data.HashMap.Strict.Refined
85 , differenceWith
85 , differenceWith
86 , differenceWithKey
86 , differenceWithKey
87 , PartialDifferenceProof(..)
87 , PartialDifferenceProof(..)
88+ , Common.intersection
89+ , intersectionWith
88 , intersectionWithKey
90 , intersectionWithKey
89 , IntersectionProof(..)
91 , IntersectionProof(..)
90 -- * Traversal
92 -- * Traversal
@@ -406,6 +408,17 @@ differenceWithKey f (HashMap m1) (HashMap m2) = SomeHashMapWith
406 (HashMap.mapWithKey (,) m2))
408 (HashMap.mapWithKey (,) m2))
407 $ PartialDifferenceProof unsafeSubset unsafeSubset
409 $ PartialDifferenceProof unsafeSubset unsafeSubset
408
410
411+-- | Return the intersection of two maps with the given combining function.
412+intersectionWith
413+ :: forall s t k a b c. Hashable k
414+ => (a -> b -> c)
415+ -> HashMap s k a
416+ -> HashMap t k b
417+ -> SomeHashMapWith (IntersectionProof 'Hashed s t) k c
418+intersectionWith f (HashMap m1) (HashMap m2) = SomeHashMapWith
419+ (HashMap $ HashMap.intersectionWith f m1 m2)
420+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
421+
409-- | Return the intersection of two maps with the given combining function.
422-- | Return the intersection of two maps with the given combining function.
410--
423--
411-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
424-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
src/Data/IntMap/Common/Refined.hs+13
@@ -288,6 +288,19 @@ difference (IntMap m1) (IntMap m2) = SomeIntMapWith
288 (IntMap $ IntMap.difference m1 m2)
288 (IntMap $ IntMap.difference m1 m2)
289 $ DifferenceProof unsafeSubset (\f g -> unsafeSubsetWith2 f g) unsafeSubset
289 $ DifferenceProof unsafeSubset (\f g -> unsafeSubsetWith2 f g) unsafeSubset
290
290
291+-- | Return the intersection of two maps, taking values from the first map.
292+--
293+-- @
294+-- 'intersection' = intersectionWith 'const'
295+-- @
296+intersection
297+ :: forall s t a b. IntMap s a
298+ -> IntMap t b
299+ -> SomeIntMapWith (IntersectionProof 'Int s t) a
300+intersection (IntMap m1) (IntMap m2) = SomeIntMapWith
301+ (IntMap $ IntMap.intersection m1 m2)
302+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
303+
291-- | Apply a function to all values in a map, together with their corresponding
304-- | Apply a function to all values in a map, together with their corresponding
292-- keys, that are proven to be in the map. The set of keys remains the same.
305-- keys, that are proven to be in the map. The set of keys remains the same.
293mapWithKey :: forall s a b. (Key s -> a -> b) -> IntMap s a -> IntMap s b
306mapWithKey :: forall s a b. (Key s -> a -> b) -> IntMap s a -> IntMap s b
src/Data/IntMap/Refined.hs+12
@@ -80,6 +80,8 @@ module Data.IntMap.Refined
80 , differenceWith
80 , differenceWith
81 , differenceWithKey
81 , differenceWithKey
82 , PartialDifferenceProof(..)
82 , PartialDifferenceProof(..)
83+ , Common.intersection
84+ , intersectionWith
83 , intersectionWithKey
85 , intersectionWithKey
84 , IntersectionProof(..)
86 , IntersectionProof(..)
85 -- * Traversal
87 -- * Traversal
@@ -377,6 +379,16 @@ differenceWithKey f (IntMap m1) (IntMap m2) = SomeIntMapWith
377 (IntMap $ IntMap.differenceWithKey (f . reallyUnsafeRefine) m1 m2)
379 (IntMap $ IntMap.differenceWithKey (f . reallyUnsafeRefine) m1 m2)
378 $ PartialDifferenceProof unsafeSubset unsafeSubset
380 $ PartialDifferenceProof unsafeSubset unsafeSubset
379
381
382+-- | Return the intersection of two maps with the given combining function.
383+intersectionWith
384+ :: forall s t a b c. (a -> b -> c)
385+ -> IntMap s a
386+ -> IntMap t b
387+ -> SomeIntMapWith (IntersectionProof 'Int s t) c
388+intersectionWith f (IntMap m1) (IntMap m2) = SomeIntMapWith
389+ (IntMap $ IntMap.intersectionWith f m1 m2)
390+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
391+
380-- | Return the intersection of two maps with the given combining function.
392-- | Return the intersection of two maps with the given combining function.
381--
393--
382-- You can use 'andLeft' and 'andRight' to obtain @'Key' s@ and @'Key' t@
394-- You can use 'andLeft' and 'andRight' to obtain @'Key' s@ and @'Key' t@
src/Data/IntMap/Strict/Refined.hs+12
@@ -80,6 +80,8 @@ module Data.IntMap.Strict.Refined
80 , differenceWith
80 , differenceWith
81 , differenceWithKey
81 , differenceWithKey
82 , PartialDifferenceProof(..)
82 , PartialDifferenceProof(..)
83+ , Common.intersection
84+ , intersectionWith
83 , intersectionWithKey
85 , intersectionWithKey
84 , IntersectionProof(..)
86 , IntersectionProof(..)
85 -- * Traversal
87 -- * Traversal
@@ -404,6 +406,16 @@ differenceWithKey f (IntMap m1) (IntMap m2) = SomeIntMapWith
404 (IntMap $ IntMap.differenceWithKey (f . reallyUnsafeRefine) m1 m2)
406 (IntMap $ IntMap.differenceWithKey (f . reallyUnsafeRefine) m1 m2)
405 $ PartialDifferenceProof unsafeSubset unsafeSubset
407 $ PartialDifferenceProof unsafeSubset unsafeSubset
406
408
409+-- | Return the intersection of two maps with the given combining function.
410+intersectionWith
411+ :: forall s t a b c. (a -> b -> c)
412+ -> IntMap s a
413+ -> IntMap t b
414+ -> SomeIntMapWith (IntersectionProof 'Int s t) c
415+intersectionWith f (IntMap m1) (IntMap m2) = SomeIntMapWith
416+ (IntMap $ IntMap.intersectionWith f m1 m2)
417+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
418+
407-- | Return the intersection of two maps with the given combining function.
419-- | Return the intersection of two maps with the given combining function.
408--
420--
409-- You can use 'andLeft' and 'andRight' to obtain @'Key' s@ and @'Key' t@
421-- You can use 'andLeft' and 'andRight' to obtain @'Key' s@ and @'Key' t@
src/Data/Map/Common/Refined.hs+14
@@ -293,6 +293,20 @@ difference
293difference (Map m1) (Map m2) = SomeMapWith (Map $ Map.difference m1 m2)
293difference (Map m1) (Map m2) = SomeMapWith (Map $ Map.difference m1 m2)
294 $ DifferenceProof unsafeSubset (\f g -> unsafeSubsetWith2 f g) unsafeSubset
294 $ DifferenceProof unsafeSubset (\f g -> unsafeSubsetWith2 f g) unsafeSubset
295
295
296+-- | Return the intersection of two maps, taking values from the first map.
297+--
298+-- @
299+-- 'intersection' = intersectionWith 'const'
300+-- @
301+intersection
302+ :: forall s t k a b. Ord k
303+ => Map s k a
304+ -> Map t k b
305+ -> SomeMapWith (IntersectionProof 'Regular s t) k a
306+intersection (Map m1) (Map m2)
307+ = SomeMapWith (Map $ Map.intersection m1 m2)
308+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
309+
296-- | Apply a function to all values in a map, together with their corresponding
310-- | Apply a function to all values in a map, together with their corresponding
297-- keys, that are proven to be in the map. The set of keys remains the same.
311-- keys, that are proven to be in the map. The set of keys remains the same.
298mapWithKey :: forall s k a b. (Key s k -> a -> b) -> Map s k a -> Map s k b
312mapWithKey :: forall s k a b. (Key s k -> a -> b) -> Map s k a -> Map s k b
src/Data/Map/Refined.hs+13
@@ -89,6 +89,8 @@ module Data.Map.Refined
89 , differenceWith
89 , differenceWith
90 , differenceWithKey
90 , differenceWithKey
91 , PartialDifferenceProof(..)
91 , PartialDifferenceProof(..)
92+ , Common.intersection
93+ , intersectionWith
92 , intersectionWithKey
94 , intersectionWithKey
93 , IntersectionProof(..)
95 , IntersectionProof(..)
94 -- * Traversal
96 -- * Traversal
@@ -388,6 +390,17 @@ differenceWithKey f (Map m1) (Map m2)
388 = SomeMapWith (Map $ Map.differenceWithKey (f . reallyUnsafeRefine) m1 m2)
390 = SomeMapWith (Map $ Map.differenceWithKey (f . reallyUnsafeRefine) m1 m2)
389 $ PartialDifferenceProof unsafeSubset unsafeSubset
391 $ PartialDifferenceProof unsafeSubset unsafeSubset
390
392
393+-- | Return the intersection of two maps with the given combining function.
394+intersectionWith
395+ :: forall s t k a b c. Ord k
396+ => (a -> b -> c)
397+ -> Map s k a
398+ -> Map t k b
399+ -> SomeMapWith (IntersectionProof 'Regular s t) k c
400+intersectionWith f (Map m1) (Map m2)
401+ = SomeMapWith (Map $ Map.intersectionWith f m1 m2)
402+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
403+
391-- | Return the intersection of two maps with the given combining function.
404-- | Return the intersection of two maps with the given combining function.
392--
405--
393-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
406-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
src/Data/Map/Strict/Refined.hs+13
@@ -89,6 +89,8 @@ module Data.Map.Strict.Refined
89 , differenceWith
89 , differenceWith
90 , differenceWithKey
90 , differenceWithKey
91 , PartialDifferenceProof(..)
91 , PartialDifferenceProof(..)
92+ , Common.intersection
93+ , intersectionWith
92 , intersectionWithKey
94 , intersectionWithKey
93 , IntersectionProof(..)
95 , IntersectionProof(..)
94 -- * Traversal
96 -- * Traversal
@@ -412,6 +414,17 @@ differenceWithKey f (Map m1) (Map m2)
412 = SomeMapWith (Map $ Map.differenceWithKey (f . reallyUnsafeRefine) m1 m2)
414 = SomeMapWith (Map $ Map.differenceWithKey (f . reallyUnsafeRefine) m1 m2)
413 $ PartialDifferenceProof unsafeSubset unsafeSubset
415 $ PartialDifferenceProof unsafeSubset unsafeSubset
414
416
417+-- | Return the intersection of two maps with the given combining function.
418+intersectionWith
419+ :: forall s t k a b c. Ord k
420+ => (a -> b -> c)
421+ -> Map s k a
422+ -> Map t k b
423+ -> SomeMapWith (IntersectionProof 'Regular s t) k c
424+intersectionWith f (Map m1) (Map m2)
425+ = SomeMapWith (Map $ Map.intersectionWith f m1 m2)
426+ $ IntersectionProof unsafeSubset unsafeSubsetWith2
427+
415-- | Return the intersection of two maps with the given combining function.
428-- | Return the intersection of two maps with the given combining function.
416--
429--
417-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@
430-- You can use 'andLeft' and 'andRight' to obtain @'Key' s k@ and @'Key' t k@