TextFile

Treat text files like lists of lines.

This API allows simple line by line processing of text files as lists of lines. It optionally supports indexing and early termination with pure or effectful functions.

"filename.txt"
|> File.open_reader!?
|> TextFile.walk_try!(0, |word_count, line|
    line
    |> Str.split_on(" ")
    |> List.drop_if(Str.is_empty)
    |> List.len
    |> Num.add(word_count))?

Refer to the test harnesses for more examples.

for_each_until_try! : File.Reader, (Str => [ Continue, Break, Err ]) => Result {}

for_each_try! : File.Reader, (Str => Result {} ) => Result {}

for_each_with_index_try! : File.Reader, (Str, U64 => Result {} ) => Result {}

for_each_with_index_until_try! : File.Reader, (Str, U64 => [ Continue, Break, Err ]) => Result {}

map_try! : File.Reader, (Str => Result a ) => Result (List a)

Map over the lines returned by a file reader.

map_with_index_try! : File.Reader, (Str, U64 => Result a ) => Result (List a)

walk_try! : File.Reader, a, (a, Str => Result a ) => Result a

walk_until_try! : File.Reader, a, (a, Str => [ Continue a, Break a, Err ]) => Result a

walk_with_index_until_try! : File.Reader, a, (a, Str, U64 => [ Continue a, Break a, Err ]) => Result a

walk_with_index_try! : File.Reader, a, (a, Str, U64 => Result a ) => Result a