Skip to content

Commit 2787f30

Browse files
committed
Generic helper to concatenate arbitrary numbers of slices
1 parent 41a0e60 commit 2787f30

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/utils/misc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,16 @@ func Samefile(a, b any) bool {
201201

202202
return os.SameFile(sta, stb)
203203
}
204+
205+
func Concat[T any](slices ...[]T) []T {
206+
var total int
207+
for _, s := range slices {
208+
total += len(s)
209+
}
210+
result := make([]T, total)
211+
var i int
212+
for _, s := range slices {
213+
i += copy(result[i:], s)
214+
}
215+
return result
216+
}

0 commit comments

Comments
 (0)