39 lines
660 B
Go
39 lines
660 B
Go
package anyreader
|
|
|
|
import "git.milar.in/milarin/ds"
|
|
|
|
func And[T any](f ...func(T) bool) func(T) bool {
|
|
return func(value T) bool {
|
|
return findFirstFalse(value, f)
|
|
}
|
|
}
|
|
|
|
func Or[T any](f ...func(T) bool) func(T) bool {
|
|
return func(value T) bool {
|
|
return findFirstTrue(value, f)
|
|
}
|
|
}
|
|
|
|
func Not[T any](f func(T) bool) func(T) bool {
|
|
return func(value T) bool {
|
|
return !f(value)
|
|
}
|
|
}
|
|
|
|
func Is[T comparable](value T) func(T) bool {
|
|
return func(v T) bool {
|
|
return value == v
|
|
}
|
|
}
|
|
|
|
func OneOf[T comparable](values ...T) func(T) bool {
|
|
m := ds.NewSet[T]()
|
|
for _, value := range values {
|
|
m.Add(value)
|
|
}
|
|
|
|
return func(v T) bool {
|
|
return m.Has(v)
|
|
}
|
|
}
|