reflectutil

package
Version: v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package reflectutil provides reflection-based utilities.

Index

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

func AreComparableTypes(a, b reflect.Type) bool

AreComparableTypes returns true iff a and b are comparable types: bools, strings and numbers, and composites using arrays, slices, structs or pointers.

func Compare

func Compare(a, b interface{}) int

Compare is a helper to call CompareValues.

func CompareValues

func CompareValues(a, b reflect.Value) int

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 Less

func Less(a, b interface{}) bool

Less is a helper to call LessValues.

func LessValues

func LessValues(a, b reflect.Value) bool

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

func TrySortValues(v []reflect.Value) []reflect.Value

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL