I have just started playing with F#, so this question will probably be quite basic…
I would like to read a text file line by line, and then ignore the first line and process the other lines using a given function. So I was thinking of using something along the lines of:
File.ReadAllLines(path)
|> Array.(ignore first element)
|> Array.map processLine
what would be an elegant yet efficient way to accomplish it?
There is no simple function to skip the first line in an array, because the operation is not efficient (it would have to copy the whole array), but you can do that easily if you use lazy sequences instead:
If you need the result in an array (as opposed to
seq<'T>, which is an F# alias forIEnumerable<'T>), then you can addSeq.toArrayto the end. However, if you just want to iterate over the lines later on, then you can probably just use sequences.