v0.0.465
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m39s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m39s
This commit is contained in:
@@ -474,6 +474,17 @@ func ArrAppend[T any](arr []T, add ...T) []T {
|
||||
return r
|
||||
}
|
||||
|
||||
// ArrPrepend works similar to append(x, y, z) - but doe snot touch the old array and creates a new one
|
||||
// Also - in contrast to ArrAppend - the add values are inserted at the start of the resulting array (in reverse order)
|
||||
func ArrPrepend[T any](arr []T, add ...T) []T {
|
||||
out := make([]T, len(arr)+len(add))
|
||||
copy(out[len(add):], arr)
|
||||
for i := 0; i < len(add); i++ {
|
||||
out[len(add)-i-1] = add[i]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ArrCopy does a shallow copy of the 'in' array
|
||||
func ArrCopy[T any](in []T) []T {
|
||||
out := make([]T, len(in))
|
||||
|
@@ -2,6 +2,7 @@ package langext
|
||||
|
||||
import (
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/tst"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -10,3 +11,13 @@ func TestJoinString(t *testing.T) {
|
||||
res := JoinString(ids, ",")
|
||||
tst.AssertEqual(t, res, "1,2,3")
|
||||
}
|
||||
|
||||
func TestArrPrepend(t *testing.T) {
|
||||
v1 := []string{"1", "2", "3"}
|
||||
|
||||
v2 := ArrPrepend(v1, "4", "5", "6")
|
||||
|
||||
tst.AssertEqual(t, strings.Join(v1, ""), "123")
|
||||
tst.AssertEqual(t, strings.Join(v2, ""), "654123")
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user