Function: -compose

-compose is a byte-compiled function defined in dash.el.

Signature

(-compose &rest FNS)

Documentation

Compose FNS into a single composite function.

Return a function that takes a variable number of ARGS, applies the last function in FNS to ARGS, and returns the result of calling each remaining function on the result of the previous function, right-to-left. If no FNS are given, return a variadic identity function.

View in manual

Source Code

;; Defined in ~/.emacs.d/elpa/dash-20260221.1346/dash.el
(defun -compose (&rest fns)
  "Compose FNS into a single composite function.
Return a function that takes a variable number of ARGS, applies
the last function in FNS to ARGS, and returns the result of
calling each remaining function on the result of the previous
function, right-to-left.  If no FNS are given, return a variadic
`identity' function."
  (declare (pure t) (side-effect-free error-free))
  (let* ((fns (nreverse fns))
         (head (car fns))
         (tail (cdr fns)))
    (cond (tail
           (lambda (&rest args)
             (--reduce-from (funcall it acc) (apply head args) tail)))
          (fns head)
          ((lambda (&optional arg &rest _) arg)))))