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 RConvert(v *re.Value, t re.Type) (*re.Value, bool)
- func RSet(src, dst *re.Value, convert bool) bool
- 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 ¶
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 )
const ( CodeFunctionError errors.GoCode = "FunctionError" CodeTypeMismatch errors.GoCode = "TypeMismatch" )
Variables ¶
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 RConvert ¶
RConvert converts a re.Value to a different type.
If the value is not convertible to the type, the original value is returned.
If the pointer of `v` is invalid, a new value of type `t` is created, and the pointer is set to it, then the pointer is returned.
func RSet ¶
RSet sets a value from one re.Value to another.
If the destination value is not settable, this function will return false.
If the source value is not immediately assignable to the destination value, and the convert parameter is true, the source value will be converted to the destination value's type.
If the source value is not immediately assignable to the destination value, and the convert parameter is false, this function will return false.
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