intersection package:rio
Intersection of two maps. Return elements of the first
map for keys existing in the second.
Intersection of two sets. Return elements present in both
the first set and the second.
>>> HashSet.intersection (HashSet.fromList [1,2,3]) (HashSet.fromList [2,3,4])
fromList [2,3]
O(m*log(n/m + 1)), m <= n. Intersection of two maps. Return
data in the first map for the keys existing in both maps.
(
intersection m1 m2 == intersectionWith const
m1 m2).
intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a"
O(m*log(n/m + 1)), m <= n. The intersection of two sets.
Elements of the result come from the first set, so for example
import qualified Data.Set as S
data AB = A | B deriving Show
instance Ord AB where compare _ _ = EQ
instance Eq AB where _ == _ = True
main = print (S.singleton A `S.intersection` S.singleton B,
S.singleton B `S.intersection` S.singleton A)
prints
(fromList [A],fromList [B]).
Intersection of two maps. If a key occurs in both maps
the provided function is used to combine the values from the two maps.
Intersection of two maps. If a key occurs in both maps
the provided function is used to combine the values from the two maps.
O(m*log(n/m + 1)), m <= n. Intersection with a combining
function.
intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA"
O(m*log(n/m + 1)), m <= n. Intersection with a combining
function.
let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar
intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A"