Is this answer on Stack overflow up to date? Is there a way to dispatch on whether an argument is iteratble? If not dispatch, is the given answer still the best practice? I would think not since there's mutable(?)/stateful(?) iterators where you can destroy elements by iterating, right?
There is, unfortunately, no good way. Julia does not have a real trait system for this.
You can use hasmethod(iterate, (T,)), but that is dynamic. The package Traits.jl has static_hasmethod, but I wouldn't rely on it to be stable.
There is a Base.isiterable, but that also just calls either hasmethod or applicable
there's no really good static way to do this today
It would be really cool to have a way to dispatch on this, i.e. a way to automatically get traits from the presence/absence of methods.
Of course, if function a dispatches on whether a method of b exists, that requires a backedge from b to a.
Alec has marked this topic as resolved.
Last updated: Oct 31 2025 at 04:43 UTC