diff --git a/src/stdune/map.ml b/src/stdune/map.ml index 329178bd..efc46028 100644 --- a/src/stdune/map.ml +++ b/src/stdune/map.ml @@ -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 diff --git a/src/stdune/map_intf.ml b/src/stdune/map_intf.ml index 9c6fa22e..9677ef5a 100644 --- a/src/stdune/map_intf.ml +++ b/src/stdune/map_intf.ml @@ -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 diff --git a/src/stdune/univ_map.ml b/src/stdune/univ_map.ml index 9bdb0f20..a17795be 100644 --- a/src/stdune/univ_map.ml +++ b/src/stdune/univ_map.ml @@ -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 diff --git a/src/stdune/univ_map.mli b/src/stdune/univ_map.mli index 6cea4955..03d20724 100644 --- a/src/stdune/univ_map.mli +++ b/src/stdune/univ_map.mli @@ -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