From e278ce9f3927be7f38125940330d1e6615b5783e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20St=C4=99pie=C5=84?= Date: Tue, 24 Nov 2015 18:48:47 +0100 Subject: [PATCH 1/2] 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. --- src/mount/core.clj | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/mount/core.clj b/src/mount/core.clj index 8d3492f..9831a10 100644 --- a/src/mount/core.clj +++ b/src/mount/core.clj @@ -119,8 +119,7 @@ (let [done (atom [])] (->> states (sort-by (comp :order meta) order) - (map #(fun % (meta %) done)) - doall) + (run! #(fun % (meta %) done))) @done)) (defn- merge-lifecycles @@ -160,17 +159,17 @@ (defn stop [& 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 >)] - (doall (map rollback! states)) ;; restore to origin from "start-with" + (run! rollback! states) ;; restore to origin from "start-with" {:stopped stopped})) (defn stop-except [& states] (let [all (set (find-all-states)) 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 >)] - (doall (map rollback! states)) ;; restore to origin from "start-with" + (run! rollback! states) ;; restore to origin from "start-with" {:stopped stopped})) (defn start-with-args [xs & states] @@ -180,9 +179,8 @@ (start))) (defn start-with [with] - (doall - (for [[from to] with] - (substitute! from to))) + (doseq [[from to] with] + (substitute! from to)) (start)) (defn start-without [& states] From 3179ed223368027e42267e4bba26ef570f4ba572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20St=C4=99pie=C5=84?= Date: Tue, 24 Nov 2015 21:00:47 +0100 Subject: [PATCH 2/2] Replace run! with dorun and map This makes mount compatible with older Clojure versions again. --- src/mount/core.clj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mount/core.clj b/src/mount/core.clj index 9831a10..64e43e4 100644 --- a/src/mount/core.clj +++ b/src/mount/core.clj @@ -119,7 +119,8 @@ (let [done (atom [])] (->> states (sort-by (comp :order meta) order) - (run! #(fun % (meta %) done))) + (map #(fun % (meta %) done)) + dorun) @done)) (defn- merge-lifecycles @@ -159,17 +160,17 @@ (defn stop [& states] (let [states (or states (find-all-states)) - _ (run! unsub states) ;; unmark substitutions marked by "start-with" + _ (dorun (map unsub states)) ;; unmark substitutions marked by "start-with" stopped (bring states down >)] - (run! rollback! states) ;; restore to origin from "start-with" + (dorun (map rollback! states)) ;; restore to origin from "start-with" {:stopped stopped})) (defn stop-except [& states] (let [all (set (find-all-states)) states (remove (set states) all) - _ (run! unsub states) ;; unmark substitutions marked by "start-with" + _ (dorun (map unsub states)) ;; unmark substitutions marked by "start-with" stopped (bring states down >)] - (run! rollback! states) ;; restore to origin from "start-with" + (dorun (map rollback! states)) ;; restore to origin from "start-with" {:stopped stopped})) (defn start-with-args [xs & states]