Difference between Seq and Array for array value

I am very new to F #.

I think arrays are still collections, so I could use Seqto iterate the array as follows:

[|"a"; "b"|] |> Seq.map (fun f -> printfn "a") |> ignore;;

But this does not work - it does not print anything. On the other hand, if I use Array, it prints the lines:

[|"a"; "b"|] |> Array.map (fun f -> printfn "a") |> ignore;;

Why is this?

+3
source share
2 answers

Array.mapbuilding another array - this means that he should do it with impatience. You cannot build an array and say, "I will fill in the values ​​when you want them."

, , ... , , . Seq.map:

, MoveNext , .

LINQ, Enumerable.Select ( ) Array.ConvertAll ( ).

, - . , Array.iter Seq.iter - .

+6

Seq.iter, , :

[|"a"; "b"|] |> Seq.iter (fun f -> printfn "%A" f);;

Array.iter, :

[|"a"; "b"|] |> Array.iter (fun f -> printfn "%A" f);;

( ) printfn "%A":

[|"a"; "b"|] |> printfn "%A";;

[|"a"; "b"|]. , F # , .

+5

Source: https://habr.com/ru/post/1766429/


All Articles