Partial Application

Tango.Functional.PartialApplication

This static class contains several overloads for the Partial Application operation, where each overload deals with functions that contains different amounts of parameters, with or without a return.

Methods

Usage

The overloads available in this class can be used to create new functions from existing functions as well as Currying class.

In this example we'll consider an add function as a function that performs a sum of two numbers:

 Func<int, int, int> add = (value, value2) => value + value2;

With the application of the PartialApply function is created a new function as return, this function needs the last parameter of the sum and returns the result of this operation.

Func<int, int, int> add = 
    (value, value2) => value + value2;

Func<int, int> addPartial = PartialApplication.PartialApply(add, 2);
int partialResult = addPartial(3);

The major difference between Currying and Partial application is the fact that, when the partial application is used is also necessary inform at least one parameter to apply to the target function.

Other interesting fact about this operation in particular is its returns. Partial Application creates a new function just as Currying does, but this time, the created function must receive all remaining parameters.

The fundamentals about Partial Application and another examples can be find in Fundamentals > Currying and Partial Application.

Last updated