liveBook · Manning

Partial

As explained in Clojure: The Essential Reference

partial is a Clojure function that returns a function with specified leading arguments pre-applied to a target function.

partial creates a function with leading arguments pre-applied, deferring invocation until additional arguments arrive. It suits higher-order uses where configuration is available before the remaining data. section 2.2.8

Its contract is simple but positional:

  • Accepts a target function and zero or more captured arguments; the target normally has at least one argument. section 2.2.8
  • Returns a variable-arity function that appends later arguments before calling the target. section 2.2.8
  • Captures only from the left, leaving missing arguments at the end; excess arguments can produce an ArityException. section 2.2.8

Configure a reusable function

(def incrementer (partial + 1)) (incrementer 1 1) ;; 3 (map (partial validate #{:id :cache :product}) requests) ;; (true false) Use fn when arguments must be supplied in arbitrary positions; partial is clearer when an existing function receives fixed leading configuration. section 2.2.8

How Clojure: The Essential Reference covers it

How deep it goes
Defines the contract, positional limitation, arity failure, and alternatives, but does not detail implementation internals.
Examples
Demonstrates incrementing, string searching, validation over sequences, reusable predicates, and comparisons with fn.
What you can do after
Apply partial to build reusable functions and compose configured operations with sequence-processing functions.
How it connects
Connects partial with higher-order functions, deferred invocation, currying, sequence processing, and anonymous functions.

Also explained in

Compare how 2 books explain partial →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.