Skip to content

Commit 43a4abf

Browse files
committed
Merge branch '0.11.4'
2 parents 1bb5d2e + e9ccd45 commit 43a4abf

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[![Build Status](https://secure.travis-ci.org/flatland/useful.png)](http://travis-ci.org/flatland/useful)
22

3+
![lein dependency](https://clojars.org/org.flatland/useful/latest-version.svg)
4+
35
These two repositories are usually identical:
46

57
* https://github.com/amalloy/useful

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject org.flatland/useful "0.11.3"
1+
(defproject org.flatland/useful "0.11.4"
22
:description "A collection of generally-useful Clojure utility functions"
33
:license {:name "Eclipse Public License - v 1.0"
44
:url "http://www.eclipse.org/legal/epl-v10.html"

src/flatland/useful/fn.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,19 @@
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)))))

test/flatland/useful/fn_test.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@
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))))))

0 commit comments

Comments
 (0)