Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of keys and values in maps

Tags:

clojure

When we call keys on a map, is the order of keys in the resulting seq guaranteed to be the same as the order of values when we call vals on the same map?

In other words, is it ok to map a function f over the contents of a map like this:

(map #(f %1 %2) (keys m) (vals m))

If not, is there an equivalent to perl's each in clojure? Or perhaps the inverse function of zipmap?

like image 554
kliron Avatar asked Aug 09 '11 09:08

kliron


1 Answers

You can iterate over the map, you get key val pairs,


(map (fn [[key val]]
       (println key val)) {:a :b :c :d})

pretty much all clojure data structures are seqable.

like image 153
Hamza Yerlikaya Avatar answered Nov 10 '22 00:11

Hamza Yerlikaya