module main

struct SquareIterator {
	arr []int
mut:
	idx int
}

fn (mut iter SquareIterator) next[K]() ?K {
	if iter.idx >= iter.arr.len {
		return none
	}
	defer {
		iter.idx++
	}
	return iter.arr[iter.idx] * iter.arr[iter.idx]
}

fn main() {
	nums := [1, 2, 3, 4, 5]
	iter := SquareIterator{
		arr: nums
	}

	for squared in iter {
		println(squared)
	}
}
