# Stateful iterators with known eltype

**URL:** <https://discourse.julialang.org/t/stateful-iterators-with-known-eltype/93528>\
**Category:** General Usage\
**Tags:** question, iterators\
**Created:** [January 25, 2023, 6:46pm UTC](https://discourse.julialang.org/t/stateful-iterators-with-known-eltype/93528 "2023-01-25T18:46:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [January 25, 2023, 6:46pm UTC](https://discourse.julialang.org/t/stateful-iterators-with-known-eltype/93528/1 "2023-01-25T18:46:04Z")

</div>

`Iterators.Stateful` tries to determine the type of the `(value, state)` tuple using internal introspection tools. This can be complicated if the type of `state` keeps changing across iterations, and in such cases the inferred type of the `(value, state)` tuple defaults to `Any`. However, in my case, I do know the type of `value`, although the `state` might as well be `Any`. This knowledge of the type of the value helps with type-inference downstream. However, I don’t see a constructor that lets one specify the type of the value, which is also essentially the `eltype` of the iterator. Would it make sense to add one such constructor?
