Re: clojure.set/union bug?

2013-07-02 Thread Cedric Greevey
Still seems verbose compared to (into #{}) ... On Tue, Jul 2, 2013 at 4:41 AM, Ray Miller wrote: > On 2 July 2013 08:10, Cedric Greevey wrote: > >> Er...that won't use my custom comparator. :) >> > > Sorry, I thought it was clear how to generalize from my previous example. > Here it is with a

Re: clojure.set/union bug?

2013-07-02 Thread Ray Miller
On 2 July 2013 08:10, Cedric Greevey wrote: > Er...that won't use my custom comparator. :) > Sorry, I thought it was clear how to generalize from my previous example. Here it is with a custom comparator: (into (sorted-set-by >) [1 2 4 2 1 2 3]) ;; => #{4 3 2 1} > On Tue, Jul 2, 2013 at 2:40 A

Re: clojure.set/union bug?

2013-07-02 Thread Cedric Greevey
Er...that won't use my custom comparator. :) On Tue, Jul 2, 2013 at 2:40 AM, Ray Miller wrote: > On 1 July 2013 21:39, Cedric Greevey wrote: > >> >> What bugs me is that "sorted-set-by" needs "apply" to convert a coll into >> a sorted set; there's no short-and-pithy "into" for that case, and n

Re: clojure.set/union bug?

2013-07-01 Thread Ray Miller
On 1 July 2013 21:39, Cedric Greevey wrote: > > What bugs me is that "sorted-set-by" needs "apply" to convert a coll into > a sorted set; there's no short-and-pithy "into" for that case, and no > coll-taking and varargs version pair like vec/vector either. > (into (sorted-set) coll) -- -- You

Re: clojure.set/union bug?

2013-07-01 Thread Marcus Lindner
As it seems clojure.set/union can be used with maps as parameters too. =>(clojure.set/union {:a 1 :b 2 :c 3 :d 4} {:a 1 :b 4 :c 4}) {:a 1, :c 4, :b 4, :d 4} So it is possible to get a union of keys of a map with => (keys (clojure.set/union {:a 1 :b 2 :c 3 :d 4} {:a 1 :b 4 :c 4})) (:a :c :b :d) I

Re: clojure.set/union bug?

2013-07-01 Thread Jim - FooBar();
On 01/07/13 21:39, Cedric Greevey wrote: It's likely that "keys" returns a seq because you might care about the order in the case that you call it in a sorted map, and you can always convert it to a set with "into #{}" or whatever. yes, of course! I completely forgot the ordering issue..

Re: clojure.set/union bug?

2013-07-01 Thread Cedric Greevey
It's likely that "keys" returns a seq because you might care about the order in the case that you call it in a sorted map, and you can always convert it to a set with "into #{}" or whatever. What bugs me is that "sorted-set-by" needs "apply" to convert a coll into a sorted set; there's no short-an

Re: clojure.set/union bug?

2013-07-01 Thread Mark Engelberg
Expanding on what Jim said, you don't usually need to convert the keys of a map into a set, because the map pretty much acts like a set of its keys if you use contains? For example, (contains? {:a 1, :b 2} :a) tests whether :a is among the set of keys in the map. I believe that clojure.set's unio

Re: clojure.set/union bug?

2013-07-01 Thread Jim - FooBar();
On 01/07/13 20:02, Pablo Nussembaum wrote: This is pretty strange behavior to me, why is the case that keys function don't return a set like java? It doesn't need to be, does it?...the map itself ensures that there are no duplicate keys anyway. I guess it's one of those 'less is more' cases...

Re: clojure.set/union bug?

2013-07-01 Thread Pablo Nussembaum
Hi, This is pretty strange behavior to me, why is the case that keys function don't return a set like java? That could lead to a big penalty in performance if you don't realize this difference. I don't say that this is bug, although I would like to believe that a nice explanation exists ;-) Regard

Re: clojure.set/union bug?

2013-07-01 Thread Jim - FooBar();
HI there, It's pretty obvious what is happeningyou are not providing sets to union but rather seqs. in other words 'keys' return a seq not a set. union will simply conj all the elements from the first set into the second (or vice versa). if they are not sets they won't behave like sets...

clojure.set/union bug?

2013-07-01 Thread Goldritter
I wanted to create a union of the keys from two maps. When I write (clojure.set/union (keys {:a 1 :b 2 :c 3}) (keys {:a 1 :b 2 :c 3})) I get a result of (:b :c :a :a :c :b). When I write (set (clojure.set/union (keys {:a 1 :b 2 :c 3}) (keys {:a 1 :b 2 :c 3}))) the result is #{:a :c :b}. The doc