# insertWithKey

O(min(n,W)). Insert with a combining function. insertWithKey f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f key new_value old_value. > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value > insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] > insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] > insertWithKey f 5 "xxx" empty == singleton 5 "xxx"
O(min(n,W)). Insert with a combining function. insertWithKey f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert f key new_value old_value. > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value > insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] > insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] > insertWithKey f 5 "xxx" empty == singleton 5 "xxx" If the key exists in the map, this function is lazy in x but strict in the result of f.
O(log n). Insert with a function, combining key, new value and old value. insertWithKey f key value mp will insert the pair (key, value) into mp if key does not exist in the map. If the key does exist, the function will insert the pair (key,f key new_value old_value). Note that the key passed to f is the same key passed to insertWithKey. > let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value > insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] > insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] > insertWithKey f 5 "xxx" empty == singleton 5 "xxx"
Deprecated. As of version 0.5, replaced by insertWithKey. O(log n). Same as insertWithKey, but the result of the combining function is evaluated to WHNF before inserted to the map.
Deprecated. As of version 0.5, replaced by insertWithKey. O(log n). Same as insertWithKey, but the value being inserted to the map is evaluated to WHNF beforehand.