Skip to content

Destructuring

Giorgio Garofalo edited this page Dec 11, 2024 · 1 revision

Destructuring

Destructuring is the operation that splits an element into its bare components. For instance, a pair has two components, while a generic iterable has many.

If the called function supports destructuring and the target type is destructurable, the operation is performed on the element's components rather than the element itself.

The following functions currently support destructuring:

The following types are destructurable:

For instance, when iterating via .foreach, if the elements are yet other iterables, using more than 1 lambda parameter lets the element be destructured into its components.

In the following example we define a Dictionary and iterate over its destructured key-value components:

.var {x}
  .dictionary 
    - a: 1
    - b: 2
    - c: 3

.foreach {.x}
    key value: <!-- 2 lambda parameters, one per pair component -->
    **.key** has value **.value**
Destructuring
Clone this wiki locally