Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Seq.map and Seq.collect in F#

Tags:

In F#, what is the difference between functions "Seq.collect" and "Seq.map"? They seem equivalent from the description on MSDN.

like image 802
Manuel Avatar asked Jan 24 '10 13:01

Manuel


2 Answers

If you know LINQ, the following comparison may be useful:

F#: Seq.map, LINQ: Select

F#: Seq.collect, LINQ: SelectMany

like image 82
cfern Avatar answered Nov 28 '22 05:11

cfern


Seq.collect will first map each sequence element to a new sequence and flatten this sequences into a single one.

Seq.map will just map each element to a new element.

like image 28
Dario Avatar answered Nov 28 '22 06:11

Dario