The most idiomatic way is to not annotate and just let it fail when they are not iterable. But if you want the same function to work for scalars, you have two options:
- Annotate the scalar, and use the iterator one as fallback. This works well if you know what type of scalar you expect
- Annotate the iterator, and make a scalar fallback. This is what you’re asking for. You’ll need to constrain the available iterators.
AbstractArray
will catch quite a few of possibilities. AddTuple
and you have a lot.
There is no built-in interface system.