(sort-by #{:age} …) will use the set #{:age} as the keyfn, and both (#{:age} {:age 3, :name “luo”}) and (#{:age} {:age 1, :name “sheng”}) both return :age – because both maps contain the key in the set. As far as sort-by is concerned, both hash maps compare equal. What you want is (sort-by :age …) so you the keyfn pulls the value corresponding to :age out of the hash maps. That will produce 3 from {:age 3, :name “luo”} and 1 from {:age 1, :name “sheng”} so they will sort appropriately. Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN From: sheng.peisi....@gmail.com Hey there, in my lein repl, (sort-by #{:age} [{:age 3,:name "luo"},{:age 1,:name "sheng"}]) returns ({:age 3, :name "luo"} {:age 1, :name "sheng"}) rather than ({:age 1, :name "sheng"}, {:age 3, :name "luo"}). Why? -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. |
- results from sort-by are not sorted sheng . peisi . luo
- Re: results from sort-by are not sorted Bill Xie
- RE: results from sort-by are not sorted sean
- Re: results from sort-by are not sorted sheng . peisi . luo
- Re: results from sort-by are not sorted Justin Smith
- RE: results from sort-by are not sort... Sean Corfield