You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/guides/destructuring.adoc
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ toc::[]
11
11
12
12
== What is Destructuring?
13
13
14
-
Destructuring is a way to concisely bind names to the values inside a data structure. Destructuring allows us to write more concise and readable code.
14
+
<<xref/../../reference/special_forms#binding-forms,Destructuring>> is a way to concisely bind names to the values inside a data structure. Destructuring allows us to write more concise and readable code.
15
15
16
16
Consider the following example of extracting and naming values in a vector.
17
17
@@ -57,7 +57,7 @@ An even more concise version of this would recursively destructure without needi
57
57
58
58
== Sequential Destructuring
59
59
60
-
Clojure destructuring is broken up into two categories, sequential destructuring and associative destructuring. Sequential destructuring represents a sequential data structure as a Clojure vector within a let binding.
60
+
Clojure destructuring is broken up into two categories, sequential destructuring and associative destructuring. <<xref/../../reference/special_forms#sequential-destructuring,Sequential destructuring>> represents a sequential data structure as a Clojure vector within a let binding.
61
61
62
62
This type of destructuring can be used on any kind of data structure that can be traversed in linear time, including lists, vectors, seqs, strings, arrays, and anything that supports `nth`.
63
63
@@ -223,7 +223,7 @@ When you have nested vectors, you can use `:as` or `&` at any level as well.
223
223
224
224
== Associative Destructuring
225
225
226
-
Associative destructuring is similar to sequential destructuring, but applied instead to associative (key-value) structures (including maps, records, vectors, etc). The associative bindings are concerned with concisely extracting values of the map by key.
226
+
<<xref/../../reference/special_forms#associative-destructuring,Associative destructuring>> is similar to sequential destructuring, but applied instead to associative (key-value) structures (including maps, records, vectors, etc). The associative bindings are concerned with concisely extracting values of the map by key.
227
227
228
228
Let's first consider an example that extracts values from a map without destructuring:
229
229
@@ -387,7 +387,7 @@ To support this style of invocation, associative destructuring also works with l
The use of keyword arguments had fallen in and out of fashion in the Clojure community over the years. They are now mostly used when presenting interfaces that people are expected to type at the REPL or the outermost layers of an API. In general, inner layers of the code found it easier to pass options as an explicit map. However, in Clojure 1.11 the capability was added to allow passing of alternating key->values, or a map of those same mappings, or even a map with key->values before it to functions expecting keyword arguments. Therefore, the call to `configure` above can take any of the following forms in addition to those shown above:
390
+
<<xref/../../reference/special_forms#keyword-arguments,Keyword arguments>> are mostly used when presenting interfaces that people are expected to type at the REPL or the outermost layers of an API. In general, inner layers of the code found it easier to pass options as an explicit map. However, in Clojure 1.11 the capability was added to allow passing of alternating key->values, or a map of those same mappings, or even a map with key->values before it to functions expecting keyword arguments. Therefore, the call to `configure` above can take any of the following forms in addition to those shown above:
391
391
392
392
[source,clojure]
393
393
----
@@ -447,7 +447,7 @@ You can even destructure using auto-resolved keywords, which will again be bound
447
447
448
448
Creating and destructuring maps with auto-resolved keywords allow us to write code using a namespace alias (here `p`) that is defined by a `require` in the current namespace, giving us a means of namespace indirection that can be changed at a single place in the code.
449
449
450
-
All symbols bound in the context of destructuring can be further destructured - this allows destructuring to be used in a nested fashion for both sequential and associative destructuring. It is less obvious, but this also extends to the symbol defined after `&`.
450
+
All symbols bound in the context of destructuring can be further destructured - this allows destructuring to be used in a <<xref/../../reference/special_forms#nested-destructuring,nested>> fashion for both sequential and associative destructuring. It is less obvious, but this also extends to the symbol defined after `&`.
451
451
452
452
This example destructures the `&` seq in place to decode the rest of the arguments as options (note that we are thus destructuring the two arguments sequentially and the rest associatively):
0 commit comments