Add langext.BoolCount / langext.Range

This commit is contained in:
Mike Schwörer 2022-10-27 17:06:16 +02:00
parent c9e459edac
commit 4dd1c08e77
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

View File

@ -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)