# Rant: I hate that it's possible to iterate over an integer

**URL:** <https://discourse.julialang.org/t/rant-i-hate-that-its-possible-to-iterate-over-an-integer/77645>\
**Category:** New to Julia\
**Created:** [March 9, 2022, 6:09pm UTC](https://discourse.julialang.org/t/rant-i-hate-that-its-possible-to-iterate-over-an-integer/77645 "2022-03-09T18:09:49Z")\
**Posts on this page:** 2\
**Page:** 3

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 12, 2022, 12:49pm UTC](https://discourse.julialang.org/t/rant-i-hate-that-its-possible-to-iterate-over-an-integer/77645/42 "2022-03-12T12:49:54Z")

</div>

This issue is that this point of view suggests that `x` and `Ref(x)` should behave the same, ie that `collect(x) == collect(Ref(x))`. But while that’s true for numbers, it’s not true when `x` is a collection like `[1,2,3]` or `"abc"`. The counterargument is that this behavior is uniquely useful for array indices but that argument feels very thin to me.

---

<div class="post-metadata">

**Author:** ![Evey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evey/32/214967_2.png) [@Evey](https://discourse.julialang.org/u/Evey)\
**Post date:** [March 13, 2022, 10:22pm UTC](https://discourse.julialang.org/t/rant-i-hate-that-its-possible-to-iterate-over-an-integer/77645/43 "2022-03-13T22:22:46Z")

</div>

As an experienced user, I sometimes really like this behaviour. But I have team members who complain about this too, and I totally agree that it is a bit quirky, and wouldn’t mind if it went away.

As an aside, I don’t think it would be fair to claim that this behaviour is derived from a linear algebraic understanding of numbers. There seems to be very little linear algebra that goes into iteration schemes of other objects. The iteration scheme of a matrix, for example, is derived from the memory layout of the object. On the other hand, if numbers _were_ truly regarded as how one would typically understand them in a linear algebra context, they would be operators and closer in equivalence to a `UniformScaling`, which, by the way, does not support iteration 😏. However, as I recall, treating numbers as operators in a linear algebra context was met with a lot of opposition in discussions pre-1.0, and, although I used to be in favour, I’m now happy that it wasn’t implemented 😅

[Previous page](https://discourse.julialang.org/t/rant-i-hate-that-its-possible-to-iterate-over-an-integer/77645.md?page=2)
