Support destructuring maps with namespaced keywords


  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.5
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:


Current :keys destructuring expects symbols and creates local bindings based on those symbols. This works fine with maps that use non-namespaced keyword keys. This enhancement is to add support for destructuring maps with namespaced keyword keys.

;; typical key destructuring for keyword keys without namespaces
(let [{:keys [a b]} {:a 1 :b 2}] (+ a b))

;; WANT some way to destructure map with namespaced keys
(let [{:keys [????]} {:x/a 1 :y/b 2}] (+ a b))

Approach: Allow keywords (with or without namespaces) in :keys destructuring. Destructure to bindings with the name of the keyword (namespace is ignored).

;; this now works
(let [{:keys [x/a y/b]} {:x/a 1 :y/b 2}] (+ a b))

;; add support for putting keywords into :keys as well to support ::keywords
(let [{:keys [:x/a :y/b]} {:x/a 1 :y/b 2}] (+ a b))
(let [{:keys [::a]} {:user/a 1}] a)

;; syms will also now support namespaced symbols
(let [{:syms [x/a y/b]} {'x/a 1 'y/b 2}] (+ a b))

Patch: clj-1318-6.diff

Screened by: Stuart Sierra. See comments, below.

Doc TODO: Will need to update with new binding form.

  1. clj-1318-1.diff
    06/Jan/14 11:16 AM
    2 kB
    Alex Miller
  2. clj-1318-2.diff
    06/Jan/14 3:06 PM
    3 kB
    Alex Miller
  3. clj-1318-3.diff
    07/Jan/14 4:40 PM
    3 kB
    Alex Miller
  4. clj-1318-4.diff
    10/Jan/14 2:24 PM
    4 kB
    Alex Miller
  5. clj-1318-5.diff
    24/Jan/14 10:28 AM
    4 kB
    Alex Miller
  6. clj-1318-6.diff
    24/Jan/14 11:07 AM
    4 kB
    Alex Miller



Vote (0)
Watch (3)


  • Created: