Composition and point-free style
IntermediateComposing functions is the basic move of functional programming: you build big
behaviors by combining small ones. Clojure ships three core combinators —
comp, partial, and juxt — which together let you assemble new functions
without naming intermediate arguments. Code written this way is called
point-free or tacit: there are no "points" (argument names) cluttering
the picture.
Minimal example
comp glues functions right-to-left: (comp f g) is "first g, then f":
partial pre-fills the first arguments of a function and returns a new
function:
juxt runs several functions on the same input and returns a vector of their
results — a tiny "fork":
Practical example
Combine all three to build a small pipeline without ever naming the intermediate values:
Reading right-to-left at the inner comp: pull :score, multiply by 2.
juxt then forks each person into [name, doubled-score].
Point-free, with restraint
Point-free style is powerful but can become hard to read. A good rule of
thumb: prefer point-free for short compositions of well-known functions;
switch to a named lambda or let when the chain starts to obscure intent.
Check yourself
? quiz
`(comp f g h) x` is equivalent to which expression?
Exercise
Without using fn or #(), build a single function summary that maps a
person {:name ... :score N} to [name (* 2 N)]. Use juxt, comp,
and partial.