rearrange some stuff

This commit is contained in:
Rhiannon Morris 2020-12-03 15:11:29 +01:00
parent 5c59d80e00
commit 6ac8be6984
10 changed files with 84 additions and 51 deletions

15
set_ext.ml Normal file
View file

@ -0,0 +1,15 @@
module type S = sig
include Set.S
val exists_opt: (elt -> 'a option) -> t -> 'a option
end
module Make(Elt: Set.OrderedType) = struct
include Set.Make(Elt)
let exists_opt (type a) (f: elt -> a option) set =
let exception Found of a in
let f' x = Option.iter (fun x -> raise (Found x)) (f x) in
match iter f' set with
| exception Found x -> Some x
| _ -> None
end