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
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
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
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
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
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..
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
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
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...
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
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...
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
12 matches
Mail list logo