Created
August 18, 2010 19:37
-
-
Save fogus/535901 to your computer and use it in GitHub Desktop.
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 comp+ | |
([] identity) | |
([f] f) | |
([f g] | |
(fn | |
([] (f (g))) | |
([x] (f (g x))) | |
([x y] (f (g x y))) | |
([x y z] (f (g x y z))) | |
([x y z & args] (f (apply g x y z args))))) | |
([f g h] | |
(fn | |
([] (f (g (h)))) | |
([x] (f (g (h x)))) | |
([x y] (f (g (h x y)))) | |
([x y z] (f (g (h x y z)))) | |
([x y z & args] (f (g (apply h x y z args)))))) | |
([f1 f2 f3 & fs] | |
(let [fs (reverse (list* f1 f2 f3 fs))] | |
(fn [& args] | |
(loop [ret (apply (first fs) args) fs (next fs)] | |
(if fs | |
(recur ((first fs) ret) (next fs)) | |
ret)))))) | |
;; allowing | |
(for [f (map #(apply comp+ %) | |
[[keyword name] | |
[] | |
[name clojure.string/upper-case]]) | |
e '[foo bar]] | |
(f e)) | |
;=> (:foo :bar foo bar "FOO" "BAR") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment