Created
April 17, 2017 16:24
-
-
Save nodew/5da9e275201314a5a0dad4beabd67ff7 to your computer and use it in GitHub Desktop.
compose functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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