Skip to content

Commit

Permalink
Merge commit '6d1a' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
amalloy committed Oct 10, 2014
2 parents b655e5b + 6d1a6fb commit 2cce067
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/flatland/useful/fn.clj
Expand Up @@ -132,9 +132,9 @@
(transform y)."
([modifier]
(fn [a b]
(- (modifier a) (modifier b))))
(compare (modifier a) (modifier b))))
([direction modifier]
(let [f (comparator modifier)]
(let [f (key-comparator modifier)]
(condp #(% %2) direction
#{:desc :descending -} (comp - f)
#{:asc :ascending +} f))))
Expand Down
11 changes: 11 additions & 0 deletions test/flatland/useful/fn_test.clj
Expand Up @@ -79,3 +79,14 @@

(deftest test-ignoring-nils
(is (= 6 ((ignoring-nils +) 1 nil 2 nil nil 3))))

(deftest test-key-comparator
(let [subtract-comparator-fn-breaks-on-this [2147483650 2147483651
2147483652 4 2 3 1]
normal-cmp (key-comparator identity)]
(is (= (sort subtract-comparator-fn-breaks-on-this)
(sort normal-cmp subtract-comparator-fn-breaks-on-this))))
(let [square (fn [x] (* x x))
by-square (key-comparator :ascending square)]
(is (= (sort-by square [-9 -5 1 -2])
(sort by-square [-9 -5 1 -2])))))

0 comments on commit 2cce067

Please sign in to comment.