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

Issue 7246 - Provide a simpler example for std.algorithm.remove. #2107

Merged
merged 1 commit into from Apr 23, 2014
Merged

Issue 7246 - Provide a simpler example for std.algorithm.remove. #2107

merged 1 commit into from Apr 23, 2014

Conversation

ghost
Copy link

@ghost ghost commented Apr 23, 2014

// using a string-based predicate
assert(remove!("a == 2")(arr) == [ 1, 3, 4, 5 ]);

arr = [1, 2, 3, 2, 4, 2, 5, 2];
Copy link
Author

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.

Copy link
Collaborator

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.

Copy link
Author

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.

@ghost
Copy link
Author

ghost commented Apr 23, 2014

Updated. Auto-merge only please since the tests must pass first. :>

@monarchdodra
Copy link
Collaborator

Auto-merge toggled on

monarchdodra added a commit that referenced this pull request Apr 23, 2014
Issue 7246 - Provide a simpler example for std.algorithm.remove.
@monarchdodra monarchdodra merged commit 79903eb into dlang:master Apr 23, 2014
@CyberShadow
Copy link
Member

This example is simpler?

@dnadlinger
Copy link
Member

@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.

@CyberShadow
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants