Hi Didier The interceptor pattern is pretty tiny, certainly small enough to copy from project to project if you wanted. You can see re-frame's implementation here: https://github.com/Day8/re-frame/blob/master/src/re_frame/interceptor.cljc which is only around 100 SLOC. That doesn't handle exceptions like Pedestal, but shows the core of the idea.
On Mon, Oct 2, 2017 at 5:22 PM Didier <didi...@gmail.com> wrote: > I can't emphasize enough the utility of the interceptor chain pattern, as >> employed heavily in pedestal. >> > > Interesting... Its almost like a workflow framework, but for simpler in > code workflows. I'm reluctant to have a dependency on pedestal just for > this though. > > On Sunday, 1 October 2017 21:00:31 UTC-7, Luke Burton wrote: > >> >> On Sep 30, 2017, at 3:14 PM, Didier <did...@gmail.com> wrote: >> >> Is there another way to execute a set of complex steps which does not >> rely on let and can be try/catched in the manner I describe? >> >> >> I can't emphasize enough the utility of the interceptor chain pattern, as >> employed heavily in pedestal. >> >> I use this *everywhere* now. I have code that interleaves interceptors >> into a chain to augment them with timing information, audit logs, and more. >> I have written code that maps a subset of an interceptor chain over a >> cluster of machines, then reduces the results back down locally. Most >> importantly, they are fantastically useful when it comes time to debug a >> complex business process … you can swap interceptors in and out easily, >> isolate stateful interceptors to enable better mocking during tests, and >> more. >> >> Here's a basic application of interceptors. It's really not much code >> considering what you get. This doesn't even scratch the surface of what >> they can do. >> >> (ns interceptor.test >> (:require >> [io.pedestal.interceptor.chain :as chain])) >> >> (def step1 >> {:name :step1 >> :enter (fn [ctx] >> (let [x "sheep"] >> (assoc ctx :result x)))}) >> >> (def step2 >> {:name :step2 >> :error (fn [ctx ex-info] >> (println "so much for step2:" (:exception-type (ex-data >> ex-info)))) >> :enter (fn [{:keys [result] :as ctx}] >> >> (println "time to transform" result "into a number") >> (update ctx :result #(Long/parseLong %)))}) >> >> (defn run [] >> (chain/execute {} [step1 step2])) >> >> >> -- > 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. > -- 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.