Documentation
¶
Index ¶
- Constants
- Variables
- func CastFunc[OUT Function](fn any, opts ...func(*FuncConfig)) (OUT, error)
- func ConvertToType(value re.Value, targetType re.Type) (re.Value, error)
- func EQ_BYTES_RUNES(state *EqStepState) (eq bool, ok bool)
- func EQ_DEREF_POINTERS(state *EqStepState) (eq bool, retEq bool)
- func EQ_DRIVER_VALUER(state *EqStepState) (eq bool, ok bool)
- func EQ_ISZEROER(state *EqStepState) (eq bool, ok bool)
- func EQ_NIL_LEN_ZERO(state *EqStepState) (eq, retEq bool)
- func EQ_NIL_ZEROVALS(state *EqStepState) (eq bool, retEq bool)
- func EQ_TYPES_OPT_CNV(state *EqStepState) (eq, retEq bool)
- func EQ_UNDERLYING_KIND(state *EqStepState) (eq, retEq bool)
- func Equals(a, b any, opts ...any) bool
- func IsZero(value interface{}) bool
- func Method[T Function](obj interface{}, nameOrNames any, opts ...func(*FuncConfig)) (n T, err error)
- func RCastFunc(out reflect.Type, fn any, opts ...func(*FuncConfig)) (reflect.Value, error)
- func ReflectValue(value interface{}) re.Value
- func RegisterCompareStep(order int, step func(*EqStepState) (eq bool, ok bool))
- func WithContext(ctx context.Context) func(*FuncConfig)
- func WithFuncArgs(args ...any) func(*FuncConfig)
- type Argument
- type EqStepState
- type EqualityChecker
- type EqualityChecker2
- type FLAG_EQ
- type Func
- type FuncConfig
- type Function
- type IsZeroer
Constants ¶
View Source
const ( EQ_NONE bitcheck.Flag = 0 // convert x and y to driver.Value EQ_DRIVER_VALUE bitcheck.Flag = 1 << iota // check for IsZero method on both // special case when x and y are of kinds Array, Slice, Map, Chan: // x == nil || y == nil is ignored and only length is checked. // go psuedocode: len(x) == 0 && len(y) == 0 EQ_ZEROS // if x is a pointer and y isn't, dereference x and vice versa // psuedocode: (*a == b || a == *b) -> a == b EQ_IGNORE_PTR /* ignores the first check performed by [equals], this /CAN/ be useful in certain situations for example, the following struct is defined: “` type myStruct{value int} func (m *mystruct) Equals(other any) bool { // ... if o, ok := other.(*myStruct); ok { if m == nil || other == nil { return m == nil && (o == nil || o.value == 0) || o == nil && (m == nil || m.value == 0) } return m.value == o.value } // ... return false } “` Would mean the following call is true: “` Equals((*mystruct)(nil), &myStruct{value: 0}, EQ_IGNORE_NIL) == true “` As mentioned, this is only valuable in extremely rare situations, which is why it isn't included by default. */ EQ_IGNORE_NIL // auto-convert types // psuedocode: int8(5) == int64(5) EQ_TYPE_CONVERT // include all above conversions EQ_DFLT = EQ_DRIVER_VALUE | EQ_ZEROS | EQ_IGNORE_PTR | EQ_TYPE_CONVERT )
View Source
const ( CodeFunctionError errors.GoCode = "FunctionError" CodeTypeMismatch errors.GoCode = "TypeMismatch" )
Variables ¶
View Source
var ( ErrFunction = errors.New(CodeFunctionError, "function error") ErrTypeMismatch = errors.New(CodeTypeMismatch, "type mismatch") ErrNotFunc = ErrFunction.WithCause(goerrors.New("fn must be a function")) ErrArgCount = ErrFunction.WithCause(goerrors.New("argument count mismatch")) ErrReturnCount = ErrFunction.WithCause(goerrors.New("return count mismatch")) ErrNilObject = ErrFunction.WithCause(goerrors.New("object is nil")) ErrMethodNotFound = ErrFunction.WithCause(goerrors.New("method not found")) )
Functions ¶
func EQ_BYTES_RUNES ¶
func EQ_BYTES_RUNES(state *EqStepState) (eq bool, ok bool)
func EQ_DEREF_POINTERS ¶
func EQ_DEREF_POINTERS(state *EqStepState) (eq bool, retEq bool)
func EQ_DRIVER_VALUER ¶
func EQ_DRIVER_VALUER(state *EqStepState) (eq bool, ok bool)
func EQ_ISZEROER ¶
func EQ_ISZEROER(state *EqStepState) (eq bool, ok bool)
func EQ_NIL_LEN_ZERO ¶
func EQ_NIL_LEN_ZERO(state *EqStepState) (eq, retEq bool)
func EQ_NIL_ZEROVALS ¶
func EQ_NIL_ZEROVALS(state *EqStepState) (eq bool, retEq bool)
func EQ_TYPES_OPT_CNV ¶
func EQ_TYPES_OPT_CNV(state *EqStepState) (eq, retEq bool)
func EQ_UNDERLYING_KIND ¶
func EQ_UNDERLYING_KIND(state *EqStepState) (eq, retEq bool)
func Equals ¶
Equals checks if a is equal to b.
This does not nescessarily mean a == b, see the EQ_FLAGS documentation above for more details.
Custom comparison operations can be added with RegisterCompareStep
func Method ¶
func Method[T Function](obj interface{}, nameOrNames any, opts ...func(*FuncConfig)) (n T, err error)
func ReflectValue ¶
func RegisterCompareStep ¶
func RegisterCompareStep(order int, step func(*EqStepState) (eq bool, ok bool))
func WithContext ¶
func WithContext(ctx context.Context) func(*FuncConfig)
func WithFuncArgs ¶
func WithFuncArgs(args ...any) func(*FuncConfig)
Types ¶
type EqStepState ¶
type EqStepState struct {
A, B any
V1, V2 reflect.Value
Opts FLAG_EQ
// contains filtered or unexported fields
}
func (*EqStepState) Equals ¶
func (e *EqStepState) Equals(a, b any) bool
type EqualityChecker ¶
type EqualityChecker2 ¶
type Func ¶
type FuncConfig ¶
Click to show internal directories.
Click to hide internal directories.