Re: sorted-set-by drops elements

2010-04-16 Thread Sean Devlin
Here's the source for sorted-set-by: (defn sorted-set-by Returns a new sorted set with supplied keys, using the supplied comparator. ([comparator keys] (clojure.lang.PersistentTreeSet/create comparator keys))) This is because your comparator is saying that everything is equal.

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
It doesn't seem confusing to me. You are taking complete control of the set's local notion of ordering and equality. This is what I'd expect. Here's an example. First, a handy little function from Haskell: (defn on [key f] #(apply f (map key %))) Then: user (sorted-set-by (on :id compare)

Re: sorted-set-by drops elements

2010-04-16 Thread Razvan
Why should sorting be related to the primary key? You should be able to sort on any attribute. If you wanted to sort a set of people by age would it make sense to only retain one person of each age? Sort order and identity should be orthogonal. Besides, if you need a collection based on primary

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
Maybe the example was poorly picked but the point stands: if you're asking for a sorted set based on a comparator, you should expect duplicate elements as dictated by comparator to be eliminated. If you wanted to sort a set of people by age, you wouldn't use a sorted set but a sorted sequence.

Re: sorted-set-by drops elements

2010-04-16 Thread Sean Devlin
I think the fns you're interested in are sort and sort-by, not sorted- set-by. I know you might not like it, but there is a convention in JavaLand that a comparator value of 0 is identical in a sorted collection. This causes orthogonal concepts of order identity to be entwined. Sean On Apr 16,

Re: sorted-set-by drops elements

2010-04-16 Thread Sean Devlin
CORRECTION, DON'T SHOOT!! I should have order value, not order identity. On Apr 16, 1:01 pm, Sean Devlin francoisdev...@gmail.com wrote: I think the fns you're interested in are sort and sort-by, not sorted- set-by. I know you might not like it, but there is a convention in JavaLand

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
On Sat, Apr 17, 2010 at 12:01 AM, Sean Devlin francoisdev...@gmail.com wrote: I know you might not like it, but there is a convention in JavaLand that a comparator value of 0 is identical in a sorted collection. It's not a Java convention. It's intrinsic to the business of sorting. For sorting

Re: sorted-set-by drops elements

2010-04-16 Thread ataggart
The problem is you're unnecessarily conflating the value by which to base a sort (x and y in your example) with the elements of the set. Equality and ordinality are not the same thing. It should be perfectly reasonable to hand someone a set of unique objects sorted by some non-unique attribute of

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
Equality and ordinality are not the same thing.  It should be perfectly reasonable to hand someone a set of unique objects sorted by some non-unique attribute of the elements of the set. Sure, it's perfectly reasonable but it implies a different data structure. It sounds like you want a data

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
On Sat, Apr 17, 2010 at 1:05 AM, Per Vognsen per.vogn...@gmail.com wrote: You can only do slow linear-time lookups by traversing the tree's nodes exhaustively. Correction: You do not have to do a linear search on the whole tree but only on the subset of the tree for which the comparator returns

Re: sorted-set-by drops elements

2010-04-16 Thread Chris Perkins
On Apr 16, 8:25 am, Razvan gigi.clan...@gmail.com wrote: Hi, Is this the intended behavior? (sorted-set-by (constantly 0) 1 2 3 4) returns #{1}. I would expect the set to contain all the elements, and the comparator to only affect sort order. I expected the same thing at first, but the