I am writing an iterator which calls walkDir and iterates over all of the files 
in the dir creating objects from those files. I have a proc which reads the 
file and creates a seq of the objects. It works fine. Amazingly so, on my 
machine Nim will read one of these files and create almost 400k objects in 40ms.

I want an iterator which iterates over each of these files, serving each of its 
objects one at a time.
    
    
    iterator pricestream*(source: string, instrument: Instrument): Price =
      ## Iterator for all historic prices for the source, and instrument.
      var paths: seq[string]
      for file in walkDir(datapath / source / $instrument / "Prices"):
        paths.add(file.path)
      paths.sort(system.cmp[string])
      for path in paths:
        for price in pricesFromCsv(path):
          yield price
    
    # If I call like this:
    
    var stream = pricestream("oanda", EUR_USD)
    for p in stream:
      ...
    
    # I get this:
    # ntplayground.nim(46, 27) Error: attempting to call undeclared routine: 
'pricestream'
    
    # If I call like this:
    var stream = pricestream
    for p in stream("oanda", EUR_USD):
      ...
    
    # I get this:
    # ntplayground.nim(47, 18) Error: type mismatch: got <Price>
    # but expected one of:
    # iterator items[T](a: set[T]): T
    # ...
    
    
    Run

Any help in understanding how to write and call an iterator (this iterator) 
would be greatly appreciated.

Reply via email to