Don't retain heads in side-effectful iterations

Replace forms iterating over collections for the purpose of side-effects
with alternatives which don't retain heads of collections.
This commit is contained in:
Jan Stępień 2015-11-24 18:48:47 +01:00
parent 7c9ccb2f3f
commit e278ce9f39

View file

@ -119,8 +119,7 @@
(let [done (atom [])] (let [done (atom [])]
(->> states (->> states
(sort-by (comp :order meta) order) (sort-by (comp :order meta) order)
(map #(fun % (meta %) done)) (run! #(fun % (meta %) done)))
doall)
@done)) @done))
(defn- merge-lifecycles (defn- merge-lifecycles
@ -160,17 +159,17 @@
(defn stop [& states] (defn stop [& states]
(let [states (or states (find-all-states)) (let [states (or states (find-all-states))
_ (doall (map unsub states)) ;; unmark substitutions marked by "start-with" _ (run! unsub states) ;; unmark substitutions marked by "start-with"
stopped (bring states down >)] stopped (bring states down >)]
(doall (map rollback! states)) ;; restore to origin from "start-with" (run! rollback! states) ;; restore to origin from "start-with"
{:stopped stopped})) {:stopped stopped}))
(defn stop-except [& states] (defn stop-except [& states]
(let [all (set (find-all-states)) (let [all (set (find-all-states))
states (remove (set states) all) states (remove (set states) all)
_ (doall (map unsub states)) ;; unmark substitutions marked by "start-with" _ (run! unsub states) ;; unmark substitutions marked by "start-with"
stopped (bring states down >)] stopped (bring states down >)]
(doall (map rollback! states)) ;; restore to origin from "start-with" (run! rollback! states) ;; restore to origin from "start-with"
{:stopped stopped})) {:stopped stopped}))
(defn start-with-args [xs & states] (defn start-with-args [xs & states]
@ -180,9 +179,8 @@
(start))) (start)))
(defn start-with [with] (defn start-with [with]
(doall (doseq [[from to] with]
(for [[from to] with] (substitute! from to))
(substitute! from to)))
(start)) (start))
(defn start-without [& states] (defn start-without [& states]