Skip to content

Commit 05486df

Browse files
committed
Merge commit '@{1}' into develop
2 parents b655e5b + bbcae65 commit 05486df

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/flatland/useful/fn.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@
132132
(transform y)."
133133
([modifier]
134134
(fn [a b]
135-
(- (modifier a) (modifier b))))
135+
(compare (modifier a) (modifier b))))
136136
([direction modifier]
137-
(let [f (comparator modifier)]
137+
(let [f (key-comparator modifier)]
138138
(condp #(% %2) direction
139139
#{:desc :descending -} (comp - f)
140140
#{:asc :ascending +} f))))

test/flatland/useful/fn_test.clj

+11
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,14 @@
7979

8080
(deftest test-ignoring-nils
8181
(is (= 6 ((ignoring-nils +) 1 nil 2 nil nil 3))))
82+
83+
(deftest test-key-comparator
84+
(let [subtract-comparator-fn-breaks-on-this [2147483650 2147483651
85+
2147483652 4 2 3 1]
86+
normal-cmp (key-comparator identity)]
87+
(is (= (sort subtract-comparator-fn-breaks-on-this)
88+
(sort normal-cmp subtract-comparator-fn-breaks-on-this))))
89+
(let [square (fn [x] (* x x))
90+
by-square (key-comparator :ascending square)]
91+
(is (= (sort-by square [-9 -5 1 -2])
92+
(sort by-square [-9 -5 1 -2])))))

0 commit comments

Comments
 (0)