File.FoldUtility Functions and Combinators for fold.
These functions make it easier to provide the function parameter to fold for certain use cases.
These functions are all folder's.
val noop : 'a foldernoop simply returns its accumulator.
Invariant: ∀dir s.t. File.Is.dir dir . (fold noop x dir = x)
val cons : string list foldercons is (fun _exn _depth x xs -> List.cons x xs).
Example: (fold cons [] ".") returns a list of all the files in the current directory, recursively, ignoring any directory traversal errors.
These functions all return a folder.
val elided : (string -> 'a -> 'a) -> 'a folderelided takes a function shaped like List.cons and returns one that ignores the exn and depth parameters.
I.e. (elided f = (fun _exn _depth x xs -> f x xs))
Example: (fold (elided List.cons) [] ".")
(prerr f) calls folder f preceded by printing any exception via (Exn.to_string >> prerr_endline).
Example:
File.Fold.(fold (prerr cons) [] ".") = File.Fold.(fold (prerr (elided List.cons)) [] ".")(err f) is folder f except any exception is raised.
Therefore, (err f) terminates the fold at the first exception.
(maxdepth n f) only applies folder f to the current path if the depth of recursion is <= n.
N.B. every directory under dir is still traversed (i.e. there is no short-circuiting), so using maxdepth will not significantly decrease the amount of time spent in traversal.