|
|
|
|
|
by 1718627440
254 days ago
|
|
If the iterator abstracts the iteration away, it should also abstract over the modification. > Like you cause any other simple bug. Yes, but we don't forbid modifying other things, just because you could modify them by accident, because you want to modify them some of the time. Why does a[i] = ... needs to be prevented, but a = ... is fine? |
|
That's no longer a simple iterator; it's a collection wrapper that represents in-iteration collection. It can be useful, and it is possible to write! But I don't think this is what programming languages should offer as their default iterator. Also, how do you solve the problem of mutation done through the collection without involving the iterator?
> Yes, but we don't forbid modifying other things, just because you could modify them by accident, because you want to modify them some of the time. Why does a[i] = ... needs to be prevented, but a = ... is fine?
I agree, this is not a strong reason on its own, but it strengthen the main reason.