-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Issue 7246 - Provide a simpler example for std.algorithm.remove. #2107
Conversation
| // using a string-based predicate | ||
| assert(remove!("a == 2")(arr) == [ 1, 3, 4, 5 ]); | ||
|
|
||
| arr = [1, 2, 3, 2, 4, 2, 5, 2]; |
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.
Note that I've had to re-initialize the array since remove has side-effects.
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.
Perhaps that comment should be part of the documentation? I'm thinking:
static immutable base = [1, 2, 3, 2, 4, 2, 5, 2];
int[] arr = base[].dup;
// using a string-based predicate
assert(remove!("a == 2")(arr) == [ 1, 3, 4, 5 ]);
//The original array contents have been modified,
//so we need to reset it to its original state.
//The length is unmodified though.
arr[] = base[];
// using a lambda predicate
assert(remove!(a => a == 2)(arr) == [ 1, 3, 4, 5 ]);As you wish. It looks fine as is too.
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 little overkill but maybe we should document it. I got caught off-guard by it as well.
I'll make an amend.
|
Updated. Auto-merge only please since the tests must pass first. :> |
|
Auto-merge toggled on |
Issue 7246 - Provide a simpler example for std.algorithm.remove.
|
This example is simpler? |
|
@CyberShadow: That's the original bug title. I don't think adding the extra explanations is a bad idea, because people might not be familiar with the "slice off end"-style semantics. |
|
OK, my nit is that this replaces a short two-line example with one that's a bit harder to follow, with the extra variable and assignments. |
https://issues.dlang.org/show_bug.cgi?id=7246