Documentation ¶
Index ¶
- Variables
- func CanIndirect(v interface{}) bool
- func CanIndirectType(t reflect.Type) bool
- func CanIndirectValue(v reflect.Value) bool
- func CanLen(x interface{}) bool
- func Contains(source interface{}, element interface{}) bool
- func ContainsKey(source interface{}, element interface{}) bool
- func ContainsSameKey(source interface{}, element interface{}) bool
- func ContainsSameValue(source interface{}, element interface{}) bool
- func ContainsValue(source interface{}, element interface{}) bool
- func DeepEqual(expected, actual interface{}) bool
- func Equal(expected, actual interface{}) bool
- func Index(list interface{}, element interface{}) int
- func IndexSame(list interface{}, element interface{}) int
- func Indirect(v interface{}) interface{}
- func IsKind(t Kinder, kind reflect.Kind) bool
- func IsNil(object interface{}) bool
- func IsZero(v interface{}) bool
- func KindOneOf(t Kinder, kinds ...reflect.Kind) bool
- func Len(x interface{}) (length int)
- func PathTo(v interface{}) string
- func String(v interface{}) string
- type Comparator
- type Data
- func (v Data) At(i int) (Value, Value)
- func (v Data) CanIndirect() bool
- func (v Data) CanInterface() bool
- func (v Data) CanLen() bool
- func (v Data) Compare(comparator Comparator, value Value) bool
- func (v Data) ContainsKey(compare Comparator, element interface{}) bool
- func (v Data) ContainsValue(compare Comparator, element interface{}) bool
- func (v Data) DeepEqual(element interface{}) bool
- func (v Data) Equal(element interface{}) bool
- func (v Data) Indirect() Data
- func (v Data) Interface() interface{}
- func (v Data) InterfaceOrNil() interface{}
- func (v Data) IsKind(k reflect.Kind) bool
- func (v Data) IsNil() bool
- func (v Data) IsZero() bool
- func (v Data) Iterate(iterator IteratorFunc)
- func (v Data) Iterator() *Iterator
- func (v Data) KindOneOf(k ...reflect.Kind) bool
- func (v Data) Len() (length int)
- func (v Data) PathTo() string
- func (v Data) Search(iterator SearchFunc) *KeyValue
- func (v Data) SearchIndex(compare Comparator, element interface{}) int
- func (v Data) SearchKey(compare Comparator, element interface{}) *KeyValue
- func (v Data) SearchValue(compare Comparator, element interface{}) *KeyValue
- func (v Data) String() string
- func (v Data) Type() Type
- func (v Data) Untyped() Data
- func (v Data) Value() Value
- type Equalizer
- type Indexer
- type Iterator
- type IteratorFunc
- type KeyValue
- func Search(source interface{}, iterator SearchFunc) *KeyValue
- func SearchKey(source interface{}, element interface{}) *KeyValue
- func SearchSameKey(source interface{}, element interface{}) *KeyValue
- func SearchSameValue(source interface{}, element interface{}) *KeyValue
- func SearchValue(source interface{}, element interface{}) *KeyValue
- type Kinder
- type MapIndexer
- type SearchFunc
- type SliceIndexer
- type StructIndexer
- type Type
- type Value
- func (v Value) At(i int) (Value, Value)
- func (v Value) CanIndex() bool
- func (v Value) CanIndirect() bool
- func (v Value) CanInterface() bool
- func (v Value) CanLen() bool
- func (v Value) CanUseIndexer() bool
- func (v Value) Compare(comparator Comparator, value Value) bool
- func (v Value) ContainsKey(compare Comparator, element interface{}) bool
- func (v Value) ContainsValue(compare Comparator, element interface{}) bool
- func (v Value) Index(i int) Value
- func (v Value) Indexer() Indexer
- func (v Value) Indirect() Value
- func (v Value) InterfaceOrNil() interface{}
- func (t Value) IsKind(k reflect.Kind) bool
- func (v Value) IsNil() bool
- func (v Value) IsZero() bool
- func (v Value) Iterate(iterator IteratorFunc)
- func (v Value) Iterator() *Iterator
- func (t Value) KindOneOf(k ...reflect.Kind) bool
- func (v Value) Len() (length int)
- func (v Value) Search(iterator SearchFunc) *KeyValue
- func (v Value) SearchIndex(compare Comparator, element interface{}) int
- func (v Value) SearchKey(compare Comparator, element interface{}) *KeyValue
- func (v Value) SearchValue(compare Comparator, element interface{}) *KeyValue
- func (v Value) String() string
- func (v Value) Type() Type
- func (v Value) Untyped() Value
- func (v Value) Zero() Value
- func (v Value) Zeroer() (Zeroer, bool)
- type ValueSorter
- type Zeroer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrArgumentNotIndexable = errors.New("argument can't be used to search index")
ErrArgumentNotIndexable is telling you that argument supplied to function is not a searchable for specific index
Functions ¶
func CanIndirect ¶
func CanIndirect(v interface{}) bool
CanIndirect will determine if value can be dereferenced refer to https://golang.org/pkg/reflect/#Value.Elem
func CanIndirectType ¶
CanIndirectType will determine if type can be dereferenced refer to https://golang.org/pkg/reflect/#Type method Elem()
func CanIndirectValue ¶
CanIndirectValue will determine if value can be dereferenced refer to https://golang.org/pkg/reflect/#Value.Elem
func CanLen ¶
func CanLen(x interface{}) bool
CanLen tells you if possible to search for len of given object. https://golang.org/pkg/reflect/#Value.Len
func Contains ¶
func Contains(source interface{}, element interface{}) bool
Contains will search for specific value in list and return bool if found. It panics if list is not searchable
func ContainsKey ¶
func ContainsKey(source interface{}, element interface{}) bool
ContainsKey will search for specific key in list and return bool if found. It panics if list is not searchable
func ContainsSameKey ¶
func ContainsSameKey(source interface{}, element interface{}) bool
ContainsSameKey will search for specific key in list and return bool if found. It panics if list is not searchable. Unlike ContainsKey compared keys needs to be deep equal
func ContainsSameValue ¶
func ContainsSameValue(source interface{}, element interface{}) bool
ContainsSameValue will search for specific value in list and return bool if found. It panics if list is not searchable. Unlike ContainsValue compared keys needs to be deep equal
func ContainsValue ¶
func ContainsValue(source interface{}, element interface{}) bool
ContainsValue will search for specific value in list and return bool if found. it panics if list is not searchable
func DeepEqual ¶
func DeepEqual(expected, actual interface{}) bool
DeepEqual determines if two Objects are considered equal. This is what reflect does, except this method add nil check for speed improvement
Example ¶
fmt.Printf("%v\n", DeepEqual(uint(0), 0)) fmt.Printf("%v\n", DeepEqual(0, 0))
Output: false true
func Equal ¶
func Equal(expected, actual interface{}) bool
Equal gets whether two Objects are equal. It don't cares about underlying type. If first argument is compliant with `Equalizer` interface then it will use `Equal(interface) bool` on type to compare. Otherwise it try to compare using `DeepEqual` and same types.
Example ¶
fmt.Printf("%v\n", Equal(uint(0), 0)) // implements `Equal(v interface{}) bool` // checkout type `YourStruct` a := &YourStruct{A: "same"} b := &DiffStruct{A: "same"} fmt.Printf("%v\n", Equal(a, b))
Output: true true
func Index ¶
func Index(list interface{}, element interface{}) int
Index will search for specific element in list and return index. If not found returns -1. If list is not list it will panic
func IndexSame ¶
func IndexSame(list interface{}, element interface{}) int
IndexSame will search for specific element in list and return index. If not found returns -1. If list is not list it will panic. But unlike Index it will compare values so they must be deep equal.
func Indirect ¶
func Indirect(v interface{}) interface{}
Indirect will return actual value insted of pointer if values is passed value is returned
func IsNil ¶
func IsNil(object interface{}) bool
IsNil checks if a specified object is nil or not also check underlying type if its nil or not
func IsZero ¶
func IsZero(v interface{}) bool
IsZero return true if underlying type is equal to its zero value
Types ¶
type Comparator ¶
type Comparator func(interface{}, interface{}) bool
Comparator is used as abstraction for method like IsEqual which compare two values
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data is structure supporting this package but also have application outside. It helps to simplify working with reflect
func (Data) CanIndirect ¶
CanIndirect will determine if value can be dereferenced refer to https://golang.org/pkg/reflect/#Value.Elem
func (Data) CanInterface ¶
CanInterface returns whether value can interface
func (Data) CanLen ¶
CanLen tells you if possible to search for len of given reflect.Value. https://golang.org/pkg/reflect/#Value.Len
func (Data) Compare ¶
func (v Data) Compare(comparator Comparator, value Value) bool
Compare will use comparator to compare to another Value
func (Data) ContainsKey ¶
func (v Data) ContainsKey(compare Comparator, element interface{}) bool
ContainsKey will search for specific key in list and return bool if found. It panics if list is not searchable
func (Data) ContainsValue ¶
func (v Data) ContainsValue(compare Comparator, element interface{}) bool
ContainsValue will search for specific value in list and return bool if found. It panics if list is not searchable
func (Data) DeepEqual ¶
DeepEqual determines if two Objects are considered equal. This is what reflect does, except this method add nil check for speed improvement
func (Data) Equal ¶
Equal gets whether two Objects are equal. It don't cares about underlying type. If first argument is compliant with `Equalizer` interface then it will use `Equal(interface) bool` on type to compare. Otherwise it try to compare using `DeepEqual` and same types.
func (Data) Indirect ¶
Indirect will check if value can be dereferenced and dereference otherwise return value itself
func (Data) Interface ¶
func (v Data) Interface() interface{}
Interface returns actual data originally inserted
func (Data) InterfaceOrNil ¶
func (v Data) InterfaceOrNil() interface{}
InterfaceOrNil will either return interface or nil if interface cannot be obtained
func (Data) IsNil ¶
IsNil checks if a specified object is nil or not also check underlying type if its nil or not
func (Data) Iterate ¶
func (v Data) Iterate(iterator IteratorFunc)
Iterate will iterate over struct map or slice providing key value of every element
func (Data) Search ¶
func (v Data) Search(iterator SearchFunc) *KeyValue
Search will iterate over struct map or slice providing key value of every element and return first result when iterator return true
func (Data) SearchIndex ¶
func (v Data) SearchIndex(compare Comparator, element interface{}) int
SearchIndex will search for specific element in list and return index. If not found returns -1. it panics if list is not searchable
func (Data) SearchKey ¶
func (v Data) SearchKey(compare Comparator, element interface{}) *KeyValue
SearchKey will search for specific key in struct slice or map
func (Data) SearchValue ¶
func (v Data) SearchValue(compare Comparator, element interface{}) *KeyValue
SearchValue will search for specific value in struct slice or map
type Equalizer ¶
type Equalizer interface {
Equal(v interface{}) bool
}
Equalizer is way how to check if object can compare it self to another object. Used only with `Equal` method
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator designed to manage iterations over indexer
type IteratorFunc ¶
type IteratorFunc func(*Iterator)
IteratorFunc function iterates over Indexer providing key and value
type KeyValue ¶
KeyValue provides key value. Key just like value can be any interface. If slice key will be int wrapped in Value
func Search ¶
func Search(source interface{}, iterator SearchFunc) *KeyValue
Search will iterate over struct map or slice providing key value of every element and return first result when iterator return true
func SearchKey ¶
func SearchKey(source interface{}, element interface{}) *KeyValue
SearchKey will search for specific key in struct slice or map
func SearchSameKey ¶
func SearchSameKey(source interface{}, element interface{}) *KeyValue
SearchSameKey will search for specific key in struct slice or map. Unlike SearchKey it the compared keys needs to be deep equal
func SearchSameValue ¶
func SearchSameValue(source interface{}, element interface{}) *KeyValue
SearchSameValue will search for specific value in struct slice or map. Unlike SearchKey it compared keys needs to be deep equal
func SearchValue ¶
func SearchValue(source interface{}, element interface{}) *KeyValue
SearchValue will search for specific value in struct slice or map
type MapIndexer ¶
type MapIndexer struct { Source Value // contains filtered or unexported fields }
MapIndexer implements Indexer for maps
func NewMapIndexer ¶
func NewMapIndexer(source Value) *MapIndexer
NewMapIndexer will create MapIndexer
type SearchFunc ¶
SearchFunc function iterates over Indexer providing key and value and return result if result of function is true
type SliceIndexer ¶
type SliceIndexer struct { Source Value // contains filtered or unexported fields }
SliceIndexer implements Indexer for slices or arrays
func NewSliceIndexer ¶
func NewSliceIndexer(source Value) *SliceIndexer
NewSliceIndexer will create SliceIndexer
type StructIndexer ¶
type StructIndexer struct { Source Value // contains filtered or unexported fields }
StructIndexer implements Indexer for structs
func NewStructIndexer ¶
func NewStructIndexer(source Value) *StructIndexer
NewStructIndexer will create StructIndexer
type Type ¶
Type is wrapper around reflect.Type
func IndirectType ¶
IndirectType will check if type can be dereferenced and do so, otherwise return type itself panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.
func IndirectTypeOf ¶
func IndirectTypeOf(x interface{}) Type
IndirectTypeOf is shortcut to TypeOf().Elem(). only indirect if possible otherwise it returns current type
func (Type) CanIndirect ¶
CanIndirect will determine if type can be dereferenced refer to https://golang.org/pkg/reflect/#Type method Elem()
func (Type) Indirect ¶
Indirect will check if type can be dereferenced and do so, otherwise return type itself panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.
func (Type) KindOneOf ¶
KindOneOf is method to compare type against multiple reflect.Type with logical OR
type Value ¶
Value is wrapper around reflect.Value
func IndirectValue ¶
IndirectValue will check if value can be dereferenced and dereference otherwise return value itself
func IndirectValueOf ¶
func IndirectValueOf(v interface{}) Value
IndirectValueOf is shortcut to ValueOf().Elem()
func (Value) CanIndex ¶
CanIndex tells you if you can get value from index. Checkout https://golang.org/pkg/reflect/#Value.Index
func (Value) CanIndirect ¶
CanIndirect will determine if value can be dereferenced refer to https://golang.org/pkg/reflect/#Value.Elem
func (Value) CanInterface ¶
CanInterface returns whether value can interface
func (Value) CanLen ¶
CanLen tells you if possible to search for len of given reflect.Value. https://golang.org/pkg/reflect/#Value.Len
func (Value) CanUseIndexer ¶
CanUseIndexer return bool if Indexer Method can be used
func (Value) Compare ¶
func (v Value) Compare(comparator Comparator, value Value) bool
Compare will use comparator to compare to another Value
func (Value) ContainsKey ¶
func (v Value) ContainsKey(compare Comparator, element interface{}) bool
ContainsKey will search for specific key in list and return bool if found. It panics if list is not searchable
func (Value) ContainsValue ¶
func (v Value) ContainsValue(compare Comparator, element interface{}) bool
ContainsValue will search for specific value in list and return bool if found. It panics if list is not searchable
func (Value) Index ¶
Index is just wrapper of regular index method. It will indirect value if is pointer
func (Value) Indirect ¶
Indirect will check if value can be dereferenced and dereference otherwise return value itself
func (Value) InterfaceOrNil ¶
func (v Value) InterfaceOrNil() interface{}
InterfaceOrNil will either return interface or nil if interface cannot be obtained
func (Value) IsNil ¶
IsNil will check if you can ask reflect for IsNil and if its pointer it will recursively check until its resolved
func (Value) Iterate ¶
func (v Value) Iterate(iterator IteratorFunc)
Iterate will iterate over struct map or slice providing iterator object
func (Value) KindOneOf ¶
KindOneOf is method to compare type against multiple reflect.Type with logical OR
func (Value) Len ¶
Len try to get length of object. It will wrap original value into new value so interface{} can work
func (Value) Search ¶
func (v Value) Search(iterator SearchFunc) *KeyValue
Search will iterate over struct map or slice providing key value of every element and return first result when iterator return true
func (Value) SearchIndex ¶
func (v Value) SearchIndex(compare Comparator, element interface{}) int
SearchIndex will search for specific element in list and return index. If not found returns -1. it panics if list is not searchable
func (Value) SearchKey ¶
func (v Value) SearchKey(compare Comparator, element interface{}) *KeyValue
SearchKey will search for specific key in struct slice or map
func (Value) SearchValue ¶
func (v Value) SearchValue(compare Comparator, element interface{}) *KeyValue
SearchValue will search for specific value in struct slice or map
type ValueSorter ¶
type ValueSorter []Value
ValueSorter will sort values in slice this is good for searching maps and structs which don't have to preserve order
func (ValueSorter) Less ¶
func (sorter ValueSorter) Less(i, j int) bool
Less will check if value is 'less' then other
func (ValueSorter) Swap ¶
func (sorter ValueSorter) Swap(i, j int)
Swap performs swaping of values in slice