add CCList.to_string

This commit is contained in:
Fardale 2019-10-28 13:03:22 +01:00
parent 10c0576d91
commit 9c375ed93e
2 changed files with 18 additions and 0 deletions

View file

@ -1649,6 +1649,18 @@ let random_choose l = match l with
let random_sequence l st = map (fun g -> g st) l
let to_string ?(start="") ?(stop="") ?(sep=", ") item_to_string l =
let l = List.map item_to_string l in
start ^ (String.concat sep l) ^ stop
(*$= to_string & ~printer:(fun s -> s)
(to_string string_of_int []) ""
(to_string ~start:"[" ~stop:"]" string_of_int []) "[]"
(to_string ~start:"[" ~stop:"]" string_of_int [1]) "[1]"
(to_string ~start:"[" ~stop:"]" string_of_int [1;2;3;4]) "[1, 2, 3, 4]"
(to_string ~sep:" " string_of_int [1;2;3;4]) "1 2 3 4"
*)
let to_seq l k = List.iter k l
let of_seq seq =
let l = ref [] in

View file

@ -685,6 +685,12 @@ val random_choose : 'a t -> 'a random_gen
val random_sequence : 'a random_gen t -> 'a t random_gen
val to_string : ?start:string -> ?stop:string -> ?sep:string ->
('a -> string) -> 'a t -> string
(** [to_string ~start ~stop ~sep item_to_string l] print [l] to a string using
[sep] as a separator between elements of [l].
@since NEXT_RELEASE *)
val to_seq : 'a t -> 'a sequence
(** Return a [sequence] of the elements of the list. *)