Check out pedestals interceptors, they handle both error and pause/resume-request functionality. Seems you could have great use of it.
Pedestal-service is the repo. pedestal.io /Linus On Monday, July 21, 2014, Leon Grapenthin <grapenthinl...@gmail.com> wrote: > The predicate parameter introduces an additional predicate check on a > per-step basis which can be avoided under most circumstances. > > If check-auth or check-balance return just their input value where that is > valid, threading has no use here. > > They could be modified to only return something if there is an error, > otherwise nil. For clarity, they could then be called auth-error and > balance-error. They could be composed with some-fn and be used in a handler > to serve the error as early as possible. > > E. g. > > (def my-handler-error (some-fn auth-error balance-error)) > > (defn my-handler > [request] > (or (my-handler-error request) > ;; serve response > )) > > > > On Monday, July 21, 2014 6:20:50 PM UTC+2, Max Countryman wrote: >> >> Hi, >> >> Recently I found myself wanting a macro similar to some-> or some->> but >> one where I could specify an arbitrary predicate instead of nil?. For >> example, I have a Ring request map which I wish to pass through a number of >> functions. Any of these functions might return an error response and if so >> I do not want to evaluate any remaining forms—much like how some-> will not >> evaluate after a nil response. To do this, I wrote a macro that is >> essentially some-> but which takes a predicate. >> >> Here’s the macro I ended up with: >> >> (defmacro until-pred-> >> "Like some-> but evalutes via -> until or if a predicate is true." >> [pred expr & forms] >> (let [g (gensym) >> pstep (fn [step] >> `(if (~pred ~g) >> ~g >> (-> ~g ~step)))] >> `(let [~g ~expr >> ~@(interleave (repeat g) (map pstep forms))] >> ~g))) >> >> An example of how I might use this: >> >> (defn my-handler >> [request] >> (until-pred-> error-response? request >> check-auth >> check-balance >> …)) >> >> That said, I’m wondering if there is a more idiomatic way of passing Ring >> request maps through a series of functions, each of which might be a >> terminal step? I’m also curious if there’s a particular reason some-> >> wasn’t implemented in a more general way; perhaps the fact that I can so >> easily write a macro that achieves this myself is a good enough reason? >> >> Thanks, >> >> >> Max > > -- > 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 > <javascript:_e(%7B%7D,'cvml','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 > <javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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 > <javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');>. > For more options, visit https://groups.google.com/d/optout. > -- 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/d/optout.