Hello Ritchie!
I had almost the same:
(fn [& fs]
(let [f (last fs)
r (rest (reverse fs))]
(fn [& data] (reduce #(%2 %) (apply f data) r))))
But then I really liked your destructuring, so I'll take it with me:
(fn [& fs]
(let [[f & r] (reverse fs)]
(fn [& data] (reduce #(%2 %) (apply f data) r))))
Thanks a lot!
Le dimanche 26 août 2012 14:06:20 UTC-4, Sam Ritchie a écrit :
>
> 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]<javascript:>
> > 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]<javascript:>
>> 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] <javascript:>
>> 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
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.