Created
April 10, 2012 14:33
-
-
Save paulosuzart/2351780 to your computer and use it in GitHub Desktop.
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
;;all the available sizes as a map with indexes. | |
;; ex {:pp 0, :p 1} | |
(def sizes | |
(apply hash-map | |
(flatten | |
(map-indexed | |
(fn [i s] (list (keyword s) i)) | |
'(pp, p, m, mm, g, gg, a, aa))))) | |
;; the comparator itself. takes s (the map of available sizes as argument) | |
;; returns a comparator the uses the supplied s for comparing two itens. | |
(defn compar [s] | |
(comparator (fn [x y] (< ((keyword x) s) ((keyword y) s))))) | |
;;sorting | |
(sort (compar sizes) '(g, a, gg, p)) | |
;;should return | |
;;(p g gg a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment