test: add a test for update

This commit is contained in:
Simon Cruanes 2020-09-21 13:48:30 -04:00
parent e6f77edf1a
commit 5ee25afad5

View file

@ -103,6 +103,10 @@ module type S = sig
?pp_sep:unit printer -> key printer -> 'a printer -> 'a t printer ?pp_sep:unit printer -> key printer -> 'a printer -> 'a t printer
end end
(*$inject
module M = CCMap.Make(String)
*)
module Make(O : Map.OrderedType) = struct module Make(O : Map.OrderedType) = struct
module M = Map.Make(O) module M = Map.Make(O)
@ -175,6 +179,15 @@ module Make(O : Map.OrderedType) = struct
| None -> M.remove k m | None -> M.remove k m
| Some v' -> M.add k v' m | Some v' -> M.add k v' m
(*$= & ~printer:CCFormat.(to_string @@ Dump.(list (pair string int)))
["a", 1; "b", 20] \
(M.of_list ["b", 2; "c", 3] \
|> M.update "a" (function _ -> Some 1) \
|> M.update "c" (fun _ -> None) \
|> M.update "b" (CCOpt.map (fun x -> x * 10)) \
|> M.to_list |> List.sort CCOrd.compare)
*)
include M include M
let get = find_opt let get = find_opt