Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Created April 10, 2012 14:33
Show Gist options
  • Save paulosuzart/2351780 to your computer and use it in GitHub Desktop.
Save paulosuzart/2351780 to your computer and use it in GitHub Desktop.
;;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