liveBook · Manning

Partial application

As explained in The Well-Grounded Rubyist, Fourth Edition

Partial function application is a functional programming technique that applies fewer arguments than a function's arity and returns a function accepting the remaining arguments.

Partial function application passes a function fewer arguments than its arity, evaluates the supplied arguments, and returns a function that accepts the rest. In Ruby, curry handles this behavior for Proc objects and methods. section 16.3.5

Specializing a reusable function

Define one generic function for finding multiples, then curry it and specialize the first argument: find_multiples_of.(3) and find_multiples_of.(5) produce functions for multiples of 3 and 5. Applying those functions to an array returns the matching elements.

Partial application returns one function after applying any supplied arguments. Currying instead describes a series of one-argument functions; Ruby's curry supports both grouped partial application and chained calls. section 16.3.5

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains arity, returned functions, chained calls, grouped arguments, and variadic behavior, while stopping short of implementation internals.
Examples
Uses addition, multiple-finding functions, chained calls, grouped calls, variadic summation, and a curried method.
What it assumes
Assumes familiarity with functions, Proc objects, lambdas, methods, and argument arity.
What you can do after
Apply it via Ruby's curry method to build specialized functions from lambdas, procs, or methods.
How it connects
Connects partial application with currying, functional programming, Proc objects, lambdas, methods, and arity.

Also explained in

Compare how 10 books explain partial application →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.