Question

I have a map like this:

(def my-map {43423 43.3, 63452 32.02, 823828 67.43, ...})

and a vector of keys that are in a different order:

(def my-keys [63452 823828 43423 ...])

How can I call the my-keys vector on my-map to pull out the values and maintain the order of the vector, as below?

;=> [32.02 67.43 43.3 ...] 

Any datatype returned is fine as long as the order is maintained.

Was it helpful?

Solution

Use map

(map my-map my-keys)
;=> (32.02 67.43 43.3)

This works because {} maps implement the function interface by looking up the argument in themselves.

({:foo 1 :bar 2} :bar)
;=> 2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top