Skip to content

Commit 4000278

Browse files
committed
Make =to work on old old old versions of clojure
1 parent 2158d9f commit 4000278

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/flatland/useful/fn.clj

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,22 @@
177177

178178
(def ap "A shorthand version of applied" applied)
179179

180-
(defn =to
181-
"Produces an equality predicate from a single object. ((=to x) y) is
180+
(let [impl (delay (try (eval `(fn [x#]
181+
(if (keyword? x) ;; a case myssteriously not covered in equivPred
182+
(fn [y#]
183+
(identical? x# y#))
184+
(let [p# (clojure.lang.Util/equivPred x#)]
185+
(fn [y#]
186+
(.equiv p# x# y#))))))
187+
(catch Exception e ;; running some version prior to equivPred
188+
(fn [x] (fn [y] (= x y))))))]
189+
(defn =to
190+
"Produces an equality predicate from a single object. ((=to x) y) is
182191
the same as (= x y), but if the returned function will be called many
183192
times it may be more efficient than repeated calls to =, because =to
184193
can short-circuit many irrelevant code paths based on knowing the type
185194
of x.
186195
187196
Just a wrapper for clojure.lang.Util/equivPred."
188-
[x]
189-
(if (keyword? x) ;; a case myssteriously not covered in equivPred
190-
(fn [y]
191-
(identical? x y))
192-
(let [p (clojure.lang.Util/equivPred x)]
193-
(fn [y]
194-
(.equiv p x y)))))
197+
[x]
198+
(@impl x)))

0 commit comments

Comments
 (0)