tags:

views:

461

answers:

3

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

Is there a C# equivalent to this functionality?

+12  A: 

Select

MSDN Reference

See my question here (Only if you are curious as it is not directly related).

ChaosPandion
Thanks...This is a bit counter intuitive, I was thinking Select would filter rows from a collection.
BM
I really hope you check out my question.
ChaosPandion
BM: Filtering comes from Where.
Edward Kmett
+5  A: 

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

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

Eric Lippert
+4  A: 

Since Select and SelectMany were already mentioned, I'll answer an additional question you didn't ask: fold is found as Aggregate.

Now everyone reading this should be fully equipped to go be That Guy who writes Language X using Language Y idioms... so for the sake of your fellow C# programmers, don't get too carried away.

camccann
Now camccann, there is nothing wrong with throwing a functional wrench into your toolbox even though you are imperatively hammering nails. You may have to tighten a few bolts.
ChaosPandion
@camccan Functional C# is really pretty good. Just because the language isn't strictly functional doesn't mean that most .net programmers wouldn't hugely benefit from building things a *lot* more functionally.
Isaac Cambron
Using the functional programming features that C# offers is a great idea. Forcing C# into functional idioms that it doesn't support well (say, curried partial application as is so popular in Haskell), on the other hand, will probably give you a headache, obfuscate your code, and annoy anyone else who has to work with it.
camccann