Generator
classin packageklyn.collections
public abstract class Generator<T> implements AutoClosable
Generator
All Implemented Interfaces: AutoClosable

Lazy, forward-only sequence produced by a function containing yield.

A generator is not a collection: it has no size, index or mutation API. Each call creates an independent cursor. Values are computed on demand; the cursor keeps its current value, not a history of the sequence. A completed or closed cursor cannot be restarted. for closes its generator on every exit, including break.

Example
import klyn.collections

def numbers() as Generator<Int>:
    yield 10
    yield 20

for number in numbers():
    print(number)
Properties
Modifier and Type Member Description
public abstract readonly property current
current as T
Reads the current element without advancing the generator.
Methods
Modifier and Type Member Description
public abstract close
close() as Void
Terminates iteration and executes active resource/finally cleanups once.
public abstract next
next() as Boolean
Advances to the next element without materializing the sequence.