filters

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func False

func False(args ...any) bool

False returns a filter that always returns false.

func FilterCollection

func FilterCollection[T any](c collections.Collection[T], filter Filter) collections.Collection[T]

FilterCollection filters a collection by applying a filter function to each entry. Only the entries for which the filter function returns true are kept in the copy. The original collection is not modified. Note that the entries are not deep-copied.

func FilterMap

func FilterMap[K comparable, V any](m map[K]V, filter Filter) map[K]V

FilterMap filters a map by applying a filter function to each key-value pair. Only the entries for which the filter function returns true are kept in the copy. The original map is not modified. Passes the key as first and the value as second argument into the filter function. Note that the values are not deep-copied.

func FilterSlice

func FilterSlice[T any](s []T, filter Filter) []T

FilterSlice filters a slice by applying a filter function to each entry. Only the entries for which the filter function returns true are kept the copy. The original slice is not modified. Note that the entries are not deep-copied.

func True

func True(args ...any) bool

True returns a filter that always returns true.

Types

type Filter

type Filter func(args ...any) bool

func And

func And(filters ...Filter) Filter

And returns a filter that returns true if all given filters return true.

func ApplyToNthArgument

func ApplyToNthArgument(n int, filter Filter) Filter

ApplyToNthArgument applies feeds only the nth argument of the given arguments to the given filter. Indexing starts with 0.

func Not

func Not(filter Filter) Filter

Not returns the negation of the given filter.

func NumericallyEqualTo

func NumericallyEqualTo[T Number](n T) Filter

NumericallyEqualTo returns a Filter that returns true for any value equal to n. The Filter panics if the value is not a number.

func NumericallyGreaterThan

func NumericallyGreaterThan[T Number](n T) Filter

NumericallyGreaterThan returns a Filter that returns true for any value greater than n. The Filter panics if the value is not a number.

func NumericallyGreaterThanOrEqualTo

func NumericallyGreaterThanOrEqualTo[T Number](n T) Filter

NumericallyGreaterThanOrEqualTo returns a Filter that returns true for any value greater or equal to n. The Filter panics if the value is not a number.

func NumericallyLessThan

func NumericallyLessThan[T Number](n T) Filter

NumericallyLessThan returns a Filter that returns true for any value less than n. The Filter panics if the value is not a number.

func NumericallyLessThanOrEqualTo

func NumericallyLessThanOrEqualTo[T Number](n T) Filter

NumericallyLessThanOrEqualTo returns a Filter that returns true for any value less or equal to n. The Filter panics if the value is not a number.

func Or

func Or(filters ...Filter) Filter

Or returns a filter that returns true if at least one of the given filters returns true.

func Wrap

func Wrap(f any, staticArgs map[int]any) Filter

Wrap takes a function that returns a bool and turns it into a filter. If staticArgs is not nil or empty, the provided values are passed to the function at the given positions when the filter is called. This function panics in several cases: - the given value is not a function - the given function does not return a bool as first return value (further return values are ignored) - the args when calling the filter do not match the function's signature - the indices of the staticArgs are out of bounds for the function's signature

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Jump to

Keyboard shortcuts

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