File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 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))))
Original file line number Diff line number Diff line change 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 ])))))
You can’t perform that action at this time.
0 commit comments