File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 132
132
(transform y)."
133
133
([modifier]
134
134
(fn [a b]
135
- (- (modifier a) (modifier b))))
135
+ (compare (modifier a) (modifier b))))
136
136
([direction modifier]
137
- (let [f (comparator modifier)]
137
+ (let [f (key- comparator modifier)]
138
138
(condp #(% %2 ) direction
139
139
#{:desc :descending -} (comp - f)
140
140
#{:asc :ascending +} f))))
Original file line number Diff line number Diff line change 79
79
80
80
(deftest test-ignoring-nils
81
81
(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