On Sun, Nov 21, 2010 at 11:02 PM, Alex Baranosky <alexander.barano...@gmail.com> wrote: > Hi guys, > I'm trying to figure out how to use sort-by in reverse order. > something like: > (defn keyfn [p] > (:last-name p)) > (sort-by keyfn persons) > where persons is a map... > I don't see it in the docs, what's the idiomatic way to do this?
What's wrong with just using (reverse (sort-by foo my-map))? When you need a seq view, you can wrap it in reverse. When you don't, the sort order is irrelevant anyway. (For a reverse-sorted seq of just the keys, (reverse (sort-by foo (keys my-map))) works of course.) Note that sorting a map sorts by keys; if the map is persons to something else (e.g. account details or something) then you can sort it by last name, or if the keys are things like {:first-name "foo" :last-name "bar"} and the values are whole persons, but if you're trying to sort on a field of the values that isn't a field of the keys, you've got bigger problems than reversing the sort order. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en