Add langext.BoolCount / langext.Range
This commit is contained in:
parent
c9e459edac
commit
4dd1c08e77
@ -4,6 +4,24 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func BoolCount(arr ...bool) int {
|
||||
c := 0
|
||||
for _, v := range arr {
|
||||
if v {
|
||||
c++
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func Range[T IntegerConstraint](start T, end T) []T {
|
||||
r := make([]T, 0, end-start)
|
||||
for i := start; i < end; i++ {
|
||||
r = append(r, i)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func ForceArray[T any](v []T) []T {
|
||||
if v == nil {
|
||||
return make([]T, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user