Skip to content

Commit

Permalink
Eradicate set- from the code base (#8)
Browse files Browse the repository at this point in the history
We are in Clojure so we can safely use assoc to indicate we use immutable data
structures.
  • Loading branch information
arichiardi authored Nov 18, 2018
1 parent 675e642 commit 2a68bfa
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/fonda/execute.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[fonda.step :as st]
[cljs.spec.alpha :as s]))

(s/fdef set-tap-result
(s/fdef assoc-tap-result
:args (s/cat :runtime-ctx ::r/runtime-context
:res any?))

(defn set-tap-result [{:as runtime-ctx :keys [anomaly?]} res]
(defn assoc-tap-result [{:as runtime-ctx :keys [anomaly?]} res]
(if (anomaly? res)
(assoc runtime-ctx :anomaly res)
runtime-ctx))
Expand Down Expand Up @@ -36,17 +36,17 @@
If an exception gets triggerd, an exception is added on the context.
If an anomaly is returned, an anomaly is added to the context"
[{:as runtime-ctx :keys [ctx log-step-fn]}
{:as step :keys [path name processor tap]}]
{:as step :keys [path name processor tap]}]
(try
(let [res (if processor (processor ctx) (tap ctx))
set-result-fn (cond
(not (nil? tap)) (partial set-tap-result runtime-ctx)
(not (nil? processor)) (partial assoc-processor-result runtime-ctx path))
set-result #(-> (set-result-fn %) (update :step-log log-step-fn step res))]
assoc-result-fn (cond
(not (nil? tap)) (partial assoc-tap-result runtime-ctx)
(not (nil? processor)) (partial assoc-processor-result runtime-ctx path))
assoc-result #(-> (assoc-result-fn %) (update :step-log log-step-fn step res))]

(if (a/async? res)
(a/continue res set-result #(assoc runtime-ctx :exception %))
(set-result res)))
(a/continue res assoc-result #(assoc runtime-ctx :exception %))
(assoc-result res)))

(catch :default e
(assoc runtime-ctx :exception e))))
Expand Down Expand Up @@ -143,4 +143,4 @@
(recur
(-> runtime-ctx
(assoc :queue (pop queue))
(try-step step)))))))
(try-step step)))))))

0 comments on commit 2a68bfa

Please sign in to comment.