We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
As append(append(append(a, b...), c...), d...) is way to common :/
append(append(append(a, b...), c...), d...)
I propose a function that gets a list of slices of same type and return one slice of that type*
// Merge return a new slice that combines all values of input slices func Merge[T any](slices ...[]T) []T { sl := 0 for i := range slices { sl += len(slices[i]) } result := make([]T, sl) cp := 0 for _, s := range slices { if sLen := len(s); sLen != 0 { copy(result[cp:], s) cp += sLen } } return result }
test:
resultSS := MergeSlices([]string{}, []string{"a", "b"}, []string{"c"}, nil) assert.EqualValues(t, []string{"a", "b", "c"}, resultSS) resultIS := MergeSlices([]int{}, []int{1, 2}, []int{4}, nil) assert.EqualValues(t, []int{1, 2, 4}, resultIS)
The text was updated successfully, but these errors were encountered:
If it will get accepted I'll file a pull :)
Sorry, something went wrong.
Dupe of #56353
Duplicate of #56353
No branches or pull requests
As
append(append(append(a, b...), c...), d...)
is way to common :/I propose a function that gets a list of slices of same type and return one slice of that type*
test:
The text was updated successfully, but these errors were encountered: