I was hacking around with trying to use templates to combine inline iterators, 
and I wasn't successful, but I'm not sure what the problem is. 
    
    
    template chain(iter1, iter2: typed): typed =
      iterator res: string {.inline.} =
        for r1 in iter1():
          yield r1
        for r2 in iter2():
          yield r2
      res
    
    iterator thing1: string =
      yield "A"
      yield "B"
      yield "C"
      yield "D"
    
    iterator thing2: string =
      yield "E"
      yield "F"
      yield "cookiemonster"
    
    for thing in chain(thing1,thing2):
      echo(thing)
    

The error is "value of type 'iterator (): string{.inline, noSideEffect, gcsafe, 
locks: 0.}' has to be discarded; for a function call use ()"

It's pretty easy to make something like this work: 
    
    
    chain(dummyname,thing1,thing2)
    for thing in dummyname:
      ...
    

But I can't quite get the template to produce something that goes in the for 
statement itself.

* * *

The other problem is the iterators might not always yield a string, but it 
eludes me how to declare my wrapper iterator to return type(elementof(thing1))

Reply via email to