Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# - convert Array to list

Tags:

arrays

list

f#

I am reading a file into an array like follows (note I know this is bad code):

let filename = if argv.[0] != null then argv.[0] else System.Console.ReadLine()
let data = File.ReadAllLines(filename)

I want to perform an F# map onto the data returned in that above line. My problem is that I can only perform map on n F# list, and not the System.String[] that File.ReadAllLines() returns. Can I convert a standard .Net array into an F# list. I'm sure that I could just read the file differently, or labor through manually copying the array contents to a list, but it would be a lot easier if there was a simple way to do this.

like image 459
James Parsons Avatar asked Dec 01 '15 02:12

James Parsons


People also ask

What does ⟨F⟩ mean?

This sound is usually considered to be an allophone of /h/, which is pronounced in different ways depending upon its context; Japanese /h/ is pronounced as [ɸ] before /u/. In Welsh orthography, ⟨f⟩ represents /v/ while ⟨ff⟩ represents /f/. In Slavic languages, ⟨f⟩ is used primarily in words of foreign (Greek, Latin, or Germanic) origin.

What does the letter F mean in math?

In countries such as the United States, the letter "F" is defined as a failure in terms of academic evaluation. Other countries that use this system include Saudi Arabia, Venezuela, and the Netherlands. In the hexadecimal number system, the letter "F" or "f" is used to represent the hexadecimal digit fifteen (equivalent to 15 10 ).

What does F stand for in the Etruscan alphabet?

In the Etruscan alphabet, 'F' probably represented /w/, as in Greek, and the Etruscans formed the digraph 'FH' to represent /f/.

Is the letter F doubled at the end of words?

It is often doubled at the end of words. Exceptionally, it represents the voiced labiodental fricative / v / in the common word "of". F is the twelfth least frequently used letter in the English language (after C, G, Y, P, B, V, K, J, X, Q, and Z ), with a frequency of about 2.23% in words.


Video Answer


1 Answers

You can use Array.toList to do that.

let data2 = data |> Array.toList

Or you can use List.ofArray

let data2 = data |> List.ofArray

You can also do Array.map instead of List.map and in that case you might not need to map to list at all.

like image 61
MarcinJuraszek Avatar answered Sep 19 '22 08:09

MarcinJuraszek