Documentation ¶
Index ¶
- Constants
- func TypeErr(format string) func(t reflect.Type) error
- type Checker
- type Comparable
- type Filter
- func Contains(substr string) Filter[string]
- func EQ[T Comparable](a T) Filter[T]
- func GT[T Comparable](a T) Filter[T]
- func GTE[T Comparable](a T) Filter[T]
- func LT[T Comparable](a T) Filter[T]
- func LTE[T Comparable](a T) Filter[T]
- func MethodName(f func(string) bool) Filter[*reflector.Method]
- func NEQ[T Comparable](a T) Filter[T]
- func New[T any](fn func(T) bool) Filter[T]
- func Prefix(prefix string) Filter[string]
- func Regex(re string) (Filter[string], error)
- func Suffix(suffix string) Filter[string]
- func (f Filter[T]) And(f2 Filter[T]) Filter[T]
- func (f Filter[T]) Chan(ch <-chan T, buf int) <-chan T
- func (f Filter[T]) Check(errFn func(T) error) Checker[T]
- func (f Filter[T]) First(vals ...T) (t T, idx int)
- func (f Filter[T]) FirstIdx(vals ...T) int
- func (f Filter[T]) Iter(i liter.Iter[T]) liter.Wrapper[T]
- func (f Filter[T]) Not() Filter[T]
- func (f Filter[T]) Or(f2 Filter[T]) Filter[T]
- func (f Filter[T]) Slice(vals []T) slice.Slice[T]
- func (f Filter[T]) SliceInPlace(vals []T) (passing, failing slice.Slice[T])
- type Iter
- type Map
- type MapKeyFilter
- type MapSliceFlag
- type MapValueFilter
- type Type
- func (t Type) And(t2 Type) Type
- func (t Type) Check(errFn func(reflect.Type) error) TypeChecker
- func (t Type) Elem() Type
- func (t Type) In(i int) Type
- func (t Type) Method() Filter[*reflector.Method]
- func (t Type) Not() Type
- func (t Type) OnInterface(i any) bool
- func (t Type) Or(t2 Type) Type
- func (t Type) Out(i int) Type
- type TypeChecker
Constants ¶
const ( ReturnKeys = 1 << iota InverseKeys ReturnVals InverseVals ReturnBoth = ReturnKeys | ReturnVals )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Comparable ¶
type Comparable interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~string }
Comparable are the types that support ==, != and >.
type Filter ¶
Filter represents logic to classify a type as passing or failing.
func Contains ¶
Contains creates a string Filter that returns true when passed a string that contains the given substr.
func EQ ¶
func EQ[T Comparable](a T) Filter[T]
EQ returns a Filter that will check if a given value is equal to 'a'.
func GT ¶
func GT[T Comparable](a T) Filter[T]
EQ returns a Filter that will check if a given value is greater than to 'a'.
func GTE ¶
func GTE[T Comparable](a T) Filter[T]
GTE returns a Filter that will check if a given value is greater than or equal to 'a'.
func LT ¶
func LT[T Comparable](a T) Filter[T]
LT returns a Filter that will check if a given value is not less than to 'a'.
func LTE ¶
func LTE[T Comparable](a T) Filter[T]
LTE returns a Filter that will check if a given value is less than or equal to 'a'.
func MethodName ¶
MethodName takes a string filter and applies it to a Method name.
func NEQ ¶
func NEQ[T Comparable](a T) Filter[T]
NEQ returns a Filter that will check if a given value is not equal to 'a'.
func Prefix ¶
Prefix creates a string filter that returns true when passed a string with the given prefix.
func Suffix ¶
Suffix creates a string filter that returns true when passed a string with the given suffix.
func (Filter[T]) And ¶
And builds a new Filter that will return true if both underlying Filter is true.
func (Filter[T]) Chan ¶
Chan runs a go routine listening on ch and any int that passes the Int is passed to the channel that is returned.
func (Filter[T]) Check ¶
Check converts a filter to a Checker and returns the provided err if the filter fails.
func (Filter[T]) First ¶
First returns the first value that passes the Filter and the index. If none pass, then idx will be -1 and t will be the default value.
func (Filter[T]) Not ¶
Not builds a new Filter that will return true if the underlying Filter is false.
func (Filter[T]) Or ¶
Or builds a new Filter that will return true if either underlying Filter is true.
func (Filter[T]) Slice ¶
Slice creates a new slice holding all values that return true when passed to Filter.
func (Filter[T]) SliceInPlace ¶
SliceInPlace reorders the slice so all the elements passing the filter are at the start of the slice and all elements failing the filter are at the end. It returns two subslices, the first for passing, the second for failing. No guarentees are made about the order of the subslices.
type Iter ¶
Iter wraps an Iter and applies a Filter to it. Only values that pass the filter are returned.
func (*Iter[T]) Cur ¶
Cur fulfills liter.Iter and returns the current value of the iterator and a bool indicating if iteration is done.
type MapKeyFilter ¶
type MapKeyFilter[K comparable, V any] Filter[K]
MapKeyFilter applys a Filter to the keys of a map.
func (MapKeyFilter[K, V]) KeySlice ¶
func (mkf MapKeyFilter[K, V]) KeySlice(m map[K]V) slice.Slice[K]
KeySlice returns all the keys in the map for which the underlying filter is true.
func (MapKeyFilter[K, V]) Map ¶
func (mkf MapKeyFilter[K, V]) Map(m map[K]V) map[K]V
Map creates a new map populated with all the key/value pairs for with the underlying filter is true for the key.
func (MapKeyFilter[K, V]) Purge ¶
func (mkf MapKeyFilter[K, V]) Purge(m map[K]V)
Purge all values from the map where the filter is false for the key.
func (MapKeyFilter[K, V]) ValSlice ¶
func (mkf MapKeyFilter[K, V]) ValSlice(m map[K]V) slice.Slice[V]
ValSlice returns all the values in the map for which the underlying filter is true for the corresponding key.
type MapSliceFlag ¶
type MapSliceFlag byte
type MapValueFilter ¶
type MapValueFilter[K comparable, V any] Filter[V]
MapValueFilter applys a Filter to the values of a map.
func (MapValueFilter[K, V]) KeySlice ¶
func (mvf MapValueFilter[K, V]) KeySlice(m map[K]V) slice.Slice[K]
KeySlice returns all the keys in the map for which the underlying filter is true for the corresponding value.
func (MapValueFilter[K, V]) Map ¶
func (mvf MapValueFilter[K, V]) Map(m map[K]V) map[K]V
Map creates a new map populated with all the key/value pairs for with the underlying filter is true for the value.
func (MapValueFilter[K, V]) Purge ¶
func (mvf MapValueFilter[K, V]) Purge(m map[K]V)
Purge all values from the map where the filter is false for the value.
func (MapValueFilter[K, V]) ValSlice ¶
func (mvf MapValueFilter[K, V]) ValSlice(m map[K]V) slice.Slice[V]
ValSlice returns all the values in the map for which the underlying filter is true.
type Type ¶
Type is a wrapper around Filter[reflect.Type] to provide helper logic for type filtering.
func IsKind ¶
IsKind creates a Type filter that returns true when given a type that matches the specified kind.
func IsType ¶
IsType creates a filter using referenceType. Returns true if the filterType is the same as referenceType.
func (Type) And ¶
And builds a new Type filter that will return true if both underlying Type filters are true.
func (Type) Check ¶
func (t Type) Check(errFn func(reflect.Type) error) TypeChecker
Check creates a TypeChecker from a Type filter. It uses reflector.ToType, so that it can accept either a reflect.Type and use it directly or an interface which it will call reflect.ToType on.
func (Type) In ¶
In checks the filter type's agument number i against the given filter. If i is less than 0, it will be indexed relative to the number of arguments, so -1 will return the last argument.
func (Type) Not ¶
Or builds a new Type filter that will return true if the underlying Type filter is false.
func (Type) OnInterface ¶
OnInterface applies the filter to the TypeOf i.