What does [{:keys [var1 var2] :as something-else] mean in Clojure argument list?

Viewed 90

I am reading an open source project and trying to understand this function which is defined in a let statement:

handler (fn [{:keys [type request-id] :as msg}]
        ...
        )

Specifically, the argument list. What is {:keys [type request-id] :as msg} called, and what does it do?

1 Answers

It's called destructuring.

This particular case is analogous to

(fn [msg]
  (let [type        (get msg :type)
        request-id  (get msg :request-id)]
    ...))
Related