mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 11:15:32 -05:00
some conversion functions that use Sequence.t2
This commit is contained in:
parent
ba3564c2bb
commit
43f4f25ed7
2 changed files with 21 additions and 1 deletions
12
sequence.ml
12
sequence.ml
|
|
@ -362,6 +362,10 @@ let of_array_i a =
|
||||||
for i = 0 to Array.length a - 1 do k (i, a.(i)) done
|
for i = 0 to Array.length a - 1 do k (i, a.(i)) done
|
||||||
in from_iter seq
|
in from_iter seq
|
||||||
|
|
||||||
|
let of_array2 a =
|
||||||
|
fun k ->
|
||||||
|
for i = 0 to Array.length a - 1 do k i a.(i) done
|
||||||
|
|
||||||
(** [array_slice a i j] Sequence of elements whose indexes range
|
(** [array_slice a i j] Sequence of elements whose indexes range
|
||||||
from [i] to [j] *)
|
from [i] to [j] *)
|
||||||
let array_slice a i j =
|
let array_slice a i j =
|
||||||
|
|
@ -410,9 +414,17 @@ let to_hashtbl seq =
|
||||||
hashtbl_replace h seq;
|
hashtbl_replace h seq;
|
||||||
h
|
h
|
||||||
|
|
||||||
|
let to_hashtbl2 seq2 =
|
||||||
|
let h = Hashtbl.create 3 in
|
||||||
|
seq2 (fun k v -> Hashtbl.replace h k v);
|
||||||
|
h
|
||||||
|
|
||||||
let of_hashtbl h =
|
let of_hashtbl h =
|
||||||
from_iter (fun k -> Hashtbl.iter (fun a b -> k (a, b)) h)
|
from_iter (fun k -> Hashtbl.iter (fun a b -> k (a, b)) h)
|
||||||
|
|
||||||
|
let of_hashtbl2 h =
|
||||||
|
fun k -> Hashtbl.iter k h
|
||||||
|
|
||||||
let hashtbl_keys h =
|
let hashtbl_keys h =
|
||||||
from_iter (fun k -> Hashtbl.iter (fun a b -> k a) h)
|
from_iter (fun k -> Hashtbl.iter (fun a b -> k a) h)
|
||||||
|
|
||||||
|
|
|
||||||
10
sequence.mli
10
sequence.mli
|
|
@ -183,6 +183,8 @@ val of_array : 'a array -> 'a t
|
||||||
val of_array_i : 'a array -> (int * 'a) t
|
val of_array_i : 'a array -> (int * 'a) t
|
||||||
(** Elements of the array, with their index *)
|
(** Elements of the array, with their index *)
|
||||||
|
|
||||||
|
val of_array2 : 'a array -> (int, 'a) t2
|
||||||
|
|
||||||
val array_slice : 'a array -> int -> int -> 'a t
|
val array_slice : 'a array -> int -> int -> 'a t
|
||||||
(** [array_slice a i j] Sequence of elements whose indexes range
|
(** [array_slice a i j] Sequence of elements whose indexes range
|
||||||
from [i] to [j] *)
|
from [i] to [j] *)
|
||||||
|
|
@ -213,12 +215,18 @@ val hashtbl_replace : ('a, 'b) Hashtbl.t -> ('a * 'b) t -> unit
|
||||||
(** Add elements of the sequence to the hashtable, with
|
(** Add elements of the sequence to the hashtable, with
|
||||||
Hashtbl.replace (erases conflicting bindings) *)
|
Hashtbl.replace (erases conflicting bindings) *)
|
||||||
|
|
||||||
val to_hashtbl :('a * 'b) t -> ('a, 'b) Hashtbl.t
|
val to_hashtbl : ('a * 'b) t -> ('a, 'b) Hashtbl.t
|
||||||
|
(** Build a hashtable from a sequence of key/value pairs *)
|
||||||
|
|
||||||
|
val to_hashtbl2 : ('a, 'b) t2 -> ('a, 'b) Hashtbl.t
|
||||||
(** Build a hashtable from a sequence of key/value pairs *)
|
(** Build a hashtable from a sequence of key/value pairs *)
|
||||||
|
|
||||||
val of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) t
|
val of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) t
|
||||||
(** Sequence of key/value pairs from the hashtable *)
|
(** Sequence of key/value pairs from the hashtable *)
|
||||||
|
|
||||||
|
val of_hashtbl2 : ('a, 'b) Hashtbl.t -> ('a, 'b) t2
|
||||||
|
(** Sequence of key/value pairs from the hashtable *)
|
||||||
|
|
||||||
val hashtbl_keys : ('a, 'b) Hashtbl.t -> 'a t
|
val hashtbl_keys : ('a, 'b) Hashtbl.t -> 'a t
|
||||||
val hashtbl_values : ('a, 'b) Hashtbl.t -> 'b t
|
val hashtbl_values : ('a, 'b) Hashtbl.t -> 'b t
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue