-
-
Notifications
You must be signed in to change notification settings - Fork 747
std.algorithm.searching: Implement none as shorthand for !any.
#6421
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
std.algorithm.searching: Implement none as shorthand for !any.
#6421
Conversation
|
Thanks for your pull request and interest in making D better, @FeepingCreature! 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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#6421" |
wilzbach
left a comment
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.
Oh I understand your motivation and I do miss a few convenience functions myself from Phobos, but I'm not sure if @andralex will approve this.
-> Tagging him
As a recommendation, before making a PR to add new symbols it might be worthwhile to ask on Slack or the NG whether that could be controversial.
Or assume by default that adding a new symbol will be controversial :P
| } | ||
|
|
||
| /++ | ||
| Checks if $(I _none) of the elements verify `pred`. This is a convenience wrapper for `!any!pred`. |
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.
Auto-highlighting has been removed recently - _ is no longer necessary :)
dlang/dlang.org#2307
| template none(alias pred = "a") | ||
| { | ||
| /++ | ||
| Returns `true` if and only if $(I _no) value `v` found in the |
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.
Auto-highlighting has been removed recently - _ is no longer necessary :)
dlang/dlang.org#2307
| `!any` can be used to verify that $(I none) of the elements verify | ||
| `pred`. | ||
| This is sometimes called `exists` in other languages. | ||
| `! any!pred` is equivalent to `none!pred`. |
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.
See_Also: $(LREF all), $(LREF none) ?
andralex
left a comment
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.
Indeed we don't do these kind of trivial functions - just compose using lambdas etc. Thanks!
In your own program you can do alias none = x => !any(x);
void main()
{
auto a = [0, 0, 0];
assert(a.none);
}Closing due to rejection. |
|
Seems a bit silly to explicitly call out And of course both |
The relevant quote is: !any can be used to verify that none of the elements verify pred. That seems a reasonable thing to say. Clearly one could go on and define none as its own primitive - e.g. Ruby and Perl have
Roger. There's been some decision making there, and one good argument was that |
|
In my opinion, the analogous reason for |
|
boo! |
When
anyis invoked with a long condition in ufcs form, it can be a bit hard to read the logic, ie.if (!someArray.any!(element => someConditionTest(element) && element > 2))- there's a lot of space between that negating ! and the actual test. In comparison,if (someArray.none!(element => someConditionTest(element) && element > 2))is read more easily and quickly.