filters

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyFilter

func ApplyFilter[T any](filter Filter[T], value T) result.Result[bool]

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 MatchAll

func MatchAll[T any](_ T) result.Result[bool]

MatchAll is a filter that always returns true.

func MatchAllNoError

func MatchAllNoError[T any](_ T) bool

MatchAllNoError is a filter that always returns true.

func MatchNone

func MatchNone[T any](_ T) result.Result[bool]

MatchNone is a filter that always returns false.

func MatchNoneNoError

func MatchNoneNoError[T any](_ T) bool

MatchNoneNoError is a filter that always returns false.

Types

type Filter

type Filter[T any] func(value T) result.Result[bool]

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

func NewIsDirectoryFilter() Filter[os.DirEntry]

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

func NewIsEmptySliceFilter[T any]() Filter[[]T]

NewIsEmptySliceFilter returns a filter that returns true if the given slice is empty, otherwise false. This filter never fails.

func NewIsEmptyStringFilter

func NewIsEmptyStringFilter() Filter[string]

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

func NewIsFileFilter() Filter[os.DirEntry]

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.

func (Filter[T]) And

func (thisFilter Filter[T]) And(thatFilter Filter[T]) Filter[T]

And creates a Filter that ANDs the receiver and the given filter.

func (Filter[T]) Not

func (thisFilter Filter[T]) Not() Filter[T]

Not creates a Filter that negates the receiver.

func (Filter[T]) Or

func (thisFilter Filter[T]) Or(thatFilter Filter[T]) Filter[T]

Or creates a Filter that ORs the receiver and the given filter.

type FilterNoError

type FilterNoError[T any] func(value T) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL