regarding Ring, am I reinventing the wheel?
I have been working with Clojure for a few months now. I am now more familiar with it then I was even 3 months ago. I am now going back through some of the early code I wrote, and I see a lot of redundancy and mistakes. In particular, I notice this function that I wrote to handle the request map (in a web app that is using Ring and Compojure): (defn process-event [request] (let [request1 (process-pre-event-hooks request) request2 (process-page-specific-pre-page-hooks request1) request3 (process-mid-event-hooks request2) request4 (process-page-specific-post-page-hooks request3) request5 (process-post-event-hooks request4)] request5)) I could probably re-write all of this as Ring middleware, yes? Functions that take the request map, do something with it, and then return the new, modified request map -- that is what middleware is, yes? Or does middleware return a function that is then called on the request map? -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: regarding Ring, am I reinventing the wheel?
A Ring middleware function takes a handler as its argument, and returns a new handler, so you could write: (defn wrap-pre-event-hooks [handler] (fn [request] (handler (process-pre-event-hooks request However, I'm curious as to what all your process-* functions are actually doing. It seems strange to modify the request map so much. - James On 16 February 2013 00:14, larry google groups lawrencecloj...@gmail.comwrote: I have been working with Clojure for a few months now. I am now more familiar with it then I was even 3 months ago. I am now going back through some of the early code I wrote, and I see a lot of redundancy and mistakes. In particular, I notice this function that I wrote to handle the request map (in a web app that is using Ring and Compojure): (defn process-event [request] (let [request1 (process-pre-event-hooks request) request2 (process-page-specific-pre-page-hooks request1) request3 (process-mid-event-hooks request2) request4 (process-page-specific-post-page-hooks request3) request5 (process-post-event-hooks request4)] request5)) I could probably re-write all of this as Ring middleware, yes? Functions that take the request map, do something with it, and then return the new, modified request map -- that is what middleware is, yes? Or does middleware return a function that is then called on the request map? -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: regarding Ring, am I reinventing the wheel?
On Fri, Feb 15, 2013 at 4:14 PM, larry google groups lawrencecloj...@gmail.com wrote: (defn process-event [request] (let [request1 (process-pre-event-hooks request) request2 (process-page-specific-pre-page-hooks request1) request3 (process-mid-event-hooks request2) request4 (process-page-specific-post-page-hooks request3) request5 (process-post-event-hooks request4)] request5)) If you wanted to keep the same basic processing, you could use this much simpler code: (defn process-event [request] (- request process-pre-event-hooks process-page-specific-pre-page-hooks process-mid-event-hooks process-page-specific-post-page-hooks process-post-event-hooks)) -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.