add a few functions to CCPersistentArray

This commit is contained in:
Simon Cruanes 2015-04-10 16:29:27 +02:00
parent d0c270504a
commit c71595f691
2 changed files with 16 additions and 0 deletions

View file

@ -80,3 +80,13 @@ let of_array a = init (Array.length a) (fun i -> a.(i))
let to_list t = Array.to_list (reroot t)
let of_list l = ref (Array (Array.of_list l))
type 'a sequence = ('a -> unit) -> unit
let to_seq a yield = iter yield a
let of_seq seq =
let l = ref [] in
seq (fun x -> l := x :: !l);
of_list (List.rev !l)

View file

@ -96,4 +96,10 @@ val to_list : 'a t -> 'a list
val of_list : 'a list -> 'a t
(** [of_list l] returns a fresh persistent array containing the elements of [l]. *)
type 'a sequence = ('a -> unit) -> unit
val to_seq : 'a t -> 'a sequence
val of_seq : 'a sequence -> 'a t