Skip to content
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

Fix Issue 18374 - Add range functions to Nullable #8417

Merged
merged 1 commit into from
Mar 27, 2022

Conversation

Herringway
Copy link
Contributor

Let's get Nullable working with the rest of phobos. Is this overkill? Probably. Definitely. 100% yes.
I genuinely have no idea what sort of documentation to write for these functions.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @Herringway! 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 coverage diff by visiting the details link of the codecov check)
  • 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 run digger -- build "master + phobos#8417"

@Herringway Herringway force-pushed the range-nullable branch 3 times, most recently from 5bd6872 to a9f2f89 Compare March 25, 2022 03:01
@Herringway Herringway changed the title Fix 18374 - Add range functions to Nullable Fix Issue 18374 - Add range functions to Nullable Mar 25, 2022
@PetarKirov
Copy link
Member

PetarKirov commented Mar 25, 2022

I genuinely have no idea what sort of documentation to write for these functions.

I suggest grouping all of these functions under the name "Range interface functions" like this:

    /// $(MREF_ALTTEXT Range interface, std, range, primitives) functions.
    alias empty = isNull;

    /// ditto
    alias popFront = nullify;

    /// ditto
    alias popBack = nullify;

...

Here's an example in std.regex: https://dlang.org/phobos/std_regex.html#.Captures.front.

Also I suggest adding a documented unittest to showcase idiomatic range-based usage. You can borrow a few examples from the optional package: https://code.dlang.org/packages/optional

@PetarKirov
Copy link
Member

PetarKirov commented Mar 25, 2022

@atilaneves @pbackus @dkorpel what are your thoughts on this addition?

Copy link
Contributor

@dkorpel dkorpel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use Nullable, so I don't have a strong opinion, but I think it's fine to give it a range interface.

std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated
return this;
}
///
inout(typeof(this)) opSlice()(size_t from, size_t to) inout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the range interface, but not sure why it needs slicing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment re: opSlice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why. I don't know why not, either. Either way, it was simple enough to support.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer less code, it's easier to maintain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Satisfying hasSlicing!T allows more efficient branches to be taken in several Phobos algorithms:

It's also necessary if we want ranges of Nullables (e.g., chain(nullable(x), nullable(y), nullable(z))) to support slicing.

std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated
return this;
}
///
inout(typeof(this)) opSlice()(size_t from, size_t to) inout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment re: opSlice.

std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated Show resolved Hide resolved
std/typecons.d Outdated Show resolved Hide resolved
@Herringway Herringway force-pushed the range-nullable branch 5 times, most recently from f890db4 to 734aada Compare March 25, 2022 19:19
@Herringway Herringway marked this pull request as ready for review March 25, 2022 23:27
@Herringway Herringway requested a review from MetaLang as a code owner March 25, 2022 23:27
@Herringway
Copy link
Contributor Author

Almost forgot to add a changelog entry.

@iK4tsu
Copy link
Contributor

iK4tsu commented Mar 27, 2022

Very nice, a much welcome change 🎉

@dlang-bot dlang-bot merged commit 90f65d4 into dlang:master Mar 27, 2022
@Herringway Herringway deleted the range-nullable branch March 27, 2022 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants