Created
February 23, 2017 03:56
-
-
Save jackmott/988b4742394cf5e7d331e31c0ee778d6 to your computer and use it in GitHub Desktop.
iterate over a file in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open System.IO | |
| [<EntryPoint>] | |
| let main argv = | |
| //use gaurantees that the file handle is disposed when it goes out of scope | |
| use s = new StreamReader ("c:\path\to\text.txt") | |
| while not s.EndOfStream do | |
| let s = s.ReadLine() | |
| printfn "%s" s | |
| //or dump it into an array | |
| let arrayOfLines = | |
| [| | |
| use s = new StreamReader ("c:\path\to\text.txt") | |
| while not s.EndOfStream do | |
| yield s.ReadLine() | |
| |] | |
| 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment