What is the equivalent of C # map function in Haskell

The display function in Haskell has two input parameters. The first parameter is a function, and the second parameter is a list. The map function applies the function passed as an input parameter to all elements in the list and returns a new list.

Is there a C # equivalent for this function?

+60
c #
Jan 26
source share
5 answers

Select

MSDN Link

See my question here (Only if you are interested, as this is not directly related).

+70
Jan 26
source share

Another alternative to Select and SelectMany is to write your own extension method.

 public static IEnumerable<U> Map<T, U>(this IEnumerable<T> s, Func<T, U> f) { foreach (var item in s) yield return f(item); } 

Thanks to Wes Dyer for this sweet extension method! :) See more.

+16
Mar 29 '12 at 8:37
source share

Since Select and SelectMany have already been mentioned, I will answer an additional question that you did not ask: fold is like Aggregate .

Now everyone who reads this should be fully equipped to become the guy who writes X using the language idioms Y ... so for the sake of your fellow C # programmers, don't get carried away.

+13
Jan 27 '10 at 3:18
source share

And to answer a question that you didn't ask, the Haskell equivalent of a monad "sequence" binding is called SelectMany in C #. See Wes Dyer's article about this article:

http://blogs.msdn.com/wesdyer/archive/2008/01/11/the-marvels-of-monads.aspx

+10
Jan 26
source share

What about ConvertAll ? It looks like the one closest to the map.

+2
Jun 26 '14 at 13:29
source share



All Articles