v0.0.563 Add 'ArrContains' alias for 'InArray'
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m7s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m7s
This commit is contained in:
@@ -24,6 +24,7 @@ func Range[T IntegerConstraint](start T, end T) []T {
|
||||
return r
|
||||
}
|
||||
|
||||
// ForceArray ensures that the given array is not nil (nil will be converted to empty)
|
||||
func ForceArray[T any](v []T) []T {
|
||||
if v == nil {
|
||||
return make([]T, 0)
|
||||
@@ -47,6 +48,16 @@ func InArray[T comparable](needle T, haystack []T) bool {
|
||||
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 {
|
||||
m := make(map[T]bool, len(array))
|
||||
for _, v := range array {
|
||||
|
Reference in New Issue
Block a user