-
-
Notifications
You must be signed in to change notification settings - Fork 189
Destructuring
Destructuring is the operation that splits a lambda parameter into its bare components. For instance, a pair has two components, while a generic iterable has many.
The following types are destructurable:
-
Iterable
(includingPair
) -
Dictionary
(as an iterable of pairs)
A value is destructured into N
components if all the following conditions are met:
- Its type is destructurable;
- The lambda expects a single argument (such as
.foreach
); -
N > 1
lambda parameters are supplied.
When the lambda argument is destructured, the operation is performed on its components rather than the element itself.
In the following example we define a Dictionary and iterate over its destructured key-value components:
.var {mydictionary}
.dictionary
- a: 1
- b: 2
- c: 3
.foreach {.mydictionary}
key value: <!-- 2 lambda parameters = each pair is destructured into its 2 components -->
**.key** has value **.value**
a has value 1
b has value 2
c has value 3
In the following example we define a Dictionary and iterate over its destructured key-value components via .foreach
as in the previous example,
but only after sorting its entries by value via .sorted
, which takes a lambda that defines the ordering criteria.
Note
Remember that @lambda
is required when declaring an inline lambda.
.var {mydictionary}
.dictionary
- a: 3
- b: 1
- c: 2
.foreach {.mydictionary::sorted by:{@lambda name value: .value}}
name value:
.name
b
c
a
- Figures
- Image size
- TeX formulas
- Table caption
- Decorative headings
- Alerts (quote types)
- Quotation source
- Page breaks
- Text symbols (text replacement)
- Syntax of a function call
- Declaring functions
- Dynamic typing
- Including other Quarkdown files
- Importing external libraries
- Localization
- Document metadata
- Theme
- CSS
- Fonts
- Page format
- Page margin content
- Page counter
- Automatic page break
- Numbering
- Paragraph style
- Caption position
- Table of contents
- Bibliography
- Stacks (row, column, grid)
- Container
- Align
- Float
- Figure
- Clip
- Box
- Collapsible
- Whitespace
- Variables
- Optionality
- Math
- Conditional statements
- Loops
- Let
- Destructuring
- String manipulation
- Table manipulation: sorting, computing, and more
- Generators
- String
- Number
- Markdown content
- Boolean
- None
- Enumeration entry
- Iterable
- Dictionary
- Range
- Lambda
- Size(s)
- Color
- Dynamic
- Paper: abstract, definitions, theorems, and more