Are keys and vals guaranteed to return in the same order?

2015-04-17 Thread Michael Blume
In other people's Clojure code I sometimes see things like (zipmap (map some-fn (keys m)) (map other-fn (vals m))) If it were my code I'd be much more inclined to write (into {} (for [[k v] m] [(some-fn k) (other-fn v)])) Is this a to-each-their-own thing or is the latter preferred?

Re: Are keys and vals guaranteed to return in the same order?

2015-04-17 Thread Ambrose Bonnaire-Sergeant
keys/vals are documented to return the same order as seq. This is a safe assumption. Thanks, Ambrose On Fri, Apr 17, 2015 at 5:39 PM, Michael Blume wrote: > > In other people's Cloj

Re: Are keys and vals guaranteed to return in the same order?

2015-04-17 Thread Ambrose Bonnaire-Sergeant
Clearly this assumes immutable maps. On Fri, Apr 17, 2015 at 5:42 PM, Ambrose Bonnaire-Sergeant < abonnaireserge...@gmail.com> wrote: > keys/vals are documented > > to return the same

Re: Are keys and vals guaranteed to return in the same order?

2015-04-17 Thread Andy Fingerhut
And it assumes that they are _identical_ maps that you are calling keys and vals on. Equal (via =) not-sorted maps do *not* guarantee that they will have the same seq order as each other, and in some cases do not, due to hash collisions in hash maps having items in a linked list in whatever order

Re: Are keys and vals guaranteed to return in the same order?

2015-04-18 Thread Allen Rohner
On Friday, April 17, 2015 at 4:40:07 PM UTC-5, Michael Blume wrote: > > > In other people's Clojure code I sometimes see things like > > (zipmap > (map some-fn (keys m)) > (map other-fn (vals m))) > > If it were my code I'd be much more inclined to write > > (into {} > (for [[k v] m] > [

Re: Are keys and vals guaranteed to return in the same order?

2015-04-19 Thread Thumbnail
*Is order guaranteed?* For any map m, (= m (zipmap (keys m) (vals m))) ... is guaranteed. But, for two maps m1 and m2, (= m1 m2) ... does *not* imply (= (seq m1) (seq m2)) *Which version to prefer?* It's worth looking at what the Clojure Cookbook does

Re: Are keys and vals guaranteed to return in the same order?

2015-04-19 Thread Thumbnail
... For example (let [m1 (array-map 1 2, 3 4) m2 (array-map 3 4, 1 2)] [(= m1 m2) (= (seq m1) (seq m2))]) => [true false] -- 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