Skip to content

Iterable

Giorgio Garofalo edited this page Dec 11, 2024 · 10 revisions

Iterable values are ordered lists or unordered set that can be iterated through a loop.

Types

Markdown list

An ordered or unordered Markdown list is automatically converted to an ordered iterable.

Note

This feature is currently limited:

  • The text content of each item is used as a dynamic value, allowing it to be adapted to any other type as invocation time;
  • Nested lists are not supported.
.var {letters}
  - A
  - B
  - C

.foreach {.letters}
  .lowercase {.1}

a

b

c

Pair

A pair is an iterable of two values.

It may be created via .pair {first} {second} or retrieved from a Dictionary's entry.

Dictionary

When used in a function which requires an iterable, a Dictionary value is used as a list of key-value pairs.

Range

An integer Range is a valid ordered iterable value.

 

Destructuring

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 iterate over a dictionary, which is an iterable of pairs (which are iterables):

.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