Thanks **Calonger**
Very clever! Wrapping the _non-dispatchable_ **iterator** in a _dispatchable_
**method** makes so much sense.
Try a
import sequtils
type
Number = object of RootObj
Odd = object of Number
Even = object of Number
method sample(number: Number): iterator(): int =
result = iterator(): int =
for i in [1, 2, 3]:
yield i
method samp
Thanks for the quick response. Not the answer I was hoping for for but we don't
want to shoot the message :-)
Followup questions:
* Is there a recommended best practice for handling this type of situation?
* Maybe there a way of getting the actual _dispatch_ type (since _object_
**of** _kin
`iterator`s are statically dispatched so you need to change the type inside of
your typecheck branch and call the corresponding iterators. The only builtin
dynamic dispatch Nim has is `method`.
Question: How do I dispatch the appropriate **iterator** for an subclassed
object?
The following is a simple exemplar to clarify: ( _in the real world where would
be many more subclass types_ )
We have two objects: ( **one** and **two** ) which are inherited from a common
class ( **Number** )