James Strieter
James Strieter

Reputation: 819

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

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?

Upvotes: 1

Views: 106

Answers (1)

Eugene Pakhomov
Eugene Pakhomov

Reputation: 10632

It's called destructuring.

This particular case is analogous to

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

Upvotes: 4

Related Questions