Skip to content

Instantly share code, notes, and snippets.

@kannangce
Created May 4, 2019 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kannangce/e163cd4b501aa35fd7c169aa6894ebf5 to your computer and use it in GitHub Desktop.
Save kannangce/e163cd4b501aa35fd7c169aa6894ebf5 to your computer and use it in GitHub Desktop.
Custom implementation of clojure 'comp'.
(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