# How can you dispatch on Iterator eltype including generators?

**URL:** <https://discourse.julialang.org/t/how-can-you-dispatch-on-iterator-eltype-including-generators/20511>\
**Category:** General Usage\
**Created:** [February 6, 2019, 5:46pm UTC](https://discourse.julialang.org/t/how-can-you-dispatch-on-iterator-eltype-including-generators/20511 "2019-02-06T17:46:53Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 8, 2019, 2:25pm UTC](https://discourse.julialang.org/t/how-can-you-dispatch-on-iterator-eltype-including-generators/20511/11 "2019-02-08T14:25:09Z")

</div>

I don’t see how broadcasting would be better. Your example will end up calling `interface_get` with single elements, so you will be calculating `prework` over and over again. One way to solve that is using caching / lazy initialization like in Tamas’ link above (see [the Lazy struct I proposed](https://discourse.julialang.org/t/best-practice-approach-for-caching-data-in-objects/20419/5)). Then you could push the calculation of prework all the way to the lookup method (where the prework is accessed). Whether that’s better or not is hard to tell – in my experience lazy variables can make the code slightly more complex and increase the risk of errors, and the lazy indirection will also add a small overhead to the lookup (few nanoseconds if cached; probably acceptable unless the lookup is trivial like in the example above).

---

_[View the full topic](https://discourse.julialang.org/t/how-can-you-dispatch-on-iterator-eltype-including-generators/20511)._
