Skip to content

Iterable

Giorgio Garofalo edited this page Apr 30, 2025 · 17 revisions

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

Iterables can also be destructured: see Destructuring for more.

Collection

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

.var {letters}
  - A
  - B
  - C

.foreach {.letters}
  .1::lowercase

a

b

c

Nested collections can be represented by nested Markdown lists as well:

.var {letters}
  - - A
    - B
  - - C
    - D
  - - E
    - F

.foreach {.letters}
  .1::first

A

C

E

Pair

A pair is an iterable of two values.

It may be created via .pair {first} {second} or retrieved as a Dictionary 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.

Operations

Assuming myiterable to be an iterable, the following operations via .myiterable::operation are valid.

  • getat {index} {orelse?} (note that indexes start at 1)
  • first
  • second
  • third
  • last
  • size
  • sumall
  • average
  • distinct
  • sorted {by?}
  • reversed
  • groupvalues

For a complete reference and documentation, please check the Collection stdlib module.

Clone this wiki locally