From a2f8dcd6bd9c2ed9e50bd473ec9a3d9b4f7428de Mon Sep 17 00:00:00 2001 From: Rich Hickey Date: Sat, 29 Aug 2009 10:31:08 -0400 Subject: added arity overloads to comp --- src/clj/clojure/core.clj | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 992989e5..587e0953 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1508,13 +1508,28 @@ of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc." - [& fs] - (let [fs (reverse fs)] + ([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))))) + ret)))))) (defn partial "Takes a function f and fewer than the normal arguments to f, and -- cgit v1.2.3-70-g09d2