mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-16 23:56:43 -05:00
add CCSet.to_string
This commit is contained in:
parent
1e0669e1b0
commit
087612823e
2 changed files with 39 additions and 0 deletions
|
|
@ -8,6 +8,13 @@ type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
module type OrderedType = Set.OrderedType
|
module type OrderedType = Set.OrderedType
|
||||||
|
|
||||||
|
(*$inject
|
||||||
|
module S = CCSet.Make(struct
|
||||||
|
type t = int
|
||||||
|
let compare x y = Stdlib.compare x y
|
||||||
|
end)
|
||||||
|
*)
|
||||||
|
|
||||||
module type S = sig
|
module type S = sig
|
||||||
include Set.S
|
include Set.S
|
||||||
|
|
||||||
|
|
@ -59,6 +66,12 @@ module type S = sig
|
||||||
|
|
||||||
val to_list : t -> elt list
|
val to_list : t -> elt list
|
||||||
|
|
||||||
|
val to_string :
|
||||||
|
?start:string -> ?stop:string -> ?sep:string ->
|
||||||
|
(elt -> string) -> t -> string
|
||||||
|
(** Print the set in a string
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val pp :
|
val pp :
|
||||||
?start:string -> ?stop:string -> ?sep:string ->
|
?start:string -> ?stop:string -> ?sep:string ->
|
||||||
elt printer -> t printer
|
elt printer -> t printer
|
||||||
|
|
@ -135,6 +148,26 @@ module Make(O : Map.OrderedType) = struct
|
||||||
|
|
||||||
let to_list = elements
|
let to_list = elements
|
||||||
|
|
||||||
|
let to_string ?(start="") ?(stop="") ?(sep=",") elt_to_string h =
|
||||||
|
to_list h
|
||||||
|
|> CCList.to_string ~start ~stop ~sep elt_to_string
|
||||||
|
|
||||||
|
(*$= & ~printer:(fun s -> s)
|
||||||
|
(S.to_string string_of_int (S.of_list [4; 3])) "3,4"
|
||||||
|
*)
|
||||||
|
(*$Q
|
||||||
|
Q.(list int) (fun l -> \
|
||||||
|
let s = S.of_list l in \
|
||||||
|
(S.to_string string_of_int s) \
|
||||||
|
= (CCList.sort_uniq ~cmp:CCInt.compare l \
|
||||||
|
|> List.map string_of_int |> String.concat ","))
|
||||||
|
Q.(list int) (fun l -> \
|
||||||
|
let s = S.of_list l in \
|
||||||
|
(S.to_string ~sep:" " string_of_int s) \
|
||||||
|
= (CCList.sort_uniq ~cmp:CCInt.compare l \
|
||||||
|
|> List.map string_of_int |> String.concat " "))
|
||||||
|
*)
|
||||||
|
|
||||||
let pp ?(start="") ?(stop="") ?(sep=", ") pp_x fmt m =
|
let pp ?(start="") ?(stop="") ?(sep=", ") pp_x fmt m =
|
||||||
Format.pp_print_string fmt start;
|
Format.pp_print_string fmt start;
|
||||||
let first = ref true in
|
let first = ref true in
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,12 @@ module type S = sig
|
||||||
val to_list : t -> elt list
|
val to_list : t -> elt list
|
||||||
(** [to_list t] converts the set [t] to a list of the elements. *)
|
(** [to_list t] converts the set [t] to a list of the elements. *)
|
||||||
|
|
||||||
|
val to_string :
|
||||||
|
?start:string -> ?stop:string -> ?sep:string ->
|
||||||
|
(elt -> string) -> t -> string
|
||||||
|
(** Print the set in a string
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val pp :
|
val pp :
|
||||||
?start:string -> ?stop:string -> ?sep:string ->
|
?start:string -> ?stop:string -> ?sep:string ->
|
||||||
elt printer -> t printer
|
elt printer -> t printer
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue