Module Deprecated.Find

Predefined Folders

A folder is a function suitable as the f parameter of fold.

val noop : 'a -> 'b -> 'c -> 'c

noop is a folder that simply returns its accumulator.

cons is (fun _ -> cons).

val cons : 'a -> 'b -> 'b list -> 'b list

cons is (fun _ -> cons).

Folder Combinators

These combinators convert functions of various shapes into folders.

val igndepth : ('a -> 'b -> 'c) -> 'd -> 'a -> 'b -> 'c

(igndepth f) returns a folder that ignores the depth parameter.

f should be a function like List.cons.

Example: collect all files into a list (assuming no errors):

  • (fold Find.(igndepth List.cons) [] ".")

(whenfile p f) returns a folder that invokes (f depth path acc) iff (p path = true).

Example: (fold Find.(whenfile Sys.is_directory cons) [] ".")

val whenfile : ('a -> bool) -> ('b -> 'a -> 'c -> 'c) -> 'b -> 'a -> 'c -> 'c

(whenfile p f) returns a folder that invokes (f depth path acc) iff (p path = true).

Example: (fold Find.(whenfile Sys.is_directory cons) [] ".")

(maxdepth d f) returns a folder that invokes f iff the depth <= d.

val maxdepth : 'a -> ('a -> 'b -> 'c -> 'c) -> 'a -> 'b -> 'c -> 'c

(maxdepth d f) returns a folder that invokes f iff the depth <= d.

(mindepth d f) returns a folder that invokes f iff the depth >= d.

val mindepth : 'a -> ('a -> 'b -> 'c -> 'c) -> 'a -> 'b -> 'c -> 'c

(mindepth d f) returns a folder that invokes f iff the depth >= d.

val ignore : ('a -> 'b -> 'c -> 'd) -> 'e -> 'a -> 'b -> 'c -> 'd

(ignore f) ignores errors, but still passes the pathname and accumulator to f.

(log hdl f) logs errors by passing a string representation of the exception to hdl, but still passes the pathname and accumulator to f.

Note that most errors will be Sys_error's and the string representation will contain the pathname.

val log : (string -> 'a) -> ('b -> 'c -> 'd -> 'e) -> exn -> 'b -> 'c -> 'd -> 'e

(log hdl f) logs errors by passing a string representation of the exception to hdl, but still passes the pathname and accumulator to f.

Note that most errors will be Sys_error's and the string representation will contain the pathname.

(prerr f) is (log prerr_endline f).

val prerr : ('a -> 'b -> 'c -> 'd) -> exn -> 'a -> 'b -> 'c -> 'd

(prerr f) is (log prerr_endline f).

val isdirectory : string -> bool

(isdirectory fn) is true if fn is a directory.

N.B. this differs from (Sys.is_directory fn) in that the latter will raise an exception if fn is a broken symlink, whereas isdirectory will simply return false.