From 4e86c8d8c769412b5e7242288ca25fe5b7a19bdd Mon Sep 17 00:00:00 2001 From: jjl Date: Sat, 18 Mar 2017 12:35:50 +0100 Subject: [PATCH 1/3] Less expensive lazy seq forcing --- src/special/core.cljc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/special/core.cljc b/src/special/core.cljc index 9c452eb..acca4f5 100644 --- a/src/special/core.cljc +++ b/src/special/core.cljc @@ -30,9 +30,12 @@ function result." [f] (fn [& args] - (let [res (apply f args) - _ (pr-str res)] - res))) + (let [res (apply f args)] + (if (instance? #?(:clj clojure.lang.IPending :cljs cljs.core.IPending) res) + (if (seq? res) + (doall res) + (force res)) + res)))) (defn manage "Takes a function f and an \"inlined\" map of conditions and keywords. From da11922fdaa2e12ab68b7ff3cd4c4b4fbe00041d Mon Sep 17 00:00:00 2001 From: jjl Date: Sun, 19 Mar 2017 14:59:50 +0100 Subject: [PATCH 2/3] force lazy seqs recursively --- src/special/core.cljc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/special/core.cljc b/src/special/core.cljc index acca4f5..9aaa3ed 100644 --- a/src/special/core.cljc +++ b/src/special/core.cljc @@ -24,18 +24,20 @@ (binding [*-special-condition-handlers-* (merge *-special-condition-handlers-* restarts)] (apply f args)))) +(defn- eager [v] + (if (instance? #?(:clj clojure.lang.IPending :cljs cljs.core.IPending) v) + (if (seq? v) + (doall (map eager v)) + (force v)) + v)) + (defn- eagerize "Turns a lazy function into an eager function, at the run-time cost of using pr-str to fully realize the function result." [f] (fn [& args] - (let [res (apply f args)] - (if (instance? #?(:clj clojure.lang.IPending :cljs cljs.core.IPending) res) - (if (seq? res) - (doall res) - (force res)) - res)))) + (eager (apply f args)))) (defn manage "Takes a function f and an \"inlined\" map of conditions and keywords. From 080d55369789c9902b4df9a53f60ae0450d498d2 Mon Sep 17 00:00:00 2001 From: jjl Date: Sun, 19 Mar 2017 15:13:44 +0100 Subject: [PATCH 3/3] Recursive eagerification --- src/special/core.cljc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/special/core.cljc b/src/special/core.cljc index 9aaa3ed..292a41b 100644 --- a/src/special/core.cljc +++ b/src/special/core.cljc @@ -1,4 +1,5 @@ -(ns special.core) +(ns special.core + (:require [clojure.walk :refer [postwalk]])) (defonce ^:dynamic *-special-condition-handlers-* {}) @@ -25,11 +26,7 @@ (apply f args)))) (defn- eager [v] - (if (instance? #?(:clj clojure.lang.IPending :cljs cljs.core.IPending) v) - (if (seq? v) - (doall (map eager v)) - (force v)) - v)) + (postwalk (constantly nil) v)) (defn- eagerize "Turns a lazy function into an eager function, at the