48 lines
666 B
Go
48 lines
666 B
Go
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
|
|
}
|
|
}
|
|
|
|
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]
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|