iter

Generated by tinox doc

Functional list helpers (map, filter, reduce, zip, enumerate, cycle, repeat) plus a lazy range Iterator (Iter::range/rangeStep with hasNext/next), in the spirit of Python's itertools or Rust's Iterator trait.

ModuleVersionGroup
collections1.0.0tinox.core

Map filter reduce

import tinox.core.iter;

class Main
{
    fnc main() -> Int32
    {
        let numbers: List<Int64> = [1, 2, 3, 4, 5];

        let doubled: List<Int64> = Iter::map(numbers, n => n * 2);
        let evens: List<Int64> = Iter::filter(doubled, n => n % 4 == 0);
        let sum: Int64 = Iter::reduce(evens, 0, (acc, n) => acc + n);

        println("sum: " + sum.toString());

        let it: Iterator = Iter::range(0, 3);
        while it.hasNext()
        {
            println(it.next().toString());
        }
        return 0;
    }
}

class Iter

Methods

fn range(start: Int64, end: Int64) → Iterator
fn rangeStep(start: Int64, end: Int64, step: Int64) → Iterator
fn repeat(value: T, count: Int64) → List<T>
fn cycle(list: List<T>) → Iterator
fn enumerate(list: List<T>) → List<Pair<Int64, T>>
fn zip(a: List<T>, b: List<U>) → List<Pair<T, U>>
fn map(list: List<T>, transform: fn(T) -> U) → List<U>
fn filter(list: List<T>, predicate: fn(T) -> Bool) → List<T>
fn reduce(list: List<T>, initial: U, combiner: fn(U, T) -> U) → U

class Iterator

Fields

currentInt64
endInt64
stepInt64
dataList<Int64>
cycledBool

Methods

fn hasNext() → Bool
fn next() → Int64