anyreader/utils.go

48 lines
666 B
Go
Raw Permalink Normal View History

2023-06-30 20:43:23 +02:00
package anyreader
func sliceToFunc[T any](s []T) func() (T, error) {
i := 0
return func() (T, error) {
c := i
if c >= len(s) {
return *new(T), ErrNoMoreValues.New()
}
i++
return s[c], nil
}
}
2023-08-07 20:45:57 +02:00
func sliceToSafeFunc[T any](s []T) func() T {
i := 0
return func() T {
c := i
if c >= len(s) {
return *new(T)
}
i++
return s[c]
}
}
2023-06-30 20:43:23 +02:00
func findFirstTrue[T any](value T, functions []func(T) bool) bool {
for _, f := range functions {
if f(value) {
return true
}
}
return false
}
func findFirstFalse[T any](rn T, functions []func(T) bool) bool {
for _, f := range functions {
if !f(rn) {
return false
}
}
return true
}