RE: results from sort-by are not sorted

2019-05-07 Thread Sean Corfield
ou're not really alive." -- Margaret Atwood From: clojure@googlegroups.com on behalf of Justin Smith Sent: Monday, May 6, 2019 1:53:48 PM To: Clojure Subject: Re: results from sort-by are not sorted minor nitpick to the answer Sean provided: #{:age} as

Re: results from sort-by are not sorted

2019-05-06 Thread Justin Smith
minor nitpick to the answer Sean provided: #{:age} as a function returns :age for an argument equal to :age and nil for all other inputs, including a hash map containing that key. On Sun, May 5, 2019, 22:22 wrote: > Thanks. What a newbie question. > > 在 2019年5月6日星期一

Re: results from sort-by are not sorted

2019-05-05 Thread sheng . peisi . luo
Thanks. What a newbie question. 在 2019年5月6日星期一 UTC+8上午11:34:36,se...@corfield.org写道: > > (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.

RE: results from sort-by are not sorted

2019-05-05 Thread sean
(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 …)

Re: results from sort-by are not sorted

2019-05-05 Thread Bill Xie
clojure.core/sort-by ([keyfn coll] [keyfn comp coll]) Returns a sorted sequence of the items in coll, where the sort order is determined by comparing (keyfn item). If no comparator is supplied, uses compare. comparator must implement java.util.Comparator. Guaranteed to be stable: equal