c# - Map and Reduce in .NET - Stack Overflow

Linq equivalents of Map and Reduce: If you’re lucky enough to have linq then you don’t need to write your own map and reduce functions. C# 3.5 and Linq already has it albeit under different names.

  • Map is Select:
    Enumerable.Range(1, 10).Select(x => x + 2);
  • Reduce is Aggregate:
    Enumerable.Range(1, 10).Aggregate(0, (acc, x) => acc + x);
  • Filter is Where:
    Enumerable.Range(1, 10).Where(x => x % 2 == 0);