Documentation ¶
Overview ¶
Package reflectutil provides reflection-based utilities.
Index ¶
- func AreComparable(a, b interface{}) bool
- func AreComparableTypes(a, b reflect.Type) bool
- func Compare(a, b interface{}) int
- func CompareValues(a, b reflect.Value) int
- func DeepEqual(a, b interface{}, options *DeepEqualOpts) bool
- func Less(a, b interface{}) bool
- func LessValues(a, b reflect.Value) bool
- func TrySortValues(v []reflect.Value) []reflect.Value
- type DeepEqualOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AreComparable ¶
func AreComparable(a, b interface{}) bool
AreComparable is a helper to call AreComparableTypes.
func AreComparableTypes ¶
AreComparableTypes returns true iff a and b are comparable types: bools, strings and numbers, and composites using arrays, slices, structs or pointers.
func CompareValues ¶
CompareValues returns an integer comparing two values. If a and b are comparable, the result is 0 if a == b, -1 if a < b and +1 if a > b. If a and b are incomparable an arbitrary value is returned. Arrays, slices and structs use lexicographic ordering, and complex numbers compare real before imaginary.
func DeepEqual ¶
func DeepEqual(a, b interface{}, options *DeepEqualOpts) bool
Equal is similar to reflect.DeepEqual, except that it also considers the sharing structure for pointers. When reflect.DeepEqual encounters pointers it just compares the dereferenced values; we also keep track of the pointers themselves and require that if a pointer appears multiple places in a, it appears in the same places in b.
func LessValues ¶
LessValues returns true iff a and b are comparable and a < b. If a and b are incomparable an arbitrary value is returned. Cyclic values are not handled; if a and b are cyclic and equal, this will infinite loop. Arrays, slices and structs use lexicographic ordering, and complex numbers compare real before imaginary.
func TrySortValues ¶
TrySortValues sorts a slice of reflect.Value if the value kind is supported. Supported kinds are bools, strings and numbers, and composites using arrays, slices, structs or pointers. Arrays, slices and structs use lexicographic ordering, and complex numbers compare real before imaginary. If the values in the slice aren't comparable or supported, the resulting ordering is arbitrary.
Types ¶
type DeepEqualOpts ¶
type DeepEqualOpts struct {
SliceEqNilEmpty bool
}
DeepEqualOpts represents the options configuration for DeepEqual.