-
Notifications
You must be signed in to change notification settings - Fork 185
function next(eit::EdgeIter, state) modifying state #419
Comments
Please do. Thanks! |
Is the only argument against mutating the state variable is to allow caching the iteration state? Is there an example of code doing this? I can only recall seeing the start, next, done interface used in for loops, which do not cache the state variable. |
@Keno - your input appreciated here, especially given http://stackoverflow.com/questions/39181313/julia-iteration-start-next-done-side-effects - see also the PR (#423). |
This capability is used extensively in some of the iterator wrappers e.g. those from https://github.com/JuliaLang/Iterators.jl. In general the state variable is not very large and immutable. If that's not the case, the trade-off needs to be carefully considered. |
In this case, I haven't looked at the code too much, but from that PR, it looks like |
the PR shows O(n) allocations with immutable state. This looks like it would be a big problem. Your thoughts? |
Did you change |
PR #423 does not. In fact it creates a new instance and then mutates it. |
I m surprised by the results when using immutable. To be honest I don't understand the reason behind that... I added the results in #423 |
Closing via #423 - thanks for the really great discussion. |
I think
state
should not be modified by the functionnext
.http://stackoverflow.com/questions/39181313/julia-iteration-start-next-done-side-effects
Fixing it requires a minor modification. I can suggest a PR if you don't mind.
The text was updated successfully, but these errors were encountered: