File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 176176 (partial apply f))
177177
178178(def ap " A shorthand version of applied" applied )
179+
180+ (defn =to
181+ " Produces an equality predicate from a single object. ((=to x) y) is
182+ the same as (= x y), but if the returned function will be called many
183+ times it may be more efficient than repeated calls to =, because =to
184+ can short-circuit many irrelevant code paths based on knowing the type
185+ of x.
186+
187+ 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)))))
Original file line number Diff line number Diff line change 9090 by-square (key-comparator :ascending square)]
9191 (is (= (sort-by square [-9 -5 1 -2 ])
9292 (sort by-square [-9 -5 1 -2 ])))))
93+
94+ (deftest test-=to
95+ (let [objs [1 :x " x" [5 ] nil (Object. ) {:x 1 } '((a b c) d)]]
96+ (doseq [x objs
97+ y objs]
98+ (is (= (= x y) ((=to x) y))))))
You can’t perform that action at this time.
0 commit comments