# updateWithKey

O(min(n,W)). The expression (update f k map) updates the value x at k (if it is in the map). If (f k x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y. > let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing > updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] > updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] > updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
O(log n). The expression (updateWithKey f k map) updates the value x at k (if it is in the map). If (f k x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y. > let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing > updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] > updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] > updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"