문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top