F# stream a text file line by line lazily
F#
open System.IO
let readLines (path: string) : seq<string> =
seq {
use reader = new StreamReader(path)
while not reader.EndOfStream do
yield reader.ReadLine()
}
// lazy: nothing is read until the sequence is enumerated
let countNonBlank path =
readLines path
|> Seq.filter (fun line -> not (System.String.IsNullOrWhiteSpace line))
|> Seq.length