-
-
Notifications
You must be signed in to change notification settings - Fork 705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid that std.range.generate calls fun one time too many #8453
Conversation
avoid that std.range.generate calls fun one time too many
|
Thanks for your pull request and interest in making D better, @rtbo! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8453" |
|
The FreeBSD failure is an issue with the CI scripts. It should be fixed when #8454 is merged. |
|
I'm not sure about this. I stumbled on this bug with I'd say wait for Phobos v2, except the status of it isn't clear, so maybe it should take the same route as |
Is it really a big deal to break compatibility with a flawed behavior that no one would expect? |
Not to me, but I hear complaints about D's lack of stability from others, and I can relate to them. @atilaneves what do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation needs to be updated to reflect this change. It currently describes the old behavior:
The resulting range will call
fun()on construction, and every call to
popFront, and the cached value will be returned whenfrontis called.
It should instead describe the new behavior. For example:
The first time
frontis called for a given element, it will callfun()and cache the return value. Additional calls tofrontwill return the cached value untilpopFrontis called.
|
I think that changing behaviour like this warrants a new function. |
|
Maybe we can call the new version |
I've made a fixed copy of |
|
PR closed as stalled due to unimplemented requested changes. This can be resurrected for Phobos 3. @jmdavis this may be of interest to you. |
This is somehow a breaking change because if
funhas side effects, the side effects won't be the same anymore.However such side effects are arguably not expected as one would not expect that
generatecallsfunone time more than the returned range length.In the proposed implementation,
funis lazily called infrontandpopFrontwould only invalidate the front value.Fixes issue 19587.