I’m defining a handy function for me to flatten data recursively into matrices and tensors. One way to do it is to descend into the list-of-lists until we see something with length(x)==1, and then we consider that to be the element type of our tensor.
There’s a problem with this method, though. If my type is RGB{Float64}, this isn’t actually considered an “atomic” element, because length(RGB(rand(3)...))==3. On the other hand, there is no iterate method for RGB. So the approach fails because I’ve found something that has a length but cannot be iterated.
What is a better way to detect if a julia type is iterable or not? In principle, I would actually be able to choose between considering tuples as iterables or elementes. I don’t think there’s a isiterable method in Julia. And in fact, I’m not even sure why there’s a length(Float64), I can imagine there are types out there that have to length method, and I would like to support those as well.
So questions are:
- Is
RGBinconsistent by offering alengthbut noiterate? And - What are the best ways to decide if a type is iterable or not?