Default Nim iterators are always inlined, so they're not first-class. What you
want are closure iterators, they are first-class and can be passed around. For
example:
iterator myitems(x: string): char {.closure.} =
for elem in x:
yield x
var input = "ABCDEFGABF".myitems
for c in input:
echo c
Run
- Can iterators not be variables? emre
- Can iterators not be variables? Yardanico
- Can iterators not be variables? ElegantBeef
