OxL Справочник OxL
РусскийEnglish

method Iterable.iter

A lazy sequence of the elements, in the order for visits them. Implement it to make a type usable in for and in the queries of from ... in.

Example:

oxl✓ проверяется в 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))}")
}
Вывод
30

A lazy sequence of the elements.

Example:

oxl✓ проверяется в CI
fn main() io {
  var total = 0
  for x in [1, 2, 3].iter() {
    total += x
  }
  print("{total}")
}
Вывод
6
fn iter() -> iter<T>

Сложность. O(1) to create.

С версии. 1.0.0-beta

Возвращает

iter<T>

Эффекты

не объявлены (чистая, пока тело не говорит иное)

Определено в: std/core/types.oxl:1123

См. также