Skip to content

Conversation

@FeepingCreature
Copy link
Contributor

When any is 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.

@dlang-bot
Copy link
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Your 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 locally

If 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 wilzbach added @andralex Review:Needs Changelog A changelog entry needs to be added to /changelog labels Apr 5, 2018
Copy link
Contributor

@wilzbach wilzbach left a 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`.
Copy link
Contributor

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
Copy link
Contributor

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`.
Copy link
Contributor

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) ?

Copy link
Member

@andralex andralex left a 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!

@andralex andralex removed the @andralex label Apr 5, 2018
@JackStouffer
Copy link
Contributor

JackStouffer commented Apr 5, 2018

just compose using lambdas etc

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.

@FeepingCreature
Copy link
Contributor Author

FeepingCreature commented Apr 5, 2018

Seems a bit silly to explicitly call out !any in the docs, even highlight it as none, and then not provide the natural verb for it.

And of course both any and all are just trivial wrappers around find...

@andralex
Copy link
Member

andralex commented Apr 5, 2018

Seems a bit silly to say in the docs "this is the same as none" and then not just providing none.

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 unless as the negation of if.

Though of course, both any and all are just trivial wrappers around find.

Roger. There's been some decision making there, and one good argument was that range.find!(pred).empty was frequently needed and somewhat awkward.

@FeepingCreature
Copy link
Contributor Author

FeepingCreature commented Apr 5, 2018

In my opinion, the analogous reason for none is the distance between the verb and the negation if you're using UFCS, since you can't do expression.(!any). :) So either the negation ends up all the way at the start of the ufcs chain, ie. !foo.bar.baz.any!pred, possibly with newlines, or you have to write the awkward .all(!pred).

@WebFreak001
Copy link
Member

boo! none is very common and when chaining calls and long lines it get's really confusing quickly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review:Needs Changelog A changelog entry needs to be added to /changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants