v0.0.563 Add 'ArrContains' alias for 'InArray'
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m7s

This commit is contained in:
Mike Schwörer 2025-01-31 21:16:42 +01:00
parent 4d606d3131
commit 4832aa9d6c
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.562" const GoextVersion = "0.0.563"
const GoextVersionTimestamp = "2025-01-29T11:24:20+0100" const GoextVersionTimestamp = "2025-01-31T21:16:42+0100"

View File

@ -24,6 +24,7 @@ func Range[T IntegerConstraint](start T, end T) []T {
return r return r
} }
// ForceArray ensures that the given array is not nil (nil will be converted to empty)
func ForceArray[T any](v []T) []T { func ForceArray[T any](v []T) []T {
if v == nil { if v == nil {
return make([]T, 0) return make([]T, 0)
@ -47,6 +48,16 @@ func InArray[T comparable](needle T, haystack []T) bool {
return false return false
} }
// ArrContains checks if the value is contained in the array (same as InArray, but odther name for better findability)
func ArrContains[T comparable](haystack []T, needle T) bool {
for _, v := range haystack {
if v == needle {
return true
}
}
return false
}
func ArrUnique[T comparable](array []T) []T { func ArrUnique[T comparable](array []T) []T {
m := make(map[T]bool, len(array)) m := make(map[T]bool, len(array))
for _, v := range array { for _, v := range array {