Functional? Not from the pure math perspective. Can math tell the difference? No. For the same inputs, the same outputs are guaranteed.* It is s Co-function. One who’s results are generated through time.
In the 70s, 80s there were, shall we say, old farts in mathematics. They claimed that computational mathematics was not really math. Fractals weren’t math. Eventually, someone proved the obvious. Numbers like e and pi are no different than a fractal expansion. The halting problem had be around for a few years. They are defined by mathematical functions, qed…
Iterators are no different than computing the next digit of pi. Fortunately, many are non-continuing rationals rather than an alternative. When dealing with process everything has state. The definition of process mean change happens over time.
Yes, iterators are functions.
But we live in a world of computers. Real computers can’t work as functions. Memory has a finite limit. Power can fail. Coffee can be spilled. An interruption the memory buss can intrude. As programmers, we pretend they don’t exist, mostly. As builders of systems, we must account for the last.
We just need to make sure those interrupts don’t disrupt the function. If we use the iterator for tail recursion, it’s easy. There are no other possible interactions. Use iterators. They are no different than immutable lists.
Shared iterators, mutable backing stores, those are problems. For the unwary, unordered sets are problematic. That is what give evangelists the willies. If they’d think it through, they would be fine. State isn’t bad. The computer has a stack or registers, after all. In math, a function that surprises us is still a function. Even functions with inverses can be unpredictable “trap door” functions.
Shared state isn’t even bad. It does make it difficult for good programmers to keep it from being problematic. It encourages bad programmers from ensuring problems. That’s the logic behind state=cooties.
Summary. State that isn’t shared isn’t bad. It’s a requirement.
*[Presuming the source is not designed to change — like I/O.]