Last active
August 29, 2015 13:56
-
-
Save skatenerd/8814785 to your computer and use it in GitHub Desktop.
lol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn sort-by-lambdas [lambdas to-sort] | |
(sort-by | |
#(mapv (fn [lambda] (lambda %)) lambdas) | |
to-sort)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;test | |
(describe "sorting" | |
(it "sorts by lowercased name" | |
(let [people [{:name "aaa"} {:name "BBB"}]] | |
(should= | |
["aaa" "BBB"] | |
(map :name (sort-by-lambdas [#(clojure.string/lower-case (:name %))] people))))) | |
(it "prioritizes one field over another" | |
(let [first-person {:age 22 :children 1} | |
second-person {:age 22 :children 100} | |
third-person {:age 30 :children 0}] | |
(should= | |
[first-person second-person third-person] | |
(sort-by-lambdas [:age :children] [first-person second-person third-person])) | |
(should= | |
[third-person first-person second-person] | |
(sort-by-lambdas [:children :age] [first-person second-person third-person]))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment