-
-
Notifications
You must be signed in to change notification settings - Fork 740
[Issue 13409] std.range.padLeft/Right #3765
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
Conversation
I don't see any purpose in splitting it up into separate PRs. We want to merge both at the same time. |
In previous PRs, I was told by quickfur and burner to split up functions that do not depend on each other into separate PRs in order to keep the diffs smaller and easier to review. |
You can accomplish that by putting them in separate commits. Changes that need to be merged together should be in the same PR (unless, of course, the patches apply to different repositories). The issue with big PRs is when multiple orthogonal changes are bundled together, delaying merging of one change because of issues with an unrelated change. |
@JakobOvrum added another commit with |
*/ | ||
auto padRight(R, E)(R r, E e, size_t n) if ( | ||
isInputRange!R && | ||
(hasLength!R && !is(CommonType!(ElementType!R, E) == void)) || |
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 padRight
version that doesn't require length seemed to be much of the point of the issue report. Will you work on adding that to this PR?
@JakobOvrum changed |
!isInfinite!R && | ||
!is(CommonType!(ElementType!R, E) == void)) | ||
{ | ||
static struct Result(R, E) |
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.
Result
doesn't need to be templated, it already has access to R
and E
(as it's defined inside the padRight
template).
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.
A static struct cannot access the frame of the function.
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.
Accessing template parameters doesn't require access to the frame of the function.
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.
Wouldn't making the struct non-templated also get rid of automatic function attributing?
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.
Since a few compiler versions ago, member functions of structs nested in templates have attribute inference. The unit tests will show.
Looks good! Note that you can test |
c401ae9
to
7edd8fa
Compare
@JakobOvrum fixed issues and added @nogc tests. |
{ | ||
static struct Result(R, E) | ||
{ | ||
R data; |
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.
Nitpick, these data members should be private.
Fixed everything this time :) |
Discussion here is relevant to this PR. Hopefully there won't be long until a decision is made. |
@JakobOvrum The forum thread ended, I don't see any thing else blocking this. |
@JackStouffer, we don't merge non-trivial PRs with just one reviewer giving the go-ahead. So far it's just me, so another reviewer (or several) will have to look over it before we can merge. |
@JakobOvrum I'm sorry if I seemed like I was asking you to merge this. What I meant by my comment is to point out that this can be reviewed again now that the forum discussion is over. |
@JackStouffer, indeed, thank you for posting it here. Sometimes it's hard for potential reviewers to see if a PR is being blocked by something or not, so posting helps. I'll add the relevant label. |
How do these relate to |
@JakobOvrum I didn't know about those functions, but here are my observations after looking at their source:
|
e = element to pad the range with | ||
n = the length to pad to | ||
|
||
Return: |
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.
"Returns:"
I approve the addition, but I recommend one more careful pass through the documentation. Reviewers, free to pull after that. Thanks! |
All comments fixed. |
5d2c4c9
to
f7b4b3f
Compare
@@ -9360,3 +9368,293 @@ if (is(typeof(fun) == void) || isSomeFunction!fun) | |||
|
|||
auto r = [1, 2, 3, 4].tee!func1.tee!func2; | |||
} | |||
|
|||
/** | |||
Extends the length of the input range `r` by padding out the start of 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.
I just want to point out that this sentence also begins with a verb and omits the subject...
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.
Nice, but that's an exception because it's the opener of the dox.
The auto-tester errors have nothing to do with this change. Can anyone give a reason why this shouldn't be merged? EDIT: and another release goes by without this. |
n = the length to pad to | ||
|
||
Returns: | ||
a range containing the elements of the original range with the extra padding |
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.
nitpick: new sentence start with a capital letter - A
.
People can make fun of JavaScript's quadratic, 11 line left-pad all they want, but at least that one isn't sitting in PR where no one can use it. |
|
I agree. I'm gonna stick my neck out here and merge this. Any complaints, please submit followup PRs. Our current approach of requiring perfection before merging is a great discouragement to new contributors and hampers progress. It's time to change that. |
Auto-merge toggled on |
Thanks! |
yay |
If you'll forgive a bit of off topic noise I found the timing of this merge unintentionally hilarious given what is going on in the npm world right now. I guess D users won't be forced to use left-pad.io. |
lol... Given the current trend, I'm starting to wonder when people will start turning glue code into packages too, so that you don't even need to write any code to glue various micro-libraries together to do something you could, for example, accomplish in 25 lines of code without any dependencies. Hilarious. |
@JackStouffer you might want to add a follow-up PR that adds a note to the changelog. @ others: it's quite easy to forget adding stuff to the changelog and with git one can still go through the lists of commits between a release. However - if i may ask - what is your current policy for the changelog? a) Should a submitter provide the change in his PR (might lead to many unnecessary git conflicts as this file is changed often) It might make sense to document such guidelines (see the forum discussion on a better contribution guide) |
This is not in the changelog because the current one is for 2.071, and this will be going into 2.072. I have to wait until 2.071 is released to add it. |
https://issues.dlang.org/show_bug.cgi?id=13409
Added the new functionpadLeft
tostd.range
. SeparatedpadLeft
andpadRight
into separate PRs.