What is the advantage of Currying in C#? (achieving partial function)

后端 未结 5 2064
情深已故
情深已故 2021-02-07 09:13

What is the advantage of Currying in C#?

What is the advantage of achieving partial function application on a curried function?

5条回答
  •  抹茶落季
    2021-02-07 10:05

    The advantage of Currying in C# is that it allows C# developers to develop in a Functional Programming style.

    Think about LINQ. A LINQ query allows you to pass in a method as a parameter:

    someCollection.Where(x => x.someVal == 1);
    

    x.someVal == 1 gets evaluated as a function and then Where uses the return value in its own execution.

    It's an example that most .NET 3 developers are familiar with, but few realize that they're dabbling in Function Programming. Without the ability to Curry, LINQ wouldn't be possible.

    ...hopefull that makes up for my smart-ass comment.

提交回复
热议问题