DECOUPLING PARAMETERS

Function or method calls can accept parameters — that is true in almost all programming languages. The underlying mechanisms to transfer the parameters and to make them available to the code executed in the function or method vary, and so does the terminology used to describe this process.

In most .NET languages the parameter list that is declared for a particular function is static. That means that the function in question can only be called with all the parameters at once. In fact, the notion of calling a function with an incomplete list of parameters probably strikes many C# programmers as rather odd. Nevertheless, this is exactly what currying is all about: splitting up the parameter list, so it becomes possible to call functions with an incomplete set of parameters.

You might think at this point that object oriented languages, or even imperative languages in general, have their own mechanisms for the purpose of providing convenient variants of functions or methods, for those cases where the standard implementations are found to be too complex to use. This is an absolutely correct association. Mechanisms like method overloading or extension methods have a similar purpose. However, the functional alternatives have advantages when it comes to function level reuse and modularization, which makes them an interesting option.

Manual Currying

Currying is a transformation technique that starts with a function with multiple parameters and converts it into a sequence ...

Get Functional Programming in C#: Classic Programming Techniques for Modern Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.