liveBook · Manning

Partial application

As explained in Functional Programming in JavaScript

Partial application is the creation of a new function by binding some arguments of an existing function while leaving the remaining arguments to be supplied later.

Partial application creates a new callable by fixing some arguments of an existing function and leaving the rest for a later call. A five-parameter function can become one expecting only its remaining two parameters. The fixed values stay in the resulting function’s closure, and the later call evaluates the function. section 4.4

Create a more specific logger

Use Lodash to fix the logger’s first three arguments, then create an even more specific logger: const consoleLog = _.partial(logger, 'console', 'json', 'FJS Partial'); const consoleInfoLog = _.partial(consoleLog, 'INFO'); consoleInfoLog('INFO logger configured with partial'); Unlike a curried function, the remaining arguments are supplied together. Calling consoleLog with only one remaining argument evaluates the function rather than returning another function. section 4.4

How Functional Programming in JavaScript covers it

How deep it goes
Defines argument binding, contrasts partial application with currying, and supplies an implementation with placeholders.
Examples
Uses Lodash loggers, partially applied string methods, URL parsing, and a configurable scheduler.
What you can do after
Apply it via Lodash’s _.partial, including placeholder arguments, to create functions with fewer parameters.
How it connects
Connects partial application with currying, function binding, placeholders, closures, and functional composition.

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 Functional Programming in JavaScript. The section links point to the parts of the book it draws on.