mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 03:05:29 -05:00
iterate on integers
This commit is contained in:
parent
bd7ecf0b96
commit
57b778f6cc
3 changed files with 17 additions and 0 deletions
|
|
@ -66,3 +66,10 @@ module Hashtbl =
|
||||||
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Int =
|
||||||
|
struct
|
||||||
|
let range ~start ~stop =
|
||||||
|
let seq_fun k =
|
||||||
|
for i = start to stop do k i done
|
||||||
|
in { seq_fun; }
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -45,3 +45,11 @@ module Hashtbl :
|
||||||
val of_seq : ('a * 'b) t -> ('a, 'b) Hashtbl.t
|
val of_seq : ('a * 'b) t -> ('a, 'b) Hashtbl.t
|
||||||
val to_seq : ('a, 'b) Hashtbl.t -> ('a * 'b) t
|
val to_seq : ('a, 'b) Hashtbl.t -> ('a * 'b) t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(** Iterate on ranges of ints *)
|
||||||
|
module Int :
|
||||||
|
sig
|
||||||
|
val range : start:int -> stop:int -> int t
|
||||||
|
(** Iterator on [start...stop] by steps 1 *)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
||||||
2
tests.ml
2
tests.ml
|
|
@ -22,8 +22,10 @@ let _ =
|
||||||
(Sequence.map (fun (x, y) -> (string_of_int x) ^ " -> " ^ (string_of_int y))
|
(Sequence.map (fun (x, y) -> (string_of_int x) ^ " -> " ^ (string_of_int y))
|
||||||
(Sequence.Hashtbl.to_seq h))
|
(Sequence.Hashtbl.to_seq h))
|
||||||
in
|
in
|
||||||
|
let l3 = Sequence.List.of_seq (Sequence.Int.range ~start:0 ~stop:42) in
|
||||||
Format.printf "l=@[<h>[%a]@]@." (pp_list Format.pp_print_int) l;
|
Format.printf "l=@[<h>[%a]@]@." (pp_list Format.pp_print_int) l;
|
||||||
Format.printf "l'=@[<h>[%a]@]@." (pp_list Format.pp_print_int) l';
|
Format.printf "l'=@[<h>[%a]@]@." (pp_list Format.pp_print_int) l';
|
||||||
Format.printf "l''=@[<h>[%a]@]@." (pp_list Format.pp_print_int) l'';
|
Format.printf "l''=@[<h>[%a]@]@." (pp_list Format.pp_print_int) l'';
|
||||||
Format.printf "l2=@[<h>[%a]@]@." (pp_list Format.pp_print_string) l2;
|
Format.printf "l2=@[<h>[%a]@]@." (pp_list Format.pp_print_string) l2;
|
||||||
|
Format.printf "l3=@[<h>[%a]@]@." (pp_list Format.pp_print_int) l3;
|
||||||
()
|
()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue