Documentation ¶
Index ¶
- Constants
- func TypeErr(format string) func(t reflect.Type) error
- type Checker
- type Compare
- type Filter
- func Contains(substr string) Filter[string]
- func EQ[T constraints.Ordered](a T) Filter[T]
- func GT[T constraints.Ordered](a T) Filter[T]
- func GTE[T constraints.Ordered](a T) Filter[T]
- func LT[T constraints.Ordered](a T) Filter[T]
- func LTE[T constraints.Ordered](a T) Filter[T]
- func MethodName(f func(string) bool) Filter[*reflector.Method]
- func NEQ[T constraints.Ordered](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]) AndN(fs ...Filter[T]) Filter[T]
- func (f Filter[T]) Chan(pipe channel.Pipe[T]) channel.Pipe[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]) SliceBuf(vals, buf []T) slice.Slice[T]
- func (f Filter[T]) SliceInPlace(vals []T) (passing, failing slice.Slice[T])
- type Iter
- type MapFilter
- func (mf MapFilter[K, V]) Filter(k K, v V) bool
- func (mf MapFilter[K, V]) Map(m Mapper[K, V], to lmap.Mapper[K, V]) lmap.Wrapper[K, V]
- func (mf MapFilter[K, V]) Purge(m Mapper[K, V], buf []K) slice.Slice[K]
- func (mf MapFilter[K, V]) Slice(m Mapper[K, V], keyBuf []K, valBuf []V, flags MapSliceFlag) (keys slice.Slice[K], vals slice.Slice[V])
- type MapSliceFlag
- type Mapper
- type Type
- func AnyType() Type
- func ConvertableTo[I any]() Type
- func Func(args, rets []any) Type
- func Implements[I any]() Type
- func InType(n int, t reflect.Type) Type
- func IsKind(kind reflect.Kind) Type
- func IsType(referenceType reflect.Type) Type
- func NumIn(f func(int) bool) Type
- func NumInEq(n int) Type
- func NumOut(f func(int) bool) Type
- func NumOutEq(n int) Type
- func OutType(n int, t reflect.Type) Type
- func (t Type) And(t2 Type) Type
- func (t Type) AndN(ts ...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
- func (t Type) SliceAnyInPlace(vals []any) (passing, failing slice.Slice[any])
- type TypeChecker
Constants ¶
const ( ReturnKeys = 1 << iota InverseKeys ReturnVals InverseVals ReturnBoth = ReturnKeys | ReturnVals )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Compare ¶
Compare should return 0 if a==0, -1 if a<b and 1 if a>b.
func Comparer ¶
func Comparer[C constraints.Ordered]() Compare[C]
type Filter ¶
Filter represents boolean logic on a Type.
func Contains ¶
Contains creates a string Filter that returns true when passed a string that contains the given substr.
func EQ ¶
func EQ[T constraints.Ordered](a T) Filter[T]
EQ returns a Filter that will check if a given value is equal to 'a'.
func GT ¶
func GT[T constraints.Ordered](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 constraints.Ordered](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 constraints.Ordered](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 constraints.Ordered](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 constraints.Ordered](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 Filters are 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 MapFilter ¶
type MapFilter[K comparable, V any] struct { Key Filter[K] Val Filter[V] }
MapFilter provides a filter for Keys and Values. For either, a nil Filter will be ignored.
func NewMap ¶
func NewMap[K comparable, V any](k Filter[K], v Filter[V]) MapFilter[K, V]
NewMap creates a Map filter from the provided filters.
type MapSliceFlag ¶
type MapSliceFlag byte
type Mapper ¶
type Mapper[K comparable, V any] interface { Each(lmap.IterFunc[K, V]) Delete(K) }
Mapper is a representation of lmap.Mapper. But the filter package only needs the Each method.
type Type ¶
Type is a wrapper around Filter[reflect.Type] to provide helper logic for type filtering.
func AnyType ¶
func AnyType() Type
AnyType is a type filter that returns True for any type. This can be useful when creating checks for things like functions.
func ConvertableTo ¶
func Func ¶
Func builds a filter for a function. Both args and rets can be either a filter.Type, filter.Filter[reflect.Type] or reflect.Type.
func Implements ¶
Implements returns true if the provided type implements interface I.
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.
func (Type) Or ¶
Or builds a new Type filter that will return true if either underlying Type filters is true.