# Monad m => m a -> m b -> m a

Promote a function to a monad, scanning the monadic arguments from left to right. For example, > liftM2 (+) [0,1] [0,2] = [0,2,1,3] > liftM2 (+) (Just 1) Nothing = Nothing
A specialised variant of bracket with just a computation to run afterward.
Like finally, but only performs the final action if there was an exception raised by the computation.
Same as difference.
O(n+m). Difference between two maps (based on keys). > difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b"
O(n+m). The (left-biased) intersection of two maps (based on keys). > intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a"
Promote a function to a monad, scanning the monadic arguments from left to right (cf. liftM2).
Flexible type extension
O(n+m). 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"
O(n+m). 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"