Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Range expressions allows to define integer ranges that can used:

See Match, Slices and for for practical usages of ranges. For the moment, we just present in Table 1 the syntax to use when defining a range.

A Range being also an Iterator, we may use Iterator methods on it like rev(). See Table 2 for some interesting iterator methods.

Table 1:Range syntax

Range expression

Meaning

1..5

From 1 included to 5 excluded.

1..=5

From 1 to 5, both included.

..5 [1]

From start of object to 5 excluded.

..=5 [1]

From start of object to 5 included.

3.. [1]

From 3 included to end of object.

.. [2]

All indices of the whole object.

Table 2:Some methods of the Iterator trait

Method

Description

all(f)

Test if all elements satisfy the predicate f().

any(f)

Test if any element satisfies the predicate f().

chain(other)

Construct a new Iterator made of the two iterators in sequence.

collect()

Transform the iterator into a collection.

count()

Consume the iterator and return the number of iterations.

cycle()

Repeat endlessly.

enumerate()

Create a new Iterator of pairs (index, element).

filter(f)

Create a new Iterator that filters elements according to the closure f().

for_each(f)

Call the closure f() on each element.

map(f)

Create a new Iterator that applies a closure f onto each element.

max()

Return the max element.

min()

Return the min element.

product()

Multiply all elements.

reduce(f)

Reduce the elements using the reducing operator f().

rev()

Reverse the iterator.

skip(n)

Skip the n first elements.

step_by(n)

Step by the given amount.

sum()

Sum the elements.

take(n)

Yield only the n first elements.

unzip()

Convert an iterator of pairs into a pair of containers.

zip(other)

Zip two iterators into an iterator of pairs.

Footnotes
  1. Only allowed in a slice or a match.

  2. Only allowed in a slice.