Merge a map and a set into a map.
merge takes a SimpleWhenMissing tactic, a SimpleWhenMissingSet
tactic, a SimpleWhenMatched tactic, a map and a set. It uses the tactics to
merge the map and the set into a map.
Its behavior is best understood via the tactics mapMaybeMissing,
generateMaybeMissingSet, and mapMaybeMatched. Consider
merge (mapMaybeMissing g1) (generateMaybeMissingSet g2) (mapMaybeMatched f) m1 s2
g1 k x = if k == 2 then Just ("1" ++ x) else Nothing
g2 k = if k == 3 then Just "2" else Nothing
f k x = if k == 6 then Just ("3" ++ x) else Nothing
m1 = fromList [(2,"a"), (4,"b"), (6,"c"), (8,"d"), (10,"e"), (12,"f")]
s2 = fromList [3, 6, 9, 12]
merge will pass the keys and values to g1, g2, or f as appropriate,
producing a Maybe for each element.
m1: [ (2, "a"), (4, "b"), (6, "c"), (8, "d"), (10, "e"), (12, "f")]
s2: [ 3, 6, 9, 12]
result: [ g1 2 "a", g2 3, g1 4 "b", f 6 "c", g1 8 "d", g2 9, g1 10 "e", f 12 "f"]
= [Just "1a", Just "2", Nothing, Just "3c", Nothing, Nothing, Nothing, Nothing]
The result map contains the Just values.
>>> merge (mapMaybeMissing g1) (generateMaybeMissingSet g2) (mapMaybeMatched f) m1 s2
fromList [(2,"1a"), (3,"2g"), (6,"3c")]
When merge is given three arguments, it is inlined at the call
site. To prevent excessive inlining, you should typically use merge
to define your custom combining functions.
What to do with keys in m1 but not s2
What to do with keys in s2 but not m1
What to do with keys in both m1 and s2
Map m1
Set s2