liveBook · Manning

Partial application

As explained in Functional Programming in Scala, Second Edition

Partial application is the creation of a function by supplying some arguments to a function while leaving the remaining arguments to be supplied later.

Partial application supplies some arguments to a function and returns a new function waiting for the rest. Its type signature sharply limits the possible implementation. section 2.5

Implementing partial1

A function accepting A and B and returning C becomes a function accepting B and returning C. The fixed A value is captured by the returned function: partial1(a, f) = (b: B) => f(a, b). section 2.5

Read the signature as a construction guide:

def partial1[A, B, C](a: A, f: (A, B) => C): B => C =
  (b: B) => f(a, b)

View the complete Scala implementation of partial1. section 2.5

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Derives the only compiling implementation from the return type and function literal, stopping at the basic pattern.
Examples
Uses partial1 with a fixed first argument and a two-argument function, alongside curry, uncurry, and compose signatures.
What it assumes
Builds anonymous-function understanding around basic function types and polymorphic type parameters.
What you can do after
Build it from scratch by returning a function that applies the fixed argument and later argument to f.
How it connects
Connects higher-order functions, polymorphism, anonymous functions, currying, uncurrying, and function 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 Scala, Second Edition. The section links point to the parts of the book it draws on.