2

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.

1 Answer 1

4

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")
Sign up to request clarification or add additional context in comments.

2 Comments

((juxt :a :b :c :b :a) {:a "a" :b "b" :c "c"}) would also work
juxt is the right and proper answer. it's self juxtafied ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.