Documentation
¶
Overview ¶
Package filters defines the filter API and a library of filter implementations. These functions can be used with various Select and Detect methods in the other packages in this library.
Index ¶
- func ApplyFilter[T any](filter Filter[T], value T) result.Result[bool]
- func ApplyFilterNoError[T any](filter FilterNoError[T], value T) bool
- func MatchAll[T any](_ T) result.Result[bool]
- func MatchAllNoError[T any](_ T) bool
- func MatchNone[T any](_ T) result.Result[bool]
- func MatchNoneNoError[T any](_ T) bool
- type Filter
- func NewIsDirectoryFilter() Filter[os.DirEntry]
- func NewIsEmptyMapFilter[M ~map[K]V, K comparable, V any]() Filter[M]
- func NewIsEmptySliceFilter[T any]() Filter[[]T]
- func NewIsEmptyStringFilter() Filter[string]
- func NewIsEqualFilter[T comparable](value T) Filter[T]
- func NewIsFileFilter() Filter[os.DirEntry]
- func NewMapContainsKeyFilter[M ~map[K]V, K comparable, V any](target M) Filter[K]
- func NewSliceContainsFilter[T comparable](values []T) Filter[T]
- type FilterNoError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyFilter ¶
ApplyFilter is a helper function that evaluates the given filter and returns the result; when the given filter is nil true is returned.
func ApplyFilterNoError ¶
func ApplyFilterNoError[T any](filter FilterNoError[T], value T) bool
ApplyFilterNoError is a helper function that evaluates the given filter and returns the result; when the given filter is nil true is returned.
func MatchAllNoError ¶
MatchAllNoError is a filter that always returns true.
func MatchNoneNoError ¶
MatchNoneNoError is a filter that always returns false.
Types ¶
type Filter ¶
Filter defines a function type for filtering values. The function returns true when the value matches the filter, otherwise false; additionally, an error is returned when the filter fails.
func NewIsDirectoryFilter ¶
NewIsDirectoryFilter returns a new Filter function that returns true when the given os.DirEntry represents a directory, otherwise false. This filter never fails.
func NewIsEmptyMapFilter ¶
func NewIsEmptyMapFilter[M ~map[K]V, K comparable, V any]() Filter[M]
NewIsEmptyMapFilter returns a filter that returns true if the given map is empty, otherwise false. This filter never fails.
func NewIsEmptySliceFilter ¶
NewIsEmptySliceFilter returns a filter that returns true if the given slice is empty, otherwise false. This filter never fails.
func NewIsEmptyStringFilter ¶
NewIsEmptyStringFilter returns a filter that returns true if the given string is empty, otherwise false. This filter never fails.
func NewIsEqualFilter ¶
func NewIsEqualFilter[T comparable](value T) Filter[T]
NewIsEqualFilter returns a filter that returns true if two comparable items are equal, otherwise false. This filter never fails.
func NewIsFileFilter ¶
NewIsFileFilter returns a filter that returns true when the given os.DirEntry represents a file, otherwise false. This filter never fails.
func NewMapContainsKeyFilter ¶
func NewMapContainsKeyFilter[M ~map[K]V, K comparable, V any](target M) Filter[K]
NewMapContainsKeyFilter returns a filter that returns true if a map contains a given key.
func NewSliceContainsFilter ¶
func NewSliceContainsFilter[T comparable](values []T) Filter[T]
NewSliceContainsFilter returns true if a value is contained in a slice of values. NOTE: If this filter ever returns an error then stringutils.Disjoint will panic.
type FilterNoError ¶
FilterNoError defines a function type for filtering values. The function returns true when the value matches the filter, otherwise false.
func (FilterNoError[T]) And ¶
func (thisFilter FilterNoError[T]) And(thatFilter FilterNoError[T]) FilterNoError[T]
And creates a FilterNoError that ANDs the receiver and the given filter.
func (FilterNoError[T]) Not ¶
func (thisFilter FilterNoError[T]) Not() FilterNoError[T]
Not creates a FilterNoError that negates the receiver.
func (FilterNoError[T]) Or ¶
func (thisFilter FilterNoError[T]) Or(thatFilter FilterNoError[T]) FilterNoError[T]
Or creates a FilterNoError that ORs the receiver and the given filter.