From d2bb362135cfb4893c98aff069b0d6aaf2db714c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 3 Jun 2024 09:39:57 +0200 Subject: [PATCH] v0.0.465 --- go.mod | 2 +- go.sum | 2 ++ goextVersion.go | 4 ++-- langext/array.go | 11 +++++++++++ langext/array_test.go | 11 +++++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index db9f011..fcc5d66 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/go-playground/validator/v10 v10.21.0 // indirect github.com/goccy/go-json v0.10.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/uuid v1.5.0 // indirect diff --git a/go.sum b/go.sum index 67ef16a..ef286bb 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,8 @@ github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-playground/validator/v10 v10.21.0 h1:4fZA11ovvtkdgaeev9RGWPgc1uj3H8W+rNYyH/ySBb0= +github.com/go-playground/validator/v10 v10.21.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= diff --git a/goextVersion.go b/goextVersion.go index 9b0fd6e..0cbac08 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.464" +const GoextVersion = "0.0.465" -const GoextVersionTimestamp = "2024-06-01T02:40:48+0200" +const GoextVersionTimestamp = "2024-06-03T09:39:57+0200" diff --git a/langext/array.go b/langext/array.go index 8963655..63c6bc0 100644 --- a/langext/array.go +++ b/langext/array.go @@ -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)) diff --git a/langext/array_test.go b/langext/array_test.go index 7c42b2b..7189b6c 100644 --- a/langext/array_test.go +++ b/langext/array_test.go @@ -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") + +}