difference package:containers

Difference between two maps (based on keys).
difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b"
Difference between two sets.
Difference of two maps. Return elements of the first map not existing in the second map.
difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b"
Difference of two sets. Return elements of the first set not existing in the second set.
difference (fromList [5, 3]) (fromList [5, 7]) == singleton 3
Difference with a combining function.
let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing
differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])
== singleton 3 "b:B"
Difference with a combining function. When two equal keys are encountered, the combining function is applied to the key and both values. If it returns Nothing, the element is discarded (proper set difference). If it returns (Just y), the element is updated with a new value y.
let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing
differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])
== singleton 3 "3:b|B"
Difference with a combining function. When two equal keys are encountered, the combining function is applied to the values of these keys. If it returns Nothing, the element is discarded (proper set difference). If it returns (Just y), the element is updated with a new value y.
let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing
differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])
== singleton 3 "b:B"
Difference with a combining function. When two equal keys are encountered, the combining function is applied to the key and both values. If it returns Nothing, the element is discarded (proper set difference). If it returns (Just y), the element is updated with a new value y.
let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing
differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])
== singleton 3 "3:b|B"
The symmetric difference of two maps. The result contains entries whose keys appear in exactly one of the two maps.
symmetricDifference
(fromList [(0,'q'),(2,'b'),(4,'w'),(6,'o')])
(fromList [(0,'e'),(3,'r'),(6,'t'),(9,'s')])
==
fromList [(2,'b'),(3,'r'),(4,'w'),(9,'s')]
The symmetric difference of two sets. The result contains elements that appear in exactly one of the two sets.
symmetricDifference (fromList [0,2,4,6]) (fromList [0,3,6,9]) == fromList [2,3,4,9]
The symmetric difference of two maps. The result contains entries whose keys appear in exactly one of the two maps.
symmetricDifference
(fromList [(0,'q'),(2,'b'),(4,'w'),(6,'o')])
(fromList [(0,'e'),(3,'r'),(6,'t'),(9,'s')])
==
fromList [(2,'b'),(3,'r'),(4,'w'),(9,'s')]
The symmetric difference of two sets. The result contains elements that appear in exactly one of the two sets.
symmetricDifference (fromList [0,2,4,6]) (fromList [0,3,6,9]) == fromList [2,3,4,9]