Add Univ_map.superpose

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
Jeremie Dimino 2018-06-19 14:07:14 +01:00
parent 0e6986c2f2
commit aed6513b05
4 changed files with 13 additions and 0 deletions

View File

@ -116,4 +116,7 @@ module Make(Key : Comparable.S) : S with type key = Key.t = struct
| None -> assert false
| Some data -> f key data)
let filter_map t ~f = filter_mapi t ~f:(fun _ x -> f x)
let superpose a b =
union a b ~f:(fun _ _ y -> Some y)
end

View File

@ -21,6 +21,10 @@ module type S = sig
-> f:(key -> 'a -> 'a -> 'a option)
-> 'a t
(** [superpose a b] is [b] augmented with bindings of [a] that are
not in [b]. *)
val superpose : 'a t -> 'a t -> 'a t
val compare : 'a t -> 'a t -> compare:('a -> 'a -> Ordering.t) -> Ordering.t
val equal : 'a t -> 'a t -> equal:('a -> 'a -> bool) -> bool

View File

@ -72,3 +72,5 @@ let find_exn t key =
Eq.cast eq v
let singleton key v = Int.Map.singleton (Key.id key) (Binding.T (key, v))
let superpose = Int.Map.superpose

View File

@ -18,3 +18,7 @@ val remove : t -> 'a Key.t -> t
val find : t -> 'a Key.t -> 'a option
val find_exn : t -> 'a Key.t -> 'a
val singleton : 'a Key.t -> 'a -> t
(** [superpose a b] is [b] augmented with bindings of [a] that are not
in [b]. *)
val superpose : t -> t -> t