Documentation
¶
Overview ¶
Package value defines helper functions to compare numeric and other value types as either ordered or unordered. It also contains helpers to perform set operations on collections, and find sub-sequences in sequences.
Index ¶
- func AsFloat(value interface{}) (float64, bool)
- func AsInt(value interface{}) (int64, bool)
- func AsUInt(value interface{}) (uint64, bool)
- func CompareOrdered(lhs, rhs interface{}) (int, error)
- func CompareUnordered(lhs, rhs interface{}) (bool, error)
- func Field(value interface{}, keypath string) interface{}
- func FormatSetValues(s Set) string
- func IndexOfSubsequence(seq, sub reflect.Value) int
- func IsSequenceType(v reflect.Value) bool
- func MaxAbsoluteDifference(lhs, rhs interface{}) (float64, error)
- func PreCheckSubsequence(v1, v2 reflect.Value) error
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareOrdered ¶
CompareOrdered returns the result of the comparison of two values of compatible type that can be ordered, including ints, floats, strings, byte slices, and slices of comparable orderable values. Values of different type or values of the same type that cannot be ordered return an error.
func CompareUnordered ¶
CompareUnordered returns the result of the equality comparison of two values of compatible type, including ints, floats, strings and slices of comparable values. Other values are compared with reflect.DeepEqual(). Values of different tyype that cannot be compared return an error.
func Field ¶
func Field(value interface{}, keypath string) interface{}
Field takes a root value or an array of root values, navigates through the data tree according to a keypath, and returns the targeted values. `keypath` is a dot-separated list of keys, each used as either field name in a struct, a key in a map, or a niladic method name. Any error during key evaluation results in a nil value. If a method invocation yields multiple return values, only the first one is captured.
When the root is a single object and all the fields along the keypath are scalar types, the result is a scalar value. For each array or slice type along the path, the result become a slice collecting the result of evaluating the sub-path on each individual element. The shape of the result is then a N-dimensional array, where N is the number of arrays traversed along the path.
Because the implementation is using the reflect package and is mostly type agnostic, the resulting arrays are always of type []interface{}, even if the field types are consistent across values.
func FormatSetValues ¶
FormatSetValues returns a textual representation of the receiving set, potentially abbreviated, for the purpose of reporting discrepancies during unit-test.
func IndexOfSubsequence ¶
IndexOfSubsequence finds the index of a sub-sequence `sub` in the sequence `seq`, or returns -1. Both arguments must be suitable sequences.
func IsSequenceType ¶
IsSequenceType checks if a value is a kind of sequence
func MaxAbsoluteDifference ¶
MaxAbsoluteDifference returns the maximum absolute difference of all the components. Both values must have the same shape and must be composed of values convertible to float64 for comparison
func PreCheckSubsequence ¶
PreCheckSubsequence checks if a pair of values are suitable for use with IndexOfSubsequence().
Types ¶
type Set ¶
type Set map[interface{}]struct{}
Set represents a unique set of values of any kind, and provides methods to performat standard set operation.
func ReflectSet ¶
ReflectSet returns a newly constructed set from a collection type, or an error if the value is not a collection.
func (Set) Intersect ¶
Intersect returns a new set that is the intersection between the receiver and another set.