Tuesday, March 2, 2010

Programmer - How read a file into a seq of lines in F#

Programmer Question

This is C# version:



public static IEnumerable<string> ReadLinesEnumerable(string path) {
using ( var reader = new StreamReader(path) ) {
var line = reader.ReadLine();
while ( line != null ) {
yield return line;
line = reader.ReadLine();
}
}
}


But directly translating needs a mutable variable.



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails