mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-16 23:56:43 -05:00
add CCList.to_string
This commit is contained in:
parent
10c0576d91
commit
9c375ed93e
2 changed files with 18 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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. *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue