interface Iterable
Source for for and queries (§4.6): a type whose iter() returns a lazy iter<T> (D-2002).
Example:
fn main() io {
var total = 0
for x in [1, 2, 3].iter() {
total += x
}
print("{total}")
}Вывод
6
Example:
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])}")
}Вывод
30 6
pub(api) interface Iterable<T>Сложность. O(1) to create.
С версии. 1.0.0-beta
Методы
iter | () -> iter<T>A lazy sequence of the elements, in the order for visits them. |
Определено в: std/core/types.oxl:1080