Documentation ¶
Index ¶
- Variables
- func Copy(source interface{}, targets ...interface{}) error
- func CopyProperties(source interface{}, targets ...interface{}) error
- func Filter(origin interface{}, dest interface{}, filters ...interface{}) error
- func IsFunction(in interface{}, argumentCheck ...[]int) bool
- func Map(origin interface{}, dest interface{}, mappers ...interface{}) error
- func Unique(origin interface{}, dest interface{}, uniquers ...interface{}) error
- type Collection
- func (collection *Collection) All(result interface{}) (err error)
- func (collection *Collection) AsArray() *Collection
- func (collection *Collection) AsMap(keyFunc interface{}) *Collection
- func (collection *Collection) DataType() DataType
- func (collection *Collection) Each(eachFunc interface{})
- func (collection *Collection) Filter(filter interface{}) *Collection
- func (collection *Collection) GroupBy(groupFunc interface{}) *Collection
- func (collection *Collection) HasIndex(index int) bool
- func (collection *Collection) Index(index int) interface{}
- func (collection *Collection) IsEmpty() bool
- func (collection *Collection) Items() interface{}
- func (collection *Collection) Map(mapFunc interface{}) *Collection
- func (collection *Collection) MapHasIndex(key interface{}) bool
- func (collection *Collection) MapIndex(key interface{}) interface{}
- func (collection *Collection) Reduce(reduceFunc interface{}, initial interface{}) interface{}
- func (collection *Collection) Size() int
- func (collection *Collection) Sort(compareFunc interface{}) *Collection
- func (collection *Collection) ToArray() ([]interface{}, error)
- func (collection *Collection) ToString() string
- func (collection *Collection) Unique(uniqFunc interface{}) *Collection
- type DataType
- type InvalidTypeError
Constants ¶
This section is empty.
Variables ¶
var ErrTargetInvalid = errors.New("target must be a pointer to struct")
var ErrTargetIsNil = errors.New("target is nil")
var ( // ErrorInvalidDataType invalid data type error ErrorInvalidDataType = errors.New("invalid data type") )
Functions ¶
func Copy ¶
func Copy(source interface{}, targets ...interface{}) error
Copy alias of CopyProperties
func CopyProperties ¶
func CopyProperties(source interface{}, targets ...interface{}) error
CopyProperties copy exported properties(with same name and type) from source to target target must be a pointer to struct
func IsFunction ¶
IsFunction returns if the argument is a function.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection is a data collection
func MustNew ¶
func MustNew(data interface{}) *Collection
MustNew create a new collection from data with error suppress
func (*Collection) All ¶
func (collection *Collection) All(result interface{}) (err error)
All get all of the items in the collection. the argument result must be a pointer to map or slice
func (*Collection) AsArray ¶
func (collection *Collection) AsArray() *Collection
AsArray convert the collection to an array collection Remember: the underlying data type is changed to []interface{}
func (*Collection) AsMap ¶
func (collection *Collection) AsMap(keyFunc interface{}) *Collection
AsMap convert collection to a map collection
keyFunc(value interface{}) interface{} keyFunc(value interface{}, key interface{}) interface{}
Remember: the underlying data type is changed to map[interface{}]interface{}
func (*Collection) DataType ¶
func (collection *Collection) DataType() DataType
DataType return the data type
func (*Collection) Each ¶
func (collection *Collection) Each(eachFunc interface{})
Each Execute a callback over each item.
func (*Collection) Filter ¶
func (collection *Collection) Filter(filter interface{}) *Collection
Filter iterates over elements of collection, return all element meet the needs filter(interface{}) bool filter(interface{}, int) bool
func (*Collection) GroupBy ¶
func (collection *Collection) GroupBy(groupFunc interface{}) *Collection
GroupBy iterates over elements of collection, grouping all elements by specified conditions groupFunc(interface{}) interface{} groupFunc(interface{}, int) interface{} Remember: the result of All must be type: map[interface{}][]interface{}
func (*Collection) HasIndex ¶
func (collection *Collection) HasIndex(index int) bool
HasIndex return whether the collection has a index
func (*Collection) Index ¶
func (collection *Collection) Index(index int) interface{}
Index Get an item from the collection by index.
func (*Collection) IsEmpty ¶
func (collection *Collection) IsEmpty() bool
IsEmpty Determine if the collection is empty or not.
func (*Collection) Items ¶
func (collection *Collection) Items() interface{}
Items return all items in the collection
func (*Collection) Map ¶
func (collection *Collection) Map(mapFunc interface{}) *Collection
Map manipulates an iterate and transforms it to another type. mapFunc(value interface{}) interface{} mapFunc(value interface{}) (value interface{}, key interface{}) mapFunc(value interface{}, key interface{}) interface{} mapFunc(value interface{}, key interface{}) (value interface{}, key interface{})
func (*Collection) MapHasIndex ¶
func (collection *Collection) MapHasIndex(key interface{}) bool
MapHasIndex return whether the collection has a key
func (*Collection) MapIndex ¶
func (collection *Collection) MapIndex(key interface{}) interface{}
MapIndex get an item from the collection by key
func (*Collection) Reduce ¶
func (collection *Collection) Reduce(reduceFunc interface{}, initial interface{}) interface{}
Reduce Iteratively reduce the array to a single value using a callback function reduceFunc(carry interface{}, item interface{}) interface{}
func (*Collection) Size ¶
func (collection *Collection) Size() int
Size count the number of items in the collection.
func (*Collection) Sort ¶
func (collection *Collection) Sort(compareFunc interface{}) *Collection
Sort sort collection with orderBy function, only support array collection
compareFunc(val1 interface{}, val2 interface{}) bool
func (*Collection) ToArray ¶
func (collection *Collection) ToArray() ([]interface{}, error)
func (*Collection) ToString ¶
func (collection *Collection) ToString() string
ToString print the data element
func (*Collection) Unique ¶
func (collection *Collection) Unique(uniqFunc interface{}) *Collection
Unique remove duplicated elements from collection
uniqFunc(value interface{}) interface{} uniqFunc(value interface{}, key interface{}) interface{}
Remember: the return collection type is map[interface{}]interface{} for map, []interface{} for array or slices
type InvalidTypeError ¶
InvalidTypeError describes an invalid argument passed to To. (The argument to To must be a non-nil pointer.)
func (*InvalidTypeError) Error ¶
func (e *InvalidTypeError) Error() string