Permalink
Browse files

Added Unixext.read_lines.

The function takes a file path, and returns a list of lines in the file.

Signed-off-by: Rok Strniša <rok.strnisa@citrix.com>
  • Loading branch information...
1 parent 576d68f commit a845e21f1d90ba25115d1c1bf36937f4420e7c41 @rokstrnisa rokstrnisa committed Jun 28, 2012
Showing with 6 additions and 0 deletions.
  1. +3 −0 stdext/unixext.ml
  2. +3 −0 stdext/unixext.mli
View
3 stdext/unixext.ml
@@ -127,6 +127,9 @@ let with_file file mode perms f =
let file_lines_fold f start file_path = with_input_channel file_path (lines_fold f start)
+let read_lines ~(path : string) : string list =
+ List.rev (file_lines_fold (fun acc line -> line::acc) [] path)
+
let file_lines_iter f = file_lines_fold (fun () line -> ignore(f line)) ()
let readfile_line = file_lines_iter
View
3 stdext/unixext.mli
@@ -37,6 +37,9 @@ val lines_iter : (string -> unit) -> in_channel -> unit
starting value [start]. *)
val file_lines_fold : ('a -> string -> 'a) -> 'a -> string -> 'a
+(** [read_lines path] returns a list of lines in the file at [path]. *)
+val read_lines : path:string -> string list
+
(** Applies function [f] to every line in the file at [file_path]. *)
val file_lines_iter : (string -> unit) -> string -> unit

0 comments on commit a845e21

Please sign in to comment.