Efficient conversion from string [] to list F #

I come to F # from the C # background and am a little behind different lists and collections. I recently came across a situation where I needed to go from line [] to list T. I ended up using the list to make the cast:

let lines = File.ReadAllLines(@"C:\LinesOText.txt") // returns a string array
let listOLines = [for l in lines -> l] // use list comprehension to get the f# list

Is there a more efficient way to convert?

+5
source share
3 answers
+11
source

this should do it:

let lines = File.ReadAllLines(@"C:\LinesOText.txt") |> List.ofArray
+3
source

Here is another way to do this:

let listOfLines = [yield! File.ReadAllLines(@"C:\LinesOText.txt")]
+2
source

All Articles