Clojure - syntactic sugar to convert map entries to function params automatically?

clojure, dictionary, function

Solution

What I think you're looking for is destructuring. Here's what you can do:

(def mymap {:a1 1 :a2 2})

(defn my-adder [{:keys [a1 a2]}]
      (+ a1 a2))

(my-adder mymap)

You can learn more about it here.

Problem

Suppose I have the following clojure function call: ``` (def mymap {:a1 1 :a2 2}) (defn my-adder [input-map] (let [a1 (:a1 input-map) a2 (:a2 input-map)] (+ a1 a2))) (my-adder mymap) ``` What I'm looking for is for some way to make the my-adder function simpler by converting the map to params automatically - something like: ``` (defn my-adder [(magic-function input-map)] (+ a1 a2)) ``` Can someone point me to what I'm missing?

Original source