From: Peter J. <pe...@jo...> - 2005-05-23 10:40:12
|
Currently enum conversion functions are only provided for the data structures included in ExtLib itself. Might it be a good idea to add them for some or all of the remaining parts of the OCaml standard library? In particular, I've often found myself wanting to convert from the builtin array type, and there doesn't seem to be a function to handle that yet. So at the very least I'd propose adding something along the lines of: val enum_of_array : 'a array -> 'a Enum.t val array_of_enum : 'a Enum.t -> 'a array let enum_of_array a = (* stolen from DynArray.enum *) let rec make start = let idxref = ref 0 in let next () = if !idxref >= Array.length a then raise Enum.No_more_elements else let retval = Array.unsafe_get a !idxref in incr idxref; retval and count () = if !idxref >= Array.length a then 0 else Array.length a - !idxref and clone () = make !idxref in Enum.make ~next:next ~count:count ~clone:clone in make 0 let array_of_enum e = match Enum.peek e with | None -> [||] | Some elt -> let a = Array.make (Enum.count e) elt in Enum.iteri (Array.unsafe_set a) e; a |