ligo/vendors/ligo-utils/simple-utils/x_map.ml

33 lines
828 B
OCaml
Raw Normal View History

2019-05-13 00:46:25 +04:00
module type OrderedType = Map.OrderedType
module type S = sig
include Map.S
val of_list : (key * 'a) list -> 'a t
val to_list : 'a t -> 'a list
val to_kv_list : 'a t -> (key * 'a) list
2020-04-22 21:44:21 +04:00
val add_bindings : (key * 'a) list -> 'a t -> 'a t
2019-05-13 00:46:25 +04:00
end
module Make(Ord : Map.OrderedType) : S with type key = Ord.t = struct
include Map.Make(Ord)
let of_list (lst: (key * 'a) list) : 'a t =
let aux prev (k, v) = add k v prev in
List.fold_left aux empty lst
let to_list (t: 'a t) : 'a list =
let aux _k v prev = v :: prev in
fold aux t []
let to_kv_list (t: 'a t) : (key * 'a) list =
let aux k v prev = (k, v) :: prev in
fold aux t []
2020-04-22 21:44:21 +04:00
let add_bindings (kvl:(key * 'a) list) (m:'a t) =
let aux prev (k, v) = add k v prev in
List.fold_left aux m kvl
2019-05-13 00:46:25 +04:00
end
module String = Make(String)