Skip to content

Commit 1a8dca4

Browse files
committed
WiP, nested :select, :or, :defaults
1 parent a6ab561 commit 1a8dca4

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

content/guides/destructuring.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,21 @@ Associative destructuring can be nested and combined with sequential destructuri
399399
;= Joe is a Ranger wielding a Longbow
400400
----
401401

402+
With nested destructuring, the use of `:or`, `:defaults`, and `:select` only apply at the level at which they are applied:
403+
404+
[source,clojure]
405+
----
406+
(let [{{:keys [class weapon name], :or {:name "Sir Joe"}, :defaults jdf, :select joe} :joe
407+
npc :npc
408+
:or {npc {:class "Farmer", :weapon "Shovel"}}} multiplayer-game-state]
409+
(println "Joe's :select data is" joe)
410+
(println name "had his name set as a default from the :or map" jdf)
411+
(println "The default unnamed NPC is" npc))
412+
;= Joe's :select data is {:weapon "Longbow", :name "Sir Joe", :class "Ranger"}
413+
;= Sir Joe had his name set as a default from the :or map {:name "Sir Joe"}
414+
;= The default unnamed NPC is {:class "Farmer", :weapon "Shovel"}
415+
----
416+
402417
=== Keyword arguments
403418

404419
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:

0 commit comments

Comments
 (0)