From f26be028f655c6d9118b3151970025aebfb55b05 Mon Sep 17 00:00:00 2001 From: kovan Date: Sat, 14 Mar 2026 20:04:40 +0100 Subject: [PATCH] Document destructuring of singleton map sequences Since Clojure 1.11 (CLJ-2603), associative destructuring of a sequence containing a single map binds directly to the map's contents. Verified against core.clj destructure/pmap function (lines 4472-4476): when the value is a seq with exactly one element, it uses (first gmap) directly rather than treating the seq as alternating key-value pairs. Fixes #688 --- content/guides/destructuring.adoc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/content/guides/destructuring.adoc b/content/guides/destructuring.adoc index 90021411..e6aa3846 100644 --- a/content/guides/destructuring.adoc +++ b/content/guides/destructuring.adoc @@ -346,6 +346,28 @@ Associative destructuring can be nested and combined with sequential destructuri ;= Joe is a Ranger wielding a Longbow ---- +=== Singleton map sequences + +Since Clojure 1.11, associative destructuring of a sequence containing a single map will bind directly to the map's contents. This means you can pass a map inside a one-element list or vector and destructure it as if it were a map: + +[source,clojure] +---- +(let [{:keys [a b]} (list {:a 1 :b 2})] + [a b]) +;;=> [1 2] +---- + +When the sequence contains more than one element, the elements are treated as alternating keys and values (the traditional behavior): + +[source,clojure] +---- +(let [{:keys [a b]} (list :a 1 :b 2)] + [a b]) +;;=> [1 2] +---- + +This behavior is useful when working with APIs that return a single map wrapped in a sequence. Note that an empty sequence destructures as an empty map. + === Keyword arguments One special case is using associative destructuring for keyword-arg parsing. Consider a function that takes options `:debug` and `:verbose`. These could be specified in an options map: