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

Union() #73

Open
elliotchance opened this issue May 1, 2019 · 0 comments
Open

Union() #73

elliotchance opened this issue May 1, 2019 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@elliotchance
Copy link
Owner

Unlike Append() and Extend(), Union() always considered the slice empty:

pie.Strings{}.Union(pie.Strings{"baz", "qux"}, pie.Strings{"quux"})
// pie.Strings{"baz", "qux", "quux"}

pie.Strings{"foo", "bar"}.Union(pie.Strings{"baz", "qux"}, pie.Strings{"quux"})
// pie.Strings{"baz", "qux", "quux"}

This syntax is useful when unioning multiple slices without separating the first one from the rest:

// This is easier:
pie.Strings{}.Union(zeroOrMoreSlices...)

// Than handling the nil case:
if len(zeroOrMoreSlices) == 0 {
    return nil;
}

return zeroOrMoreSlices[0].Extend(zeroOrMoreSlices[1:]...)
@elliotchance elliotchance added the good first issue Good for newcomers label May 1, 2019
@elliotchance elliotchance added the enhancement New feature or request label May 10, 2019
AlessandroLorenzi added a commit to AlessandroLorenzi/pie that referenced this issue Feb 13, 2020
AlessandroLorenzi added a commit to AlessandroLorenzi/pie that referenced this issue Feb 13, 2020
AlessandroLorenzi added a commit to AlessandroLorenzi/pie that referenced this issue Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant