-
-
Notifications
You must be signed in to change notification settings - Fork 752
Fix Issue 4535 - std.range could have a takeWhile!pred(range) function #5563
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
alias takeWhile = until;https://dlang.org/phobos/std_algorithm_searching.html#.until
This seems to be especially hard to find even though I tried to help people with #4985
Btw see also: #147
Uh oh!
There was an error while loading. Please reload this page.
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.
Other common confusions:
dropWhile->findflatten->joinerany->existszipMap->assocArrayindexOfvs.(byChar).countUntilgroup->chunkByThere 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.
You might also like this table: https://github.com/wilzbach/linq for a mapping from LINQ to D
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.
I think that takeWhile is much cleaner than until, in the sense that it is more generic and it doesn't have a sentinel. See discussion on bug report
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.
I like
takeWhileas well, but I'm pretty sure that @andralex will veto this as it adds yet another symbol to std.algorithmHence to save you work, my advice is to look into incorporating your changes into
until.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.
IIRC, I tried to add
takeWhilea number of years ago, and he vetoed it along with other stuff likedropWhile. Basically, the decision was that we could do what we needed to do with what we had, and you're always going to have problems with folks finding stuff, because they assume one name, whereas the person who designed the function thought of another - and changing the name often just results in a different set of people not finding what they're looking for (a prime example of this would bestripvstrim- some languages/libraries use one and some the other, and both are valid names, but if the library you're trying to use didn't use the one you're thinking of, you might not find it). And we really can't fix that problem. You try to pick a good name and then try and make sure that your documentation makes it easy to find.In this case,
untilalready does what this PR does - it even has an overload that doesn't take a sentinel. And honestly, the fact that is does have the ability to indicate a sentinel as well as whether it's open on the right makes it more useful than this implementation oftakeWhile.Certainly, I see no reason to add this code. It's just doing what
untilalready does - only less. At most, it would make sense to create an alias or to maketakeWhilea wrapper arounduntil, but neither would help functionality at all. It's just bikeshedding over the name, and while it might make it easier for some people to find the function, it's also going to result in confusion over the difference betweentakeWhileanduntil. Our policy has generally been to avoid adding aliases to provide additional names.So, while I think that this is ultimately up to Andrei, I don't think that it makes sense to add
takeWhilegiven that we already haveuntil, much as I agree thattakeWhilewould likely have been a better name.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.
If the implementation is really short (one-liner or alias), perhaps a good compromise is to implement it as an example unittest (e.g. as here). This way we 1) make the name findable, 2) show off Phobos' composition capabilities, and 3) avoid cluttering the name space with trivial one-liners. Win-win-win.
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.
Got it. I only made the PR so that we move on with the bug (closing it as invalid or fixing it). Thanks
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.
@CyberShadow
until's documentation actually already mentionstakeWhile, sayingSo, as far as searchability goes, if they search the documentation, they'll find it. It just won't be in the links, because it's not actually a symbol, just a comment in the documentation.