Sample Video Frame
29: Partial Application
In partial application you create a function that already has one half of the calculation ready to go, and then use that function with other functions to complete the calculation. In the previous exercise you did this by establishing the left side of an addition, and then when you called the function you gave it the right hand side to complete the calculation. This is useful because there are functions that only receive limited parameters, but you have to change how they work or add another parameter to complete a calculation. With partial application you simply create a new function that "eats" some of the parameters.
In this exercise I'm going to use partial application, combined with data transformations to create a useful function called the
tee. This function works like a pipe in your plumbing which takes the water coming in and sends it out to two different directions. You could also call this a "fork" but that is confused with existing operations called fork in other contexts. In this case I'm using plumbing as my model for this function.
You can use this technique when you want to capture the result of a calculation in the middle of a chain of transformation calls. Partial application isn't limited to only this, but I find this is the most direct and useful way to use it.
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.