OxL Reference

interface Iterable

Source for for and queries (§4.6): a type whose iter() returns a lazy iter<T> (D-2002).

Example:

oxl✓ checked in CI
fn main() io {
  var total = 0
  for x in [1, 2, 3].iter() {
    total += x
  }
  print("{total}")
}
Output
6

Example:

oxl✓ checked in CI
data Triple {
  base: i64
}

impl Triple {
  fn iter() -> iter<i64> => [base, base * 2, base * 3].iter()
}

fn total<I: Iterable<i64>>(xs: I) -> i64 {
  var s = 0
  for x in xs { s += x }
  s
}

fn main() io {
  print("{total(Triple(base: 5))} {total([1, 2, 3])}")
}
Output
30 6
pub(api) interface Iterable<T>

Complexity. O(1) to create.

Since. 1.0.0-beta

Methods

iter() -> iter<T>
A lazy sequence of the elements, in the order for visits them.

Defined in: std/core/types.oxl:1080

See also