Skip to content

Instantly share code, notes, and snippets.

@nodew
Created April 17, 2017 16:24
Show Gist options
  • Save nodew/5da9e275201314a5a0dad4beabd67ff7 to your computer and use it in GitHub Desktop.
Save nodew/5da9e275201314a5a0dad4beabd67ff7 to your computer and use it in GitHub Desktop.
compose functions
(defun compose (&rest funcs)
"compose functions, (compose f g) => (f (g args))"
;; at least one function is required
(if (null funcs)
nil
(destructuring-bind (fn . rest) (reverse funcs)
#'(lambda (&rest arguments)
(reduce #'(lambda (v f)
(funcall f v))
rest
:initial-value (apply fn arguments))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment