mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add CCIO.File.walk_iter
This commit is contained in:
parent
4783c635fd
commit
8e924c98be
2 changed files with 12 additions and 1 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
(** {1 IO Utils} *)
|
||||
|
||||
type 'a iter = ('a -> unit) -> unit
|
||||
type 'a or_error = ('a, string) result
|
||||
type 'a gen = unit -> 'a option
|
||||
|
||||
|
|
@ -33,6 +34,10 @@ let gen_of_array arr =
|
|||
Some x
|
||||
)
|
||||
|
||||
let rec gen_iter f g = match g() with
|
||||
| None -> ()
|
||||
| Some x -> f x; gen_iter f g
|
||||
|
||||
let gen_flat_map f next_elem =
|
||||
let state = ref `Init in
|
||||
let rec next() =
|
||||
|
|
@ -386,6 +391,7 @@ module File = struct
|
|||
*)
|
||||
|
||||
let walk_seq d = seq_of_gen_ (walk d)
|
||||
let walk_iter d = fun yield -> gen_iter yield (walk d)
|
||||
|
||||
let walk_l d =
|
||||
let l = ref [] in
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
*)
|
||||
|
||||
type 'a or_error = ('a, string) result
|
||||
type 'a iter = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
(** See [Gen] in the {{: https://github.com/c-cube/gen} gen library}. *)
|
||||
|
||||
|
|
@ -250,6 +251,10 @@ module File : sig
|
|||
symlinks, etc.)
|
||||
@raise Sys_error in case of error (e.g. permission denied) during iteration. *)
|
||||
|
||||
val walk_iter : t -> walk_item iter
|
||||
(** Like {!walk} but with an imperative iterator.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val walk_l : t -> walk_item list
|
||||
(** Like {!walk} but returns a list (therefore it's eager and might
|
||||
take some time on large directories).
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue