In the end I choose a different way, maybe not the most elegant yet it works.
    
    
    Curve*[T] = object
        cp*: seq[T]
        ....
      
      ICurve*[T] = object
        cp*: iterator: T
        ....
      
      func linear*[T](cp: seq[T] or iterator:T): auto =
      var curve = when cp is iterator:T:
        ICurve[T]()
      else:
        Curve[T]()
      ....
      
      proc iterPoint*[T](curve: Curve[T] or ICurve[T], steps:float):auto=
      #create an "internal" closure, if needed, to get the same interface for
      #sequences and closure iterators as input to iterPoints.
      when curve.cp is seq[T]:
        func curvePoints (cps:seq[T]): auto=
          return iterator(): auto=
            for i in cps:
              yield i
        let cp = curvePoints(curve.cp)
      else:
        let cp = curve.cp
      ....
    
    
    
    Run

current state of the full code, a curve / spline library, is at 
<https://ingoogni.nl/tempstuff/curve.nim.txt> (needs vmath. needs pixie for the 
demo.)

I'll have to study the object variants, but the example kind of confused me.

Thanks

Reply via email to