Is F# List.collect same as in C# List.SelectMany?

Viewed 1750

Are the List.collect equivalent of LINQ List.SelectMany?

[1;2;3;4] |> List.collect (fun x -> [x * x]) // [1;4;9;16]

in LINQ

new List<int>() { 1, 2, 3, 4 }
       .SelectMany(x => new List<int>() { x * x }); // 1;4;9;16

Edited:

More appropriate example

let list1 = [1;2;3;4]
let list2 = [2;4;6]

// [2; 4; 6; 4; 8; 12; 6; 12; 18; 8; 16; 24]
list1 |> List.collect (fun a -> list2 |> List.map (fun b -> a * b)) 

...

var list1 = new List<int>() { 1, 2, 3, 4 };
var list2 = new List<int>() { 2, 4, 6 }

// 2,4,6,4,8,12,6,12,18,8,16,24
list1.SelectMany(a => list2.Select(b => a * b)); 
4 Answers
Related