yadda
yadda

Reputation: 197

Clojure: access map using multiple keys

I'm trying to access what I believe is a "map" using what I call "multiple keys" to pull out multiple, possibly even some of the same, values.

This is the kind of thing I'm trying to do (tried many variations, doesn't work):

(:a :b :c :b :a {:a "a" :b "b" :c "c"})

This is what I want or expect in response:

"a" "b" "c" "b" "a"

Anyone know how to do this?

Thanks.

Upvotes: 2

Views: 472

Answers (1)

RedDeckWins
RedDeckWins

Reputation: 2121

Does this work? the => shows what is returning from my REPL.

(map {:a "a" :b "b" :c "c"} [:a :b :c :b :a])
=> ("a" "b" "c" "b" "a")

You can also use a map as a function call, fyi.

if you want to avoid wrapping the keys in a collection, you could do something like:

(defn map-seq [m & ks]
  (map m ks))

(map-seq {:a "a" :b "b" :c "c"} :a :b :c :b :a)
=> ("a" "b" "c" "b" "a")

Upvotes: 4

Related Questions