[sledge] Implement Map.find_and_remove more directly

Summary: No need for exceptions.

Reviewed By: jvillard

Differential Revision: D18736382

fbshipit-source-id: 684bf896c
master
Josh Berdine 5 years ago committed by Facebook Github Bot
parent 30aa8aa3b9
commit 661db9db76

@ -240,17 +240,15 @@ module Map = struct
let equal_m__t (module Elt : Compare_m) equal_v = equal equal_v
let find_and_remove_exn m k =
let find_and_remove m k =
let found = ref None in
let m =
change m k ~f:(fun v ->
found := v ;
None )
in
match !found with None -> raise Caml.Not_found | Some v -> (v, m)
let find_and_remove m k =
try Some (find_and_remove_exn m k) with Caml.Not_found -> None
let+ v = !found in
(v, m)
let find_or_add (type data) map key ~(default : data) ~if_found ~if_added
=

@ -184,7 +184,6 @@ module Map : sig
-> ('k, 'v, 'c) t
-> bool
val find_and_remove_exn : ('k, 'v, 'c) t -> 'k -> 'v * ('k, 'v, 'c) t
val find_and_remove : ('k, 'v, 'c) t -> 'k -> ('v * ('k, 'v, 'c) t) option
val find_or_add :

Loading…
Cancel
Save