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 value or an array of 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. Once a lookup is successful on the first fragment of the keypath, the evaluation continue recursively with the lookup result and the remainder of the keypath. If a key lookup fails, a nil value is returned. If a key lookup results in a method invocation that yields multiple values, only the first one is captured.
In cases where the value is a map[string]..., and the first keypath fragment is not a valid key, all partial keypaths are considered as potential keys. For example, if the keypath is "foo.bar.baz", "foo" is considered first, then "foo.bar", then "foo.bar.baz". However, if the map contains both "foo" and "foo.bar" keys, only "foo" will be accessible with this method.
When the current value 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. Arrays are always returns as a type agnostic array (`[]interface{}`), even if all the values have a consistent type.
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.