What is the C# equivalent of map function in Haskell

后端 未结 5 1005
礼貌的吻别
礼貌的吻别 2021-02-01 00:34

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 paramet

5条回答
  •  心在旅途
    2021-02-01 00:44

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

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

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

提交回复
热议问题