Created
March 22, 2020 15:26
-
-
Save dominem/052ad9f9764a0cf8bd3904a4efa39ffa to your computer and use it in GitHub Desktop.
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
(defn my-comp | |
([f g] | |
(fn [& args] | |
(f (apply g args)))) | |
([f g & fns] | |
(fn [& args] | |
(f (g (reduce (fn [result next-f] (next-f result)) | |
(apply (last fns) args) | |
(reverse (butlast fns)))))))) | |
(comment | |
((my-comp inc *) 2 3) | |
;; => 7 | |
((my-comp inc inc *) 2 3) | |
;; => 8 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment