From 431c3a1e535f0c36acaafcaa2c2b4fe454365610 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 28 Oct 2015 15:39:01 +0100 Subject: [PATCH] add `CCSet.add_{list,seq}` --- src/core/CCSet.ml | 18 ++++++++++++++---- src/core/CCSet.mli | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/core/CCSet.ml b/src/core/CCSet.ml index f62a96e0..0603ee73 100644 --- a/src/core/CCSet.ml +++ b/src/core/CCSet.ml @@ -35,10 +35,16 @@ module type S = sig val of_seq : elt sequence -> t + val add_seq : t -> elt sequence -> t + (** @since NEXT_RELEASE *) + val to_seq : t -> elt sequence val of_list : elt list -> t + val add_list : t -> elt list -> t + (** @since NEXT_RELEASE *) + val to_list : t -> elt list val pp : ?start:string -> ?stop:string -> ?sep:string -> @@ -51,14 +57,18 @@ end module Make(O : Map.OrderedType) = struct include Set.Make(O) - let of_seq s = - let set = ref empty in - s (fun x -> set := add x !set); + let add_seq set seq = + let set = ref set in + seq (fun x -> set := add x !set); !set + let of_seq s = add_seq empty s + let to_seq s yield = iter yield s - let of_list l = List.fold_left (fun set x -> add x set) empty l + let add_list = List.fold_left (fun set x -> add x set) + + let of_list l = add_list empty l let to_list = elements diff --git a/src/core/CCSet.mli b/src/core/CCSet.mli index a9b1912a..3ea014f4 100644 --- a/src/core/CCSet.mli +++ b/src/core/CCSet.mli @@ -37,10 +37,16 @@ module type S = sig val of_seq : elt sequence -> t + val add_seq : t -> elt sequence -> t + (** @since NEXT_RELEASE *) + val to_seq : t -> elt sequence val of_list : elt list -> t + val add_list : t -> elt list -> t + (** @since NEXT_RELEASE *) + val to_list : t -> elt list val pp : ?start:string -> ?stop:string -> ?sep:string ->