Generic helper to concatenate arbitrary numbers of slices
This commit is contained in:
parent
41a0e60064
commit
2787f305f3
1 changed files with 13 additions and 0 deletions
|
|
@ -201,3 +201,16 @@ func Samefile(a, b any) bool {
|
|||
|
||||
return os.SameFile(sta, stb)
|
||||
}
|
||||
|
||||
func Concat[T any](slices ...[]T) []T {
|
||||
var total int
|
||||
for _, s := range slices {
|
||||
total += len(s)
|
||||
}
|
||||
result := make([]T, total)
|
||||
var i int
|
||||
for _, s := range slices {
|
||||
i += copy(result[i:], s)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue