Here's a solution using reduce that handles passing multiple arguments into
the rightmost function:
(fn [& fns]
(fn [& args]
(let [[f & fns] (reverse fns)]
(reduce #(%2 %1) (apply f args) fns))))
On Sun, Aug 26, 2012 at 9:12 AM, Tyler Perkins <[email protected]>wrote:
> It might help to simplify. Whenever you're accumulating over a
> sequence of things, think of reduce:
>
> (let [__ (fn [& fs]
> ;; Here's the function:
> (reduce #(fn [x] (%1 (%2 x))) fs))
> ]
> ;; Testing:
> [ (= 5 ((__ (partial + 3) second) [1 2 3 4]))
> (= [3 2 1] ((__ rest reverse) [1 2 3 4]))
> ])
>
> Each step in the accumulation creates a new function that just applies
> the current function to an argument that is the result of applying the
> already-composed ones.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
--
Sam Ritchie, Twitter Inc
703.662.1337
@sritchie
(Too brief? Here's why! http://emailcharter.org)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en