Created
May 4, 2019 06:14
-
-
Save kannangce/e163cd4b501aa35fd7c169aa6894ebf5 to your computer and use it in GitHub Desktop.
Custom implementation of clojure 'comp'.
This file contains hidden or 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 custom-comp | |
"Custom implementation of clojure 'comp'. | |
Accepts a set of functions and returns a composite of | |
those functions. | |
ex, ((custom-comp f1 f2 f3) some-argument) = (f1(f2(f3(some-argument))))" | |
[& fns] | |
(fn [& params] | |
(loop [fn-list fns | |
args params] | |
(if (> 2 (count fn-list)) | |
((first fn-list) args) | |
(recur | |
(butlast fn-list) | |
((last fn-list) args)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment