2
votes

I'm guessing there's a simple way to do this that I'm not finding. I want to pass a map to a method that takes named values bound to keys, e.g.

(defn my-method [ & {:keys [ a b c ] }] ...

This works if called with e.g.

(my-method :a 1 :b 2 :c 3)

but I'd like to call it with a supplied map, e.g. something that looks like

(def m {:a 1 :b 2 :c 3})

(my-method m)

Is there a simple method to transform the map to the required argument list?

2

2 Answers

5
votes

It ain't pretty but:

(apply my-method (mapcat identity m))

or as suggested in the comments:

(apply my-method (apply concat m))
4
votes

Just drop the ampersand:

> (defn my-method [{:keys [a b c]}] (+ a b c))
> (my-method m)
6