# Iterating structs of different types efficiently

**URL:** <https://discourse.julialang.org/t/iterating-structs-of-different-types-efficiently/102321>\
**Category:** General Usage\
**Tags:** type-stability\
**Created:** [July 31, 2023, 5:00pm UTC](https://discourse.julialang.org/t/iterating-structs-of-different-types-efficiently/102321 "2023-07-31T17:00:50Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 1, 2023, 10:12am UTC](https://discourse.julialang.org/t/iterating-structs-of-different-types-efficiently/102321/14 "2023-08-01T10:12:58Z")

</div>

There are some discussions about that here in the forum. One possible solution is to use a macro to do the splitting:

> [@Macro to write function with many conditionals](https://discourse.julialang.org/t/macro-to-write-function-with-many-conditionals/51616/8):
>
> It is even more simple then that. If all types are subtypes of some abstract class, then you can use subtypes function to generate list of all subtypes. It’s little more involved in case of parametric case, so I am not sure whether it is possible to write generic macro that can solve them all, but if you know you hierarchy beforehand you bend it appropriately. As an example for non parametric types, here is an adaptation of the ManualDispatch.jl function function \_unionsplit(type, x, call) …

(that is marked in other threads discussing the topic, and you can see then the other discussions)

---

_[View the full topic](https://discourse.julialang.org/t/iterating-structs-of-different-types-efficiently/102321)._
