Documentation ¶
Index ¶
- type BaseCollection
- func (c BaseCollection) All() []interface{}
- func (c BaseCollection) Avg(key ...string) decimal.Decimal
- func (c BaseCollection) Chunk(num int) MultiDimensionalArrayCollection
- func (c BaseCollection) Collapse() Collection
- func (c BaseCollection) Combine(value []interface{}) Collection
- func (c BaseCollection) Concat(value interface{}) Collection
- func (c BaseCollection) Contains(value ...interface{}) bool
- func (c BaseCollection) Count() int
- func (c BaseCollection) CountBy(callback ...interface{}) map[interface{}]int
- func (c BaseCollection) CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection
- func (c BaseCollection) Dd()
- func (c BaseCollection) Diff(interface{}) Collection
- func (c BaseCollection) DiffAssoc(map[string]interface{}) Collection
- func (c BaseCollection) DiffKeys(map[string]interface{}) Collection
- func (c BaseCollection) Dump()
- func (c BaseCollection) Each(func(item, value interface{}) (interface{}, bool)) Collection
- func (c BaseCollection) Every(CB) bool
- func (c BaseCollection) Except([]string) Collection
- func (c BaseCollection) Filter(CB) Collection
- func (c BaseCollection) First(...CB) interface{}
- func (c BaseCollection) FirstWhere(key string, values ...interface{}) map[string]interface{}
- func (c BaseCollection) FlatMap(func(value interface{}) interface{}) Collection
- func (c BaseCollection) Flip() Collection
- func (c BaseCollection) ForPage(int, int) Collection
- func (c BaseCollection) Forget(string) Collection
- func (c BaseCollection) Get(string, ...interface{}) interface{}
- func (c BaseCollection) GroupBy(string) Collection
- func (c BaseCollection) Has(...string) bool
- func (c BaseCollection) Implode(string, string) string
- func (c BaseCollection) Intersect([]string) Collection
- func (c BaseCollection) IntersectByKeys(map[string]interface{}) Collection
- func (c BaseCollection) IsEmpty() bool
- func (c BaseCollection) IsNotEmpty() bool
- func (c BaseCollection) Join(delimiter string) string
- func (c BaseCollection) KeyBy(interface{}) Collection
- func (c BaseCollection) Keys() Collection
- func (c BaseCollection) Last(...CB) interface{}
- func (c BaseCollection) Length() int
- func (c BaseCollection) MapToGroups(MapCB) Collection
- func (c BaseCollection) MapWithKeys(MapCB) Collection
- func (c BaseCollection) Max(key ...string) decimal.Decimal
- func (c BaseCollection) Median(key ...string) decimal.Decimal
- func (c BaseCollection) Merge(interface{}) Collection
- func (c BaseCollection) Min(key ...string) decimal.Decimal
- func (c BaseCollection) Mode(key ...string) []interface{}
- func (c BaseCollection) Nth(...int) Collection
- func (c BaseCollection) Only(keys []string) Collection
- func (c BaseCollection) Pad(int, interface{}) Collection
- func (c BaseCollection) Partition(PartCB) (Collection, Collection)
- func (c BaseCollection) Pluck(key string) Collection
- func (c BaseCollection) Pop() interface{}
- func (c BaseCollection) Prepend(values ...interface{}) Collection
- func (c BaseCollection) Pull(key interface{}) Collection
- func (c BaseCollection) Push(interface{}) Collection
- func (c BaseCollection) Put(key string, value interface{}) Collection
- func (c BaseCollection) Random(...int) Collection
- func (c BaseCollection) Reduce(ReduceCB) interface{}
- func (c BaseCollection) Reject(CB) Collection
- func (c BaseCollection) Reverse() Collection
- func (c BaseCollection) Search(interface{}) int
- func (c BaseCollection) Select(keys ...string) Collection
- func (c BaseCollection) Shift() Collection
- func (c BaseCollection) Shuffle() Collection
- func (c BaseCollection) Slice(...int) Collection
- func (c BaseCollection) Sort() Collection
- func (c BaseCollection) SortBy(key string) Collection
- func (c BaseCollection) SortByDesc() Collection
- func (c BaseCollection) Splice(index ...int) Collection
- func (c BaseCollection) Split(int) Collection
- func (c BaseCollection) Sum(key ...string) decimal.Decimal
- func (c BaseCollection) Take(num int) Collection
- func (c BaseCollection) ToInt64Array() []int64
- func (c BaseCollection) ToIntArray() []int
- func (c BaseCollection) ToJson() string
- func (c BaseCollection) ToMap() map[string]interface{}
- func (c BaseCollection) ToMapArray() []map[string]interface{}
- func (c BaseCollection) ToMultiDimensionalArray() [][]interface{}
- func (c BaseCollection) ToNumberArray() []decimal.Decimal
- func (c BaseCollection) ToStringArray() []string
- func (c BaseCollection) ToStruct(dist interface{})
- func (c BaseCollection) Unique() Collection
- func (c BaseCollection) Value() interface{}
- func (c BaseCollection) Where(key string, values ...interface{}) Collection
- func (c BaseCollection) WhereIn(string, []interface{}) Collection
- func (c BaseCollection) WhereNotIn(string, []interface{}) Collection
- type CB
- type Collection
- type FilterFun
- type MapArrayCollection
- func (c MapArrayCollection) All() []interface{}
- func (c MapArrayCollection) Avg(key ...string) decimal.Decimal
- func (c MapArrayCollection) Chunk(num int) MultiDimensionalArrayCollection
- func (c MapArrayCollection) Concat(value interface{}) Collection
- func (c MapArrayCollection) CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection
- func (c MapArrayCollection) Dd()
- func (c MapArrayCollection) Dump()
- func (c MapArrayCollection) Each(cb func(item, value interface{}) (interface{}, bool)) Collection
- func (c MapArrayCollection) Every(cb CB) bool
- func (c MapArrayCollection) Filter(cb CB) Collection
- func (c MapArrayCollection) First(cbs ...CB) interface{}
- func (c MapArrayCollection) FirstWhere(key string, values ...interface{}) map[string]interface{}
- func (c MapArrayCollection) GroupBy(k string) Collection
- func (c MapArrayCollection) Implode(key string, delimiter string) string
- func (c MapArrayCollection) IsEmpty() bool
- func (c MapArrayCollection) IsNotEmpty() bool
- func (c MapArrayCollection) KeyBy(v interface{}) Collection
- func (c MapArrayCollection) Last(cbs ...CB) interface{}
- func (c MapArrayCollection) Length() int
- func (c MapArrayCollection) MapToGroups(cb MapCB) Collection
- func (c MapArrayCollection) MapWithKeys(cb MapCB) Collection
- func (c MapArrayCollection) Max(key ...string) decimal.Decimal
- func (c MapArrayCollection) Median(key ...string) decimal.Decimal
- func (c MapArrayCollection) Min(key ...string) decimal.Decimal
- func (c MapArrayCollection) Mode(key ...string) []interface{}
- func (c MapArrayCollection) Only(keys []string) Collection
- func (c MapArrayCollection) Partition(cb PartCB) (Collection, Collection)
- func (c MapArrayCollection) Pluck(key string) Collection
- func (c MapArrayCollection) Pop() interface{}
- func (c MapArrayCollection) Prepend(values ...interface{}) Collection
- func (c MapArrayCollection) Push(v interface{}) Collection
- func (c MapArrayCollection) Random(num ...int) Collection
- func (c MapArrayCollection) Reduce(cb ReduceCB) interface{}
- func (c MapArrayCollection) Reject(cb CB) Collection
- func (c MapArrayCollection) Reverse() Collection
- func (c MapArrayCollection) Search(v interface{}) int
- func (c MapArrayCollection) Select(keys ...string) Collection
- func (c MapArrayCollection) Shift() Collection
- func (c MapArrayCollection) Shuffle() Collection
- func (c MapArrayCollection) Slice(keys ...int) Collection
- func (c MapArrayCollection) Splice(index ...int) Collection
- func (c MapArrayCollection) Split(num int) Collection
- func (c MapArrayCollection) Sum(key ...string) decimal.Decimal
- func (c MapArrayCollection) Take(num int) Collection
- func (c MapArrayCollection) ToJson() string
- func (c MapArrayCollection) ToMapArray() []map[string]interface{}
- func (c MapArrayCollection) ToStruct(dist interface{})
- func (c MapArrayCollection) Where(key string, values ...interface{}) Collection
- func (c MapArrayCollection) WhereIn(key string, in []interface{}) Collection
- func (c MapArrayCollection) WhereNotIn(key string, in []interface{}) Collection
- type MapCB
- type MapCollection
- func (c MapCollection) Contains(value ...interface{}) bool
- func (c MapCollection) Dd()
- func (c MapCollection) DiffAssoc(m map[string]interface{}) Collection
- func (c MapCollection) DiffKeys(m map[string]interface{}) Collection
- func (c MapCollection) Dump()
- func (c MapCollection) Each(cb func(item, value interface{}) (interface{}, bool)) Collection
- func (c MapCollection) Every(cb CB) bool
- func (c MapCollection) Except(keys []string) Collection
- func (c MapCollection) FlatMap(cb func(value interface{}) interface{}) Collection
- func (c MapCollection) Flip() Collection
- func (c MapCollection) Forget(k string) Collection
- func (c MapCollection) Get(k string, v ...interface{}) interface{}
- func (c MapCollection) Has(keys ...string) bool
- func (c MapCollection) IntersectByKeys(m map[string]interface{}) Collection
- func (c MapCollection) IsEmpty() bool
- func (c MapCollection) IsNotEmpty() bool
- func (c MapCollection) Keys() Collection
- func (c MapCollection) Merge(i interface{}) Collection
- func (c MapCollection) Only(keys []string) Collection
- func (c MapCollection) Prepend(values ...interface{}) Collection
- func (c MapCollection) Select(keys ...string) Collection
- func (c MapCollection) ToJson() string
- func (c MapCollection) ToMap() map[string]interface{}
- func (c MapCollection) ToStruct(dist interface{})
- type MultiDimensionalArrayCollection
- func (c MultiDimensionalArrayCollection) Collapse() Collection
- func (c MultiDimensionalArrayCollection) Concat(value interface{}) Collection
- func (c MultiDimensionalArrayCollection) Dd()
- func (c MultiDimensionalArrayCollection) Dump()
- func (c MultiDimensionalArrayCollection) ToJson() string
- func (c MultiDimensionalArrayCollection) ToMultiDimensionalArray() [][]interface{}
- func (c MultiDimensionalArrayCollection) Value() interface{}
- type NumberArrayCollection
- func (c NumberArrayCollection) All() []interface{}
- func (c NumberArrayCollection) Avg(key ...string) decimal.Decimal
- func (c NumberArrayCollection) Chunk(num int) MultiDimensionalArrayCollection
- func (c NumberArrayCollection) Concat(value interface{}) Collection
- func (c NumberArrayCollection) Contains(value ...interface{}) bool
- func (c NumberArrayCollection) CountBy(callback ...interface{}) map[interface{}]int
- func (c NumberArrayCollection) CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection
- func (c NumberArrayCollection) Dd()
- func (c NumberArrayCollection) Diff(m interface{}) Collection
- func (c NumberArrayCollection) Dump()
- func (c NumberArrayCollection) Each(cb func(item, value interface{}) (interface{}, bool)) Collection
- func (c NumberArrayCollection) Every(cb CB) bool
- func (c NumberArrayCollection) Filter(cb CB) Collection
- func (c NumberArrayCollection) First(cbs ...CB) interface{}
- func (c NumberArrayCollection) ForPage(page, size int) Collection
- func (c NumberArrayCollection) IsEmpty() bool
- func (c NumberArrayCollection) IsNotEmpty() bool
- func (c NumberArrayCollection) Last(cbs ...CB) interface{}
- func (c NumberArrayCollection) Length() int
- func (c NumberArrayCollection) Max(key ...string) decimal.Decimal
- func (c NumberArrayCollection) Median(key ...string) decimal.Decimal
- func (c NumberArrayCollection) Merge(i interface{}) Collection
- func (c NumberArrayCollection) Min(key ...string) decimal.Decimal
- func (c NumberArrayCollection) Mode(key ...string) []interface{}
- func (c NumberArrayCollection) Pad(num int, value interface{}) Collection
- func (c NumberArrayCollection) Partition(cb PartCB) (Collection, Collection)
- func (c NumberArrayCollection) Pop() interface{}
- func (c NumberArrayCollection) Prepend(values ...interface{}) Collection
- func (c NumberArrayCollection) Push(v interface{}) Collection
- func (c NumberArrayCollection) Random(num ...int) Collection
- func (c NumberArrayCollection) Reduce(cb ReduceCB) interface{}
- func (c NumberArrayCollection) Reject(cb CB) Collection
- func (c NumberArrayCollection) Reverse() Collection
- func (c NumberArrayCollection) Search(v interface{}) int
- func (c NumberArrayCollection) Shift() Collection
- func (c NumberArrayCollection) Shuffle() Collection
- func (c NumberArrayCollection) Slice(keys ...int) Collection
- func (c NumberArrayCollection) Sort() Collection
- func (c NumberArrayCollection) SortByDesc() Collection
- func (c NumberArrayCollection) Splice(index ...int) Collection
- func (c NumberArrayCollection) Split(num int) Collection
- func (c NumberArrayCollection) Sum(key ...string) decimal.Decimal
- func (c NumberArrayCollection) Take(num int) Collection
- func (c NumberArrayCollection) ToInt64Array() []int64
- func (c NumberArrayCollection) ToIntArray() []int
- func (c NumberArrayCollection) ToJson() string
- func (c NumberArrayCollection) ToNumberArray() []decimal.Decimal
- func (c NumberArrayCollection) Unique() Collection
- type PartCB
- type ReduceCB
- type StringArrayCollection
- func (c StringArrayCollection) All() []interface{}
- func (c StringArrayCollection) Chunk(num int) MultiDimensionalArrayCollection
- func (c StringArrayCollection) Combine(value []interface{}) Collection
- func (c StringArrayCollection) Concat(value interface{}) Collection
- func (c StringArrayCollection) Contains(value ...interface{}) bool
- func (c StringArrayCollection) CountBy(callback ...interface{}) map[interface{}]int
- func (c StringArrayCollection) CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection
- func (c StringArrayCollection) Dd()
- func (c StringArrayCollection) Diff(m interface{}) Collection
- func (c StringArrayCollection) Dump()
- func (c StringArrayCollection) Each(cb func(item, value interface{}) (interface{}, bool)) Collection
- func (c StringArrayCollection) Every(cb CB) bool
- func (c StringArrayCollection) Filter(cb CB) Collection
- func (c StringArrayCollection) First(cbs ...CB) interface{}
- func (c StringArrayCollection) ForPage(page, size int) Collection
- func (c StringArrayCollection) Intersect(keys []string) Collection
- func (c StringArrayCollection) IsEmpty() bool
- func (c StringArrayCollection) IsNotEmpty() bool
- func (c StringArrayCollection) Join(delimiter string) string
- func (c StringArrayCollection) Last(cbs ...CB) interface{}
- func (c StringArrayCollection) Length() int
- func (c StringArrayCollection) Merge(i interface{}) Collection
- func (c StringArrayCollection) Mode(key ...string) []interface{}
- func (c StringArrayCollection) Pad(num int, value interface{}) Collection
- func (c StringArrayCollection) Partition(cb PartCB) (Collection, Collection)
- func (c StringArrayCollection) Pop() interface{}
- func (c StringArrayCollection) Prepend(values ...interface{}) Collection
- func (c StringArrayCollection) Push(v interface{}) Collection
- func (c StringArrayCollection) Random(num ...int) Collection
- func (c StringArrayCollection) Reduce(cb ReduceCB) interface{}
- func (c StringArrayCollection) Reject(cb CB) Collection
- func (c StringArrayCollection) Reverse() Collection
- func (c StringArrayCollection) Search(v interface{}) int
- func (c StringArrayCollection) Shift() Collection
- func (c StringArrayCollection) Shuffle() Collection
- func (c StringArrayCollection) Slice(keys ...int) Collection
- func (c StringArrayCollection) Splice(index ...int) Collection
- func (c StringArrayCollection) Split(num int) Collection
- func (c StringArrayCollection) Take(num int) Collection
- func (c StringArrayCollection) ToJson() string
- func (c StringArrayCollection) ToStringArray() []string
- func (c StringArrayCollection) Unique() Collection
Examples ¶
- BaseCollection.All
- BaseCollection.Avg
- BaseCollection.Chunk
- BaseCollection.Diff
- BaseCollection.Each
- BaseCollection.Every
- BaseCollection.Except
- BaseCollection.Filter
- BaseCollection.First
- BaseCollection.FirstWhere
- BaseCollection.FlatMap
- BaseCollection.Flip
- BaseCollection.ForPage
- BaseCollection.Forget
- BaseCollection.Get
- BaseCollection.GroupBy
- BaseCollection.Has
- BaseCollection.Implode
- BaseCollection.Intersect
- BaseCollection.IntersectByKeys
- BaseCollection.IsEmpty
- BaseCollection.IsNotEmpty
- BaseCollection.Join
- BaseCollection.KeyBy
- BaseCollection.Keys
- BaseCollection.Last
- BaseCollection.Length
- BaseCollection.Median
- BaseCollection.Merge
- BaseCollection.Mode
- BaseCollection.Pad
- BaseCollection.Partition
- BaseCollection.Pop
- BaseCollection.Push
- BaseCollection.Random
- BaseCollection.Reduce
- BaseCollection.Reject
- BaseCollection.Reverse
- BaseCollection.Search
- BaseCollection.Select
- BaseCollection.Shift
- BaseCollection.Shuffle
- BaseCollection.Slice
- BaseCollection.Sort
- BaseCollection.SortByDesc
- BaseCollection.Splice
- BaseCollection.Split
- BaseCollection.Sum
- BaseCollection.Take
- BaseCollection.ToIntArray
- BaseCollection.ToJson
- BaseCollection.ToMap
- BaseCollection.ToMapArray
- BaseCollection.ToNumberArray
- BaseCollection.ToStringArray
- BaseCollection.ToStruct
- BaseCollection.Unique
- BaseCollection.Where
- BaseCollection.WhereIn
- BaseCollection.WhereNotIn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseCollection ¶
type BaseCollection struct {
// contains filtered or unexported fields
}
func (BaseCollection) All ¶
func (c BaseCollection) All() []interface{}
All returns the underlying array represented by the collection.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).All())
Output: [h e l l o]
func (BaseCollection) Avg ¶
func (c BaseCollection) Avg(key ...string) decimal.Decimal
Avg returns the average value of a given key.
Example ¶
var floatTest = []float64{143.66, -14.55} fmt.Println(Collect(floatTest).Avg().String())
Output: 64.555
func (BaseCollection) Chunk ¶
func (c BaseCollection) Chunk(num int) MultiDimensionalArrayCollection
Chunk breaks the collection into multiple, smaller collections of a given size.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).Chunk(3).ToMultiDimensionalArray()[0])
Output: [h e l]
func (BaseCollection) Collapse ¶
func (c BaseCollection) Collapse() Collection
Collapse collapses a collection of arrays into a single, flat collection.
func (BaseCollection) Combine ¶
func (c BaseCollection) Combine(value []interface{}) Collection
Combine combines the values of the collection, as keys, with the values of another array or collection.
func (BaseCollection) Concat ¶
func (c BaseCollection) Concat(value interface{}) Collection
Concat appends the given array or collection values onto the end of the collection.
func (BaseCollection) Contains ¶
func (c BaseCollection) Contains(value ...interface{}) bool
Contains determines whether the collection contains a given item.
func (BaseCollection) Count ¶
func (c BaseCollection) Count() int
Count returns the total number of items in the collection.
func (BaseCollection) CountBy ¶
func (c BaseCollection) CountBy(callback ...interface{}) map[interface{}]int
CountBy counts the occurrences of values in the collection. By default, the method counts the occurrences of every element.
func (BaseCollection) CrossJoin ¶
func (c BaseCollection) CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection
CrossJoin cross joins the collection's values among the given arrays or collections, returning a Cartesian product with all possible permutations.
func (BaseCollection) Dd ¶
func (c BaseCollection) Dd()
Dd dumps the collection's items and ends execution of the script.
func (BaseCollection) Diff ¶
func (c BaseCollection) Diff(interface{}) Collection
Diff compares the collection against another collection or a plain PHP array based on its values. This method will return the values in the original collection that are not present in the given collection.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).Diff([]string{"e", "o"}).ToStringArray())
Output: [h l l]
func (BaseCollection) DiffAssoc ¶
func (c BaseCollection) DiffAssoc(map[string]interface{}) Collection
DiffAssoc compares the collection against another collection or a plain PHP array based on its keys and values. This method will return the key / value pairs in the original collection that are not present in the given collection.
func (BaseCollection) DiffKeys ¶
func (c BaseCollection) DiffKeys(map[string]interface{}) Collection
DiffKeys compares the collection against another collection or a plain PHP array based on its keys. This method will return the key / value pairs in the original collection that are not present in the given collection.
func (BaseCollection) Each ¶
func (c BaseCollection) Each(func(item, value interface{}) (interface{}, bool)) Collection
Each iterates over the items in the collection and passes each item to a callback.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Each(func(item, value interface{}) (interface{}, bool) { return value.(decimal.Decimal).IntPart() + 2, false }).ToIntArray())
Output: [4 5 6 7 8 9]
func (BaseCollection) Every ¶
func (c BaseCollection) Every(CB) bool
Every may be used to verify that all elements of a collection pass a given truth test.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Every(func(item, value interface{}) bool { return value.(decimal.Decimal).GreaterThanOrEqual(nd(5)) }))
Output: false
func (BaseCollection) Except ¶
func (c BaseCollection) Except([]string) Collection
Except returns all items in the collection except for those with the specified keys.
Example ¶
a := map[string]interface{}{ "name": "mike", "sex": 1, } fmt.Println(Collect(a).Except([]string{"name"}).ToMap())
Output: map[sex:1]
func (BaseCollection) Filter ¶
func (c BaseCollection) Filter(CB) Collection
Filter filters the collection using the given callback, keeping only those items that pass a given truth test.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Filter(func(item, value interface{}) bool { return value.(decimal.Decimal).IntPart() > 4 }).ToIntArray())
Output: [5 6 7]
func (BaseCollection) First ¶
func (c BaseCollection) First(...CB) interface{}
First returns the first element in the collection that passes a given truth test.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).First(func(item, value interface{}) bool { return value.(decimal.Decimal).IntPart() > 4 }))
Output: 5
func (BaseCollection) FirstWhere ¶
func (c BaseCollection) FirstWhere(key string, values ...interface{}) map[string]interface{}
FirstWhere returns the first element in the collection with the given key / value pair.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 1}, } fmt.Println(Collect(a).FirstWhere("sex", 1))
Output: map[name:Mary sex:1]
func (BaseCollection) FlatMap ¶
func (c BaseCollection) FlatMap(func(value interface{}) interface{}) Collection
FlatMap iterates through the collection and passes each value to the given callback.
Example ¶
a := map[string]interface{}{ "name": "mike", } fmt.Println(Collect(a).FlatMap(func(value interface{}) interface{} { return "user_" + value.(string) }).ToMap())
Output: map[name:user_mike]
func (BaseCollection) Flip ¶
func (c BaseCollection) Flip() Collection
Flip swaps the collection's keys with their corresponding values.
Example ¶
a := map[string]interface{}{ "name": "mike", } fmt.Println(Collect(a).Flip().ToMap())
Output: map[mike:name]
func (BaseCollection) ForPage ¶
func (c BaseCollection) ForPage(int, int) Collection
ForPage returns a new collection containing the items that would be present on a given page number.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).ForPage(2, 3).ToIntArray())
Output: [5 6 7]
func (BaseCollection) Forget ¶
func (c BaseCollection) Forget(string) Collection
Forget removes an item from the collection by its key.
Example ¶
a := map[string]interface{}{ "name": "mike", "sex": 1, } fmt.Println(Collect(a).Forget("name").ToMap())
Output: map[sex:1]
func (BaseCollection) Get ¶
func (c BaseCollection) Get(string, ...interface{}) interface{}
Get returns the item at a given key. If the key does not exist, null is returned.
Example ¶
a := map[string]interface{}{ "name": "mike", } fmt.Println(Collect(a).Get("name"))
Output: mike
func (BaseCollection) GroupBy ¶
func (c BaseCollection) GroupBy(string) Collection
GroupBy groups the collection's items by a given key.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 1}, } fmt.Println(Collect(a).GroupBy("sex").ToMap()["1"])
Output: [map[name:Mary sex:1] map[name:Jane sex:1]]
func (BaseCollection) Has ¶
func (c BaseCollection) Has(...string) bool
Has determines if a given key exists in the collection.
Example ¶
a := map[string]interface{}{ "name": "mike", } fmt.Println(Collect(a).Has("name"))
Output: true
func (BaseCollection) Implode ¶
func (c BaseCollection) Implode(string, string) string
Implode joins the items in a collection. Its arguments depend on the type of items in the collection.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 1}, } fmt.Println(Collect(a).Implode("name", "|"))
Output: mike|Mary|Jane
func (BaseCollection) Intersect ¶
func (c BaseCollection) Intersect([]string) Collection
Intersect removes any values from the original collection that are not present in the given array or collection.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).Intersect([]string{"e", "l", "l", "f"}).ToStringArray())
Output: [e l l]
func (BaseCollection) IntersectByKeys ¶
func (c BaseCollection) IntersectByKeys(map[string]interface{}) Collection
IntersectByKeys removes any keys from the original collection that are not present in the given array or collection.
Example ¶
a := map[string]interface{}{ "name": "mike", "sex": 0, } fmt.Println(Collect(a).IntersectByKeys(map[string]interface{}{ "name": "mike", "city": "beijing", }).ToMap())
Output: map[name:mike]
func (BaseCollection) IsEmpty ¶
func (c BaseCollection) IsEmpty() bool
IsEmpty returns true if the collection is empty; otherwise, false is returned.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).IsEmpty())
Output: false
func (BaseCollection) IsNotEmpty ¶
func (c BaseCollection) IsNotEmpty() bool
IsNotEmpty returns true if the collection is not empty; otherwise, false is returned.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).IsNotEmpty())
Output: true
func (BaseCollection) Join ¶
func (c BaseCollection) Join(delimiter string) string
Join joins the collection's values with a string.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).Join(""))
Output: hello
func (BaseCollection) KeyBy ¶
func (c BaseCollection) KeyBy(interface{}) Collection
KeyBy keys the collection by the given key. If multiple items have the same key, only the last one will appear in the new collection.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 1}, } fmt.Println(Collect(a).KeyBy("sex").ToMap()["1"])
Output: [map[name:Jane sex:1]]
func (BaseCollection) Keys ¶
func (c BaseCollection) Keys() Collection
Keys returns all of the collection's keys.
Example ¶
a := map[string]interface{}{ "name": "mike", "sex": 1, } fmt.Println(Collect(a).Keys().ToStringArray())
Output:
func (BaseCollection) Last ¶
func (c BaseCollection) Last(...CB) interface{}
Last returns the last element in the collection that passes a given truth test.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Last(func(item, value interface{}) bool { return value.(decimal.Decimal).IntPart() > 4 }))
Output: 7
func (BaseCollection) Length ¶
func (c BaseCollection) Length() int
Length return the length of the collection.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 2}, } fmt.Println(Collect(a).Length())
Output: 3
func (BaseCollection) MapToGroups ¶
func (c BaseCollection) MapToGroups(MapCB) Collection
MapToGroups groups the collection's items by the given callback.
func (BaseCollection) MapWithKeys ¶
func (c BaseCollection) MapWithKeys(MapCB) Collection
MapWithKeys iterates through the collection and passes each value to the given callback.
func (BaseCollection) Max ¶
func (c BaseCollection) Max(key ...string) decimal.Decimal
Max returns the maximum value of a given key.
func (BaseCollection) Median ¶
func (c BaseCollection) Median(key ...string) decimal.Decimal
Median returns the median value of a given key.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Median())
Output: 4.5
func (BaseCollection) Merge ¶
func (c BaseCollection) Merge(interface{}) Collection
Merge merges the given array or collection with the original collection. If a string key in the given items matches a string key in the original collection, the given items's value will overwrite the value in the original collection.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Merge([]int{8, 9}).ToIntArray())
Output: [2 3 4 5 6 7 8 9]
func (BaseCollection) Min ¶
func (c BaseCollection) Min(key ...string) decimal.Decimal
Min returns the minimum value of a given key.
func (BaseCollection) Mode ¶
func (c BaseCollection) Mode(key ...string) []interface{}
Mode returns the mode value of a given key.
Example ¶
foo2 := []map[string]interface{}{ { "foo": 10, }, { "foo": 30, }, { "foo": 20, }, { "foo": 40, }, { "foo": 40, }, } fmt.Println(Collect(`["h", "e", "l", "l", "o", "w", "o", "l", "d"]`).Mode()) fmt.Println(Collect(foo2).Mode("foo"))
Output: [l] [40]
func (BaseCollection) Nth ¶
func (c BaseCollection) Nth(...int) Collection
func (BaseCollection) Only ¶
func (c BaseCollection) Only(keys []string) Collection
Only returns the items in the collection with the specified keys.
func (BaseCollection) Pad ¶
func (c BaseCollection) Pad(int, interface{}) Collection
Pad will fill the array with the given value until the array reaches the specified size.
Example ¶
a := []int{2} fmt.Println(Collect(a).Pad(3, 0).ToIntArray())
Output: [2 0 0]
func (BaseCollection) Partition ¶
func (c BaseCollection) Partition(PartCB) (Collection, Collection)
Partition separate elements that pass a given truth test from those that do not.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} p1, p2 := Collect(a).Partition(func(i int) bool { return i > 3 }) fmt.Println(p1.ToIntArray()) fmt.Println(p2.ToIntArray())
Output: [6 7] [2 3 4 5]
func (BaseCollection) Pluck ¶
func (c BaseCollection) Pluck(key string) Collection
Pluck retrieves all of the values for a given key.
func (BaseCollection) Pop ¶
func (c BaseCollection) Pop() interface{}
Pop removes and returns the last item from the collection.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Pop())
Output: 7
func (BaseCollection) Prepend ¶
func (c BaseCollection) Prepend(values ...interface{}) Collection
Prepend adds an item to the beginning of the collection.
func (BaseCollection) Pull ¶
func (c BaseCollection) Pull(key interface{}) Collection
Pull removes and returns an item from the collection by its key.
func (BaseCollection) Push ¶
func (c BaseCollection) Push(interface{}) Collection
Push appends an item to the end of the collection.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Push(8).ToIntArray())
Output: [2 3 4 5 6 7 8]
func (BaseCollection) Put ¶
func (c BaseCollection) Put(key string, value interface{}) Collection
Put sets the given key and value in the collection:.
func (BaseCollection) Random ¶
func (c BaseCollection) Random(...int) Collection
Random returns a random item from the collection.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Random().Value())
Output:
func (BaseCollection) Reduce ¶
func (c BaseCollection) Reduce(ReduceCB) interface{}
Reduce reduces the collection to a single value, passing the result of each iteration into the subsequent iteration.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Reduce(func(i interface{}, i2 interface{}) interface{} { if i == nil { return i2 } else { return i.(decimal.Decimal).Add(i2.(decimal.Decimal)) } }))
Output: 27
func (BaseCollection) Reject ¶
func (c BaseCollection) Reject(CB) Collection
Reject filters the collection using the given callback.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Reject(func(item, value interface{}) bool { return value.(decimal.Decimal).GreaterThanOrEqual(nd(3)) }).ToIntArray())
Output: [2]
func (BaseCollection) Reverse ¶
func (c BaseCollection) Reverse() Collection
Reverse reverses the order of the collection's items, preserving the original keys.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Reverse().ToIntArray())
Output: [7 6 5 4 3 2]
func (BaseCollection) Search ¶
func (c BaseCollection) Search(interface{}) int
Search searches the collection for the given value and returns its key if found. If the item is not found, -1 is returned.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Search(3))
Output: 1
func (BaseCollection) Select ¶
func (c BaseCollection) Select(keys ...string) Collection
Select select the keys of collection and delete others.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 2}, } fmt.Println(Collect(a).Select("sex").ToMapArray())
Output: [map[sex:0] map[sex:1] map[sex:2]]
func (BaseCollection) Shift ¶
func (c BaseCollection) Shift() Collection
Shift removes and returns the first item from the collection.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Shift().ToIntArray())
Output: [3 4 5 6 7]
func (BaseCollection) Shuffle ¶
func (c BaseCollection) Shuffle() Collection
Shuffle randomly shuffles the items in the collection.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Shuffle().ToIntArray())
Output:
func (BaseCollection) Slice ¶
func (c BaseCollection) Slice(...int) Collection
Slice returns a slice of the collection starting at the given index.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Slice(1, 2).ToIntArray())
Output: [3 4]
func (BaseCollection) Sort ¶
func (c BaseCollection) Sort() Collection
Sort sorts the collection.
Example ¶
a := []int{4, 5, 2, 3, 6, 7} fmt.Println(Collect(a).Sort().ToIntArray())
Output: [2 3 4 5 6 7]
func (BaseCollection) SortBy ¶
func (c BaseCollection) SortBy(key string) Collection
SortBy sorts the collection by the given key.
func (BaseCollection) SortByDesc ¶
func (c BaseCollection) SortByDesc() Collection
SortByDesc has the same signature as the sortBy method, but will sort the collection in the opposite order.
Example ¶
a := []int{4, 5, 2, 3, 6, 7} fmt.Println(Collect(a).SortByDesc().ToIntArray())
Output: [7 6 5 4 3 2]
func (BaseCollection) Splice ¶
func (c BaseCollection) Splice(index ...int) Collection
Split breaks a collection into the given number of groups.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).Splice(1, 3).ToStringArray())
Output: [e l l]
func (BaseCollection) Split ¶
func (c BaseCollection) Split(int) Collection
Splice removes and returns a slice of items starting at the specified index.
Example ¶
a := []int{2, 3, 4, 5, 6, 7} fmt.Println(Collect(a).Split(3).Value())
Output:
func (BaseCollection) Sum ¶
func (c BaseCollection) Sum(key ...string) decimal.Decimal
Sum returns the sum of all items in the collection.
Example ¶
var floatTest = []float64{143.66, -14.55} fmt.Println(Collect(floatTest).Sum().String())
Output: 129.11
func (BaseCollection) Take ¶
func (c BaseCollection) Take(num int) Collection
Take returns a new collection with the specified number of items.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).Take(-2).ToStringArray())
Output: [l o]
func (BaseCollection) ToInt64Array ¶
func (c BaseCollection) ToInt64Array() []int64
ToInt64Array converts the collection into a plain golang slice which contains int64.
func (BaseCollection) ToIntArray ¶
func (c BaseCollection) ToIntArray() []int
ToIntArray converts the collection into a plain golang slice which contains int.
Example ¶
a := []int{4, 5, 2, 3, 6, 7} fmt.Println(Collect(a).ToIntArray())
Output: [4 5 2 3 6 7]
func (BaseCollection) ToJson ¶
func (c BaseCollection) ToJson() string
ToJson converts the collection into a json string.
Example ¶
a := []int{4, 5, 5, 2, 2, 3, 6, 6, 7} fmt.Println(Collect(a).Unique().ToJson())
Output: ["4","5","2","3","6","7"]
func (BaseCollection) ToMap ¶
func (c BaseCollection) ToMap() map[string]interface{}
ToMap converts the collection into a plain golang map.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).ToStringArray())
Output: [h e l l o]
func (BaseCollection) ToMapArray ¶
func (c BaseCollection) ToMapArray() []map[string]interface{}
ToMapArray converts the collection into a plain golang slice which contains map.
Example ¶
a := []map[string]interface{}{ {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 2}, } fmt.Println(Collect(a).ToMapArray())
Output: [map[name:Mary sex:1] map[name:Jane sex:2]]
func (BaseCollection) ToMultiDimensionalArray ¶
func (c BaseCollection) ToMultiDimensionalArray() [][]interface{}
ToStringArray converts the collection into a plain golang slice which contains string.
func (BaseCollection) ToNumberArray ¶
func (c BaseCollection) ToNumberArray() []decimal.Decimal
ToNumberArray converts the collection into a plain golang slice which contains decimal.Decimal.
Example ¶
a := []int{4, 5, 2, 3, 6, 7} fmt.Println(Collect(a).ToNumberArray())
Output:
func (BaseCollection) ToStringArray ¶
func (c BaseCollection) ToStringArray() []string
ToStringArray converts the collection into a plain golang slice which contains string.
Example ¶
a := []string{"h", "e", "l", "l", "o"} fmt.Println(Collect(a).ToStringArray())
Output: [h e l l o]
func (BaseCollection) ToStruct ¶
func (c BaseCollection) ToStruct(dist interface{})
ToStruct turn the collection to the specified struct using mapstructure. https://github.com/mitchellh/mapstructure
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 2}, } type People struct { Name string Sex int } var people = make([]People, 3) Collect(a).ToStruct(&people) fmt.Println(people)
Output: [{mike 0} {Mary 1} {Jane 2}]
func (BaseCollection) Unique ¶
func (c BaseCollection) Unique() Collection
Unique returns all of the unique items in the collection.
Example ¶
a := []int{4, 5, 5, 2, 2, 3, 6, 6, 7} fmt.Println(Collect(a).Unique().ToIntArray())
Output: [4 5 2 3 6 7]
func (BaseCollection) Value ¶
func (c BaseCollection) Value() interface{}
func (BaseCollection) Where ¶
func (c BaseCollection) Where(key string, values ...interface{}) Collection
Where filters the collection by a given key / value pair.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 2}, } Collect(a).Where("sex", ">", 1).ToMapArray() Collect(a).Where("sex", "<", 1).ToMapArray() fmt.Println(Collect(a).Where("sex", 2).ToMapArray())
Output: [map[name:Jane sex:2]]
func (BaseCollection) WhereIn ¶
func (c BaseCollection) WhereIn(string, []interface{}) Collection
WhereIn filters the collection by a given key / value contained within the given array.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 2}, } fmt.Println(Collect(a).WhereIn("sex", []interface{}{1, 2}).ToMapArray())
Output:
func (BaseCollection) WhereNotIn ¶
func (c BaseCollection) WhereNotIn(string, []interface{}) Collection
WhereNotIn filters the collection by a given key / value not contained within the given array.
Example ¶
a := []map[string]interface{}{ {"name": "mike", "sex": 0}, {"name": "Mary", "sex": 1}, {"name": "Jane", "sex": 2}, } fmt.Println(Collect(a).WhereNotIn("sex", []interface{}{1, 2}).ToMapArray())
Output: [map[name:mike sex:0]]
type Collection ¶
type Collection interface { Value() interface{} // All returns the underlying array represented by the collection. All() []interface{} // Length return the length of the collection. Length() int // ToStruct turn the collection to the specified struct using mapstructure. // https://github.com/mitchellh/mapstructure ToStruct(dist interface{}) // Select select the keys of collection and delete others. Select(keys ...string) Collection // Avg returns the average value of a given key. Avg(key ...string) decimal.Decimal // Sum returns the sum of all items in the collection. Sum(key ...string) decimal.Decimal // Min returns the minimum value of a given key. Min(key ...string) decimal.Decimal // Max returns the maximum value of a given key. Max(key ...string) decimal.Decimal // Join joins the collection's values with a string. Join(delimiter string) string // Combine combines the values of the collection, as keys, with the values of another array or collection. Combine(value []interface{}) Collection // Count returns the total number of items in the collection. Count() int // Pluck retrieves all of the values for a given key. Pluck(key string) Collection // Mode returns the mode value of a given key. Mode(key ...string) []interface{} // Only returns the items in the collection with the specified keys. Only(keys []string) Collection // Prepend adds an item to the beginning of the collection. Prepend(values ...interface{}) Collection // Pull removes and returns an item from the collection by its key. Pull(key interface{}) Collection // Put sets the given key and value in the collection:. Put(key string, value interface{}) Collection // SortBy sorts the collection by the given key. SortBy(key string) Collection // Take returns a new collection with the specified number of items. Take(num int) Collection // Chunk breaks the collection into multiple, smaller collections of a given size. Chunk(num int) MultiDimensionalArrayCollection // Collapse collapses a collection of arrays into a single, flat collection. Collapse() Collection // Concat appends the given array or collection values onto the end of the collection. Concat(value interface{}) Collection // Contains determines whether the collection contains a given item. Contains(value ...interface{}) bool // CountBy counts the occurrences of values in the collection. By default, the method counts the occurrences of every element. CountBy(callback ...interface{}) map[interface{}]int // CrossJoin cross joins the collection's values among the given arrays or collections, returning a Cartesian product with all possible permutations. CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection // Dd dumps the collection's items and ends execution of the script. Dd() // Diff compares the collection against another collection or a plain PHP array based on its values. // This method will return the values in the original collection that are not present in the given collection. Diff(interface{}) Collection // DiffAssoc compares the collection against another collection or a plain PHP array based on its keys and values. // This method will return the key / value pairs in the original collection that are not present in the given collection. DiffAssoc(map[string]interface{}) Collection // DiffKeys compares the collection against another collection or a plain PHP array based on its keys. // This method will return the key / value pairs in the original collection that are not present in the given collection. DiffKeys(map[string]interface{}) Collection // Dump dumps the collection's items. Dump() // Each iterates over the items in the collection and passes each item to a callback. Each(func(item, value interface{}) (interface{}, bool)) Collection // Every may be used to verify that all elements of a collection pass a given truth test. Every(CB) bool // Except returns all items in the collection except for those with the specified keys. Except([]string) Collection // Filter filters the collection using the given callback, keeping only those items that pass a given truth test. Filter(CB) Collection // First returns the first element in the collection that passes a given truth test. First(...CB) interface{} // FirstWhere returns the first element in the collection with the given key / value pair. FirstWhere(key string, values ...interface{}) map[string]interface{} // FlatMap iterates through the collection and passes each value to the given callback. FlatMap(func(value interface{}) interface{}) Collection // Flip swaps the collection's keys with their corresponding values. Flip() Collection // Forget removes an item from the collection by its key. Forget(string) Collection // ForPage returns a new collection containing the items that would be present on a given page number. ForPage(int, int) Collection // Get returns the item at a given key. If the key does not exist, null is returned. Get(string, ...interface{}) interface{} // GroupBy groups the collection's items by a given key. GroupBy(string) Collection // Has determines if a given key exists in the collection. Has(...string) bool // Implode joins the items in a collection. Its arguments depend on the type of items in the collection. Implode(string, string) string // Intersect removes any values from the original collection that are not present in the given array or collection. Intersect([]string) Collection // IntersectByKeys removes any keys from the original collection that are not present in the given array or collection. IntersectByKeys(map[string]interface{}) Collection // IsEmpty returns true if the collection is empty; otherwise, false is returned. IsEmpty() bool // IsNotEmpty returns true if the collection is not empty; otherwise, false is returned. IsNotEmpty() bool // KeyBy keys the collection by the given key. If multiple items have the same key, only the last one will // appear in the new collection. KeyBy(interface{}) Collection // Keys returns all of the collection's keys. Keys() Collection // Last returns the last element in the collection that passes a given truth test. Last(...CB) interface{} // MapToGroups groups the collection's items by the given callback. MapToGroups(MapCB) Collection // MapWithKeys iterates through the collection and passes each value to the given callback. MapWithKeys(MapCB) Collection // Median returns the median value of a given key. Median(...string) decimal.Decimal // Merge merges the given array or collection with the original collection. If a string key in the given items // matches a string key in the original collection, the given items's value will overwrite the value in the // original collection. Merge(interface{}) Collection // Pad will fill the array with the given value until the array reaches the specified size. Pad(int, interface{}) Collection // Partition separate elements that pass a given truth test from those that do not. Partition(PartCB) (Collection, Collection) // Pop removes and returns the last item from the collection. Pop() interface{} // Push appends an item to the end of the collection. Push(interface{}) Collection // Random returns a random item from the collection. Random(...int) Collection // Reduce reduces the collection to a single value, passing the result of each iteration into the subsequent iteration. Reduce(ReduceCB) interface{} // Reject filters the collection using the given callback. Reject(CB) Collection // Reverse reverses the order of the collection's items, preserving the original keys. Reverse() Collection // Search searches the collection for the given value and returns its key if found. If the item is not found, // -1 is returned. Search(interface{}) int // Shift removes and returns the first item from the collection. Shift() Collection // Shuffle randomly shuffles the items in the collection. Shuffle() Collection // Slice returns a slice of the collection starting at the given index. Slice(...int) Collection // Sort sorts the collection. Sort() Collection // SortByDesc has the same signature as the sortBy method, but will sort the collection in the opposite order. SortByDesc() Collection // Splice removes and returns a slice of items starting at the specified index. Splice(index ...int) Collection // Split breaks a collection into the given number of groups. Split(int) Collection // Unique returns all of the unique items in the collection. Unique() Collection // WhereIn filters the collection by a given key / value contained within the given array. WhereIn(string, []interface{}) Collection // WhereNotIn filters the collection by a given key / value not contained within the given array. WhereNotIn(string, []interface{}) Collection // ToJson converts the collection into a json string. ToJson() string // ToNumberArray converts the collection into a plain golang slice which contains decimal.Decimal. ToNumberArray() []decimal.Decimal // ToIntArray converts the collection into a plain golang slice which contains int. ToIntArray() []int // ToInt64Array converts the collection into a plain golang slice which contains int. ToInt64Array() []int64 // ToStringArray converts the collection into a plain golang slice which contains string. ToStringArray() []string // ToMultiDimensionalArray converts the collection into a multi dimensional array. ToMultiDimensionalArray() [][]interface{} // ToMap converts the collection into a plain golang map. ToMap() map[string]interface{} // ToMapArray converts the collection into a plain golang slice which contains map. ToMapArray() []map[string]interface{} // Where filters the collection by a given key / value pair. Where(key string, values ...interface{}) Collection }
func Collect ¶
func Collect(src interface{}) Collection
Collect transforms src into Collection. The src could be json string, []string, []map[string]interface{}, map[string]interface{}, []int, []int16, []int32, []int64, []float32, []float64, []interface{}.
type MapArrayCollection ¶
type MapArrayCollection struct { BaseCollection // contains filtered or unexported fields }
func (MapArrayCollection) All ¶
func (c MapArrayCollection) All() []interface{}
All returns the underlying array represented by the collection.
func (MapArrayCollection) Avg ¶
func (c MapArrayCollection) Avg(key ...string) decimal.Decimal
Sum returns the sum of all items in the collection.
func (MapArrayCollection) Chunk ¶
func (c MapArrayCollection) Chunk(num int) MultiDimensionalArrayCollection
Chunk breaks the collection into multiple, smaller collections of a given size.
func (MapArrayCollection) Concat ¶
func (c MapArrayCollection) Concat(value interface{}) Collection
Concat appends the given array or collection values onto the end of the collection.
func (MapArrayCollection) CrossJoin ¶
func (c MapArrayCollection) CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection
CrossJoin cross joins the collection's values among the given arrays or collections, returning a Cartesian product with all possible permutations.
func (MapArrayCollection) Dd ¶
func (c MapArrayCollection) Dd()
Dd dumps the collection's items and ends execution of the script.
func (MapArrayCollection) Dump ¶
func (c MapArrayCollection) Dump()
Dump dumps the collection's items.
func (MapArrayCollection) Each ¶
func (c MapArrayCollection) Each(cb func(item, value interface{}) (interface{}, bool)) Collection
Each iterates over the items in the collection and passes each item to a callback.
func (MapArrayCollection) Every ¶
func (c MapArrayCollection) Every(cb CB) bool
Every may be used to verify that all elements of a collection pass a given truth test.
func (MapArrayCollection) Filter ¶
func (c MapArrayCollection) Filter(cb CB) Collection
Filter filters the collection using the given callback, keeping only those items that pass a given truth test.
func (MapArrayCollection) First ¶
func (c MapArrayCollection) First(cbs ...CB) interface{}
First returns the first element in the collection that passes a given truth test.
func (MapArrayCollection) FirstWhere ¶
func (c MapArrayCollection) FirstWhere(key string, values ...interface{}) map[string]interface{}
FirstWhere returns the first element in the collection with the given key / value pair.
func (MapArrayCollection) GroupBy ¶
func (c MapArrayCollection) GroupBy(k string) Collection
GroupBy groups the collection's items by a given key.
func (MapArrayCollection) Implode ¶
func (c MapArrayCollection) Implode(key string, delimiter string) string
Implode joins the items in a collection. Its arguments depend on the type of items in the collection.
func (MapArrayCollection) IsEmpty ¶
func (c MapArrayCollection) IsEmpty() bool
IsEmpty returns true if the collection is empty; otherwise, false is returned.
func (MapArrayCollection) IsNotEmpty ¶
func (c MapArrayCollection) IsNotEmpty() bool
IsNotEmpty returns true if the collection is not empty; otherwise, false is returned.
func (MapArrayCollection) KeyBy ¶
func (c MapArrayCollection) KeyBy(v interface{}) Collection
KeyBy keys the collection by the given key. If multiple items have the same key, only the last one will appear in the new collection.
func (MapArrayCollection) Last ¶
func (c MapArrayCollection) Last(cbs ...CB) interface{}
Last returns the last element in the collection that passes a given truth test.
func (MapArrayCollection) Length ¶
func (c MapArrayCollection) Length() int
Length return the length of the collection.
func (MapArrayCollection) MapToGroups ¶
func (c MapArrayCollection) MapToGroups(cb MapCB) Collection
MapToGroups groups the collection's items by the given callback.
func (MapArrayCollection) MapWithKeys ¶
func (c MapArrayCollection) MapWithKeys(cb MapCB) Collection
MapWithKeys iterates through the collection and passes each value to the given callback.
func (MapArrayCollection) Max ¶
func (c MapArrayCollection) Max(key ...string) decimal.Decimal
Max returns the maximum value of a given key.
func (MapArrayCollection) Median ¶
func (c MapArrayCollection) Median(key ...string) decimal.Decimal
Median returns the median value of a given key.
func (MapArrayCollection) Min ¶
func (c MapArrayCollection) Min(key ...string) decimal.Decimal
Min returns the minimum value of a given key.
func (MapArrayCollection) Mode ¶
func (c MapArrayCollection) Mode(key ...string) []interface{}
Mode returns the mode value of a given key.
func (MapArrayCollection) Only ¶
func (c MapArrayCollection) Only(keys []string) Collection
Only returns the items in the collection with the specified keys.
func (MapArrayCollection) Partition ¶
func (c MapArrayCollection) Partition(cb PartCB) (Collection, Collection)
Partition separate elements that pass a given truth test from those that do not.
func (MapArrayCollection) Pluck ¶
func (c MapArrayCollection) Pluck(key string) Collection
Pluck retrieves all of the values for a given key.
func (MapArrayCollection) Pop ¶
func (c MapArrayCollection) Pop() interface{}
Pop removes and returns the last item from the collection.
func (MapArrayCollection) Prepend ¶
func (c MapArrayCollection) Prepend(values ...interface{}) Collection
Prepend adds an item to the beginning of the collection.
func (MapArrayCollection) Push ¶
func (c MapArrayCollection) Push(v interface{}) Collection
Push appends an item to the end of the collection.
func (MapArrayCollection) Random ¶
func (c MapArrayCollection) Random(num ...int) Collection
Random returns a random item from the collection.
func (MapArrayCollection) Reduce ¶
func (c MapArrayCollection) Reduce(cb ReduceCB) interface{}
Reduce reduces the collection to a single value, passing the result of each iteration into the subsequent iteration.
func (MapArrayCollection) Reject ¶
func (c MapArrayCollection) Reject(cb CB) Collection
Reject filters the collection using the given callback.
func (MapArrayCollection) Reverse ¶
func (c MapArrayCollection) Reverse() Collection
Reverse reverses the order of the collection's items, preserving the original keys.
func (MapArrayCollection) Search ¶
func (c MapArrayCollection) Search(v interface{}) int
Search searches the collection for the given value and returns its key if found. If the item is not found, -1 is returned.
func (MapArrayCollection) Select ¶
func (c MapArrayCollection) Select(keys ...string) Collection
Select select the keys of collection and delete others.
func (MapArrayCollection) Shift ¶
func (c MapArrayCollection) Shift() Collection
Shift removes and returns the first item from the collection.
func (MapArrayCollection) Shuffle ¶
func (c MapArrayCollection) Shuffle() Collection
Shuffle randomly shuffles the items in the collection.
func (MapArrayCollection) Slice ¶
func (c MapArrayCollection) Slice(keys ...int) Collection
Slice returns a slice of the collection starting at the given index.
func (MapArrayCollection) Splice ¶
func (c MapArrayCollection) Splice(index ...int) Collection
Splice removes and returns a slice of items starting at the specified index.
func (MapArrayCollection) Split ¶
func (c MapArrayCollection) Split(num int) Collection
Split breaks a collection into the given number of groups.
func (MapArrayCollection) Sum ¶
func (c MapArrayCollection) Sum(key ...string) decimal.Decimal
Sum returns the sum of all items in the collection.
func (MapArrayCollection) Take ¶
func (c MapArrayCollection) Take(num int) Collection
Take returns a new collection with the specified number of items.
func (MapArrayCollection) ToJson ¶
func (c MapArrayCollection) ToJson() string
ToJson converts the collection into a json string.
func (MapArrayCollection) ToMapArray ¶
func (c MapArrayCollection) ToMapArray() []map[string]interface{}
ToMapArray converts the collection into a plain golang slice which contains map.
func (MapArrayCollection) ToStruct ¶
func (c MapArrayCollection) ToStruct(dist interface{})
ToStruct turn the collection to the specified struct using mapstructure. https://github.com/mitchellh/mapstructure
func (MapArrayCollection) Where ¶
func (c MapArrayCollection) Where(key string, values ...interface{}) Collection
Where filters the collection by a given key / value pair.
func (MapArrayCollection) WhereIn ¶
func (c MapArrayCollection) WhereIn(key string, in []interface{}) Collection
WhereIn filters the collection by a given key / value contained within the given array.
func (MapArrayCollection) WhereNotIn ¶
func (c MapArrayCollection) WhereNotIn(key string, in []interface{}) Collection
WhereNotIn filters the collection by a given key / value not contained within the given array.
type MapCollection ¶
type MapCollection struct { BaseCollection // contains filtered or unexported fields }
func (MapCollection) Contains ¶
func (c MapCollection) Contains(value ...interface{}) bool
Contains determines whether the collection contains a given item.
func (MapCollection) Dd ¶
func (c MapCollection) Dd()
Dd dumps the collection's items and ends execution of the script.
func (MapCollection) DiffAssoc ¶
func (c MapCollection) DiffAssoc(m map[string]interface{}) Collection
DiffAssoc compares the collection against another collection or a plain PHP array based on its keys and values. This method will return the key / value pairs in the original collection that are not present in the given collection.
func (MapCollection) DiffKeys ¶
func (c MapCollection) DiffKeys(m map[string]interface{}) Collection
DiffKeys compares the collection against another collection or a plain PHP array based on its keys. This method will return the key / value pairs in the original collection that are not present in the given collection.
func (MapCollection) Each ¶
func (c MapCollection) Each(cb func(item, value interface{}) (interface{}, bool)) Collection
Each iterates over the items in the collection and passes each item to a callback.
func (MapCollection) Every ¶
func (c MapCollection) Every(cb CB) bool
Every may be used to verify that all elements of a collection pass a given truth test.
func (MapCollection) Except ¶
func (c MapCollection) Except(keys []string) Collection
Except returns all items in the collection except for those with the specified keys.
func (MapCollection) FlatMap ¶
func (c MapCollection) FlatMap(cb func(value interface{}) interface{}) Collection
FlatMap iterates through the collection and passes each value to the given callback.
func (MapCollection) Flip ¶
func (c MapCollection) Flip() Collection
Flip swaps the collection's keys with their corresponding values.
func (MapCollection) Forget ¶
func (c MapCollection) Forget(k string) Collection
Forget removes an item from the collection by its key.
func (MapCollection) Get ¶
func (c MapCollection) Get(k string, v ...interface{}) interface{}
Get returns the item at a given key. If the key does not exist, null is returned.
func (MapCollection) Has ¶
func (c MapCollection) Has(keys ...string) bool
Has determines if a given key exists in the collection.
func (MapCollection) IntersectByKeys ¶
func (c MapCollection) IntersectByKeys(m map[string]interface{}) Collection
IntersectByKeys removes any keys from the original collection that are not present in the given array or collection.
func (MapCollection) IsEmpty ¶
func (c MapCollection) IsEmpty() bool
IsEmpty returns true if the collection is empty; otherwise, false is returned.
func (MapCollection) IsNotEmpty ¶
func (c MapCollection) IsNotEmpty() bool
IsNotEmpty returns true if the collection is not empty; otherwise, false is returned.
func (MapCollection) Keys ¶
func (c MapCollection) Keys() Collection
Keys returns all of the collection's keys.
func (MapCollection) Merge ¶
func (c MapCollection) Merge(i interface{}) Collection
Merge merges the given array or collection with the original collection. If a string key in the given items matches a string key in the original collection, the given items's value will overwrite the value in the original collection.
func (MapCollection) Only ¶
func (c MapCollection) Only(keys []string) Collection
Only returns the items in the collection with the specified keys.
func (MapCollection) Prepend ¶
func (c MapCollection) Prepend(values ...interface{}) Collection
Prepend adds an item to the beginning of the collection.
func (MapCollection) Select ¶
func (c MapCollection) Select(keys ...string) Collection
Select select the keys of collection and delete others.
func (MapCollection) ToJson ¶
func (c MapCollection) ToJson() string
ToJson converts the collection into a json string.
func (MapCollection) ToMap ¶
func (c MapCollection) ToMap() map[string]interface{}
ToMap converts the collection into a plain golang map.
func (MapCollection) ToStruct ¶
func (c MapCollection) ToStruct(dist interface{})
ToStruct turn the collection to the specified struct using mapstructure. https://github.com/mitchellh/mapstructure
type MultiDimensionalArrayCollection ¶
type MultiDimensionalArrayCollection struct { BaseCollection // contains filtered or unexported fields }
func (MultiDimensionalArrayCollection) Collapse ¶
func (c MultiDimensionalArrayCollection) Collapse() Collection
Collapse collapses a collection of arrays into a single, flat collection.
func (MultiDimensionalArrayCollection) Concat ¶
func (c MultiDimensionalArrayCollection) Concat(value interface{}) Collection
Concat appends the given array or collection values onto the end of the collection.
func (MultiDimensionalArrayCollection) Dd ¶
func (c MultiDimensionalArrayCollection) Dd()
Dd dumps the collection's items and ends execution of the script.
func (MultiDimensionalArrayCollection) Dump ¶
func (c MultiDimensionalArrayCollection) Dump()
Dump dumps the collection's items.
func (MultiDimensionalArrayCollection) ToJson ¶
func (c MultiDimensionalArrayCollection) ToJson() string
ToJson converts the collection into a json string.
func (MultiDimensionalArrayCollection) ToMultiDimensionalArray ¶
func (c MultiDimensionalArrayCollection) ToMultiDimensionalArray() [][]interface{}
func (MultiDimensionalArrayCollection) Value ¶
func (c MultiDimensionalArrayCollection) Value() interface{}
type NumberArrayCollection ¶
type NumberArrayCollection struct { BaseCollection // contains filtered or unexported fields }
func (NumberArrayCollection) All ¶
func (c NumberArrayCollection) All() []interface{}
All returns the underlying array represented by the collection.
func (NumberArrayCollection) Avg ¶
func (c NumberArrayCollection) Avg(key ...string) decimal.Decimal
Avg returns the average value of a given key.
func (NumberArrayCollection) Chunk ¶
func (c NumberArrayCollection) Chunk(num int) MultiDimensionalArrayCollection
Chunk breaks the collection into multiple, smaller collections of a given size.
func (NumberArrayCollection) Concat ¶
func (c NumberArrayCollection) Concat(value interface{}) Collection
Concat appends the given array or collection values onto the end of the collection.
func (NumberArrayCollection) Contains ¶
func (c NumberArrayCollection) Contains(value ...interface{}) bool
Contains determines whether the collection contains a given item.
func (NumberArrayCollection) CountBy ¶
func (c NumberArrayCollection) CountBy(callback ...interface{}) map[interface{}]int
CountBy counts the occurrences of values in the collection. By default, the method counts the occurrences of every element.
func (NumberArrayCollection) CrossJoin ¶
func (c NumberArrayCollection) CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection
CrossJoin cross joins the collection's values among the given arrays or collections, returning a Cartesian product with all possible permutations.
func (NumberArrayCollection) Dd ¶
func (c NumberArrayCollection) Dd()
Dd dumps the collection's items and ends execution of the script.
func (NumberArrayCollection) Diff ¶
func (c NumberArrayCollection) Diff(m interface{}) Collection
Diff compares the collection against another collection or a plain PHP array based on its values. This method will return the values in the original collection that are not present in the given collection.
func (NumberArrayCollection) Dump ¶
func (c NumberArrayCollection) Dump()
Dump dumps the collection's items.
func (NumberArrayCollection) Each ¶
func (c NumberArrayCollection) Each(cb func(item, value interface{}) (interface{}, bool)) Collection
Each iterates over the items in the collection and passes each item to a callback.
func (NumberArrayCollection) Every ¶
func (c NumberArrayCollection) Every(cb CB) bool
Every may be used to verify that all elements of a collection pass a given truth test.
func (NumberArrayCollection) Filter ¶
func (c NumberArrayCollection) Filter(cb CB) Collection
Filter filters the collection using the given callback, keeping only those items that pass a given truth test.
func (NumberArrayCollection) First ¶
func (c NumberArrayCollection) First(cbs ...CB) interface{}
First returns the first element in the collection that passes a given truth test.
func (NumberArrayCollection) ForPage ¶
func (c NumberArrayCollection) ForPage(page, size int) Collection
ForPage returns a new collection containing the items that would be present on a given page number.
func (NumberArrayCollection) IsEmpty ¶
func (c NumberArrayCollection) IsEmpty() bool
IsEmpty returns true if the collection is empty; otherwise, false is returned.
func (NumberArrayCollection) IsNotEmpty ¶
func (c NumberArrayCollection) IsNotEmpty() bool
IsNotEmpty returns true if the collection is not empty; otherwise, false is returned.
func (NumberArrayCollection) Last ¶
func (c NumberArrayCollection) Last(cbs ...CB) interface{}
Last returns the last element in the collection that passes a given truth test.
func (NumberArrayCollection) Length ¶
func (c NumberArrayCollection) Length() int
Length return the length of the collection.
func (NumberArrayCollection) Max ¶
func (c NumberArrayCollection) Max(key ...string) decimal.Decimal
Max returns the maximum value of a given key.
func (NumberArrayCollection) Median ¶
func (c NumberArrayCollection) Median(key ...string) decimal.Decimal
Median returns the median value of a given key.
func (NumberArrayCollection) Merge ¶
func (c NumberArrayCollection) Merge(i interface{}) Collection
Merge merges the given array or collection with the original collection. If a string key in the given items matches a string key in the original collection, the given items's value will overwrite the value in the original collection.
func (NumberArrayCollection) Min ¶
func (c NumberArrayCollection) Min(key ...string) decimal.Decimal
Min returns the minimum value of a given key.
func (NumberArrayCollection) Mode ¶
func (c NumberArrayCollection) Mode(key ...string) []interface{}
Mode returns the mode value of a given key.
func (NumberArrayCollection) Pad ¶
func (c NumberArrayCollection) Pad(num int, value interface{}) Collection
Pad will fill the array with the given value until the array reaches the specified size.
func (NumberArrayCollection) Partition ¶
func (c NumberArrayCollection) Partition(cb PartCB) (Collection, Collection)
Partition separate elements that pass a given truth test from those that do not.
func (NumberArrayCollection) Pop ¶
func (c NumberArrayCollection) Pop() interface{}
Pop removes and returns the last item from the collection.
func (NumberArrayCollection) Prepend ¶
func (c NumberArrayCollection) Prepend(values ...interface{}) Collection
Prepend adds an item to the beginning of the collection.
func (NumberArrayCollection) Push ¶
func (c NumberArrayCollection) Push(v interface{}) Collection
Push appends an item to the end of the collection.
func (NumberArrayCollection) Random ¶
func (c NumberArrayCollection) Random(num ...int) Collection
Random returns a random item from the collection.
func (NumberArrayCollection) Reduce ¶
func (c NumberArrayCollection) Reduce(cb ReduceCB) interface{}
Reduce reduces the collection to a single value, passing the result of each iteration into the subsequent iteration.
func (NumberArrayCollection) Reject ¶
func (c NumberArrayCollection) Reject(cb CB) Collection
Reject filters the collection using the given callback.
func (NumberArrayCollection) Reverse ¶
func (c NumberArrayCollection) Reverse() Collection
Reverse reverses the order of the collection's items, preserving the original keys.
func (NumberArrayCollection) Search ¶
func (c NumberArrayCollection) Search(v interface{}) int
Search searches the collection for the given value and returns its key if found. If the item is not found, -1 is returned.
func (NumberArrayCollection) Shift ¶
func (c NumberArrayCollection) Shift() Collection
Shift removes and returns the first item from the collection.
func (NumberArrayCollection) Shuffle ¶
func (c NumberArrayCollection) Shuffle() Collection
Shuffle randomly shuffles the items in the collection.
func (NumberArrayCollection) Slice ¶
func (c NumberArrayCollection) Slice(keys ...int) Collection
Slice returns a slice of the collection starting at the given index.
func (NumberArrayCollection) Sort ¶
func (c NumberArrayCollection) Sort() Collection
Sort sorts the collection.
func (NumberArrayCollection) SortByDesc ¶
func (c NumberArrayCollection) SortByDesc() Collection
SortByDesc has the same signature as the sortBy method, but will sort the collection in the opposite order.
func (NumberArrayCollection) Splice ¶
func (c NumberArrayCollection) Splice(index ...int) Collection
Splice removes and returns a slice of items starting at the specified index.
func (NumberArrayCollection) Split ¶
func (c NumberArrayCollection) Split(num int) Collection
Split breaks a collection into the given number of groups.
func (NumberArrayCollection) Sum ¶
func (c NumberArrayCollection) Sum(key ...string) decimal.Decimal
Sum returns the sum of all items in the collection.
func (NumberArrayCollection) Take ¶
func (c NumberArrayCollection) Take(num int) Collection
Take returns a new collection with the specified number of items.
func (NumberArrayCollection) ToInt64Array ¶
func (c NumberArrayCollection) ToInt64Array() []int64
ToInt64Array converts the collection into a plain golang slice which contains int64.
func (NumberArrayCollection) ToIntArray ¶
func (c NumberArrayCollection) ToIntArray() []int
ToIntArray converts the collection into a plain golang slice which contains int.
func (NumberArrayCollection) ToJson ¶
func (c NumberArrayCollection) ToJson() string
ToJson converts the collection into a json string.
func (NumberArrayCollection) ToNumberArray ¶
func (c NumberArrayCollection) ToNumberArray() []decimal.Decimal
ToNumberArray converts the collection into a plain golang slice which contains decimal.Decimal.
func (NumberArrayCollection) Unique ¶
func (c NumberArrayCollection) Unique() Collection
Unique returns all of the unique items in the collection.
type StringArrayCollection ¶
type StringArrayCollection struct { BaseCollection // contains filtered or unexported fields }
func (StringArrayCollection) All ¶
func (c StringArrayCollection) All() []interface{}
All returns the underlying array represented by the collection.
func (StringArrayCollection) Chunk ¶
func (c StringArrayCollection) Chunk(num int) MultiDimensionalArrayCollection
Chunk breaks the collection into multiple, smaller collections of a given size.
func (StringArrayCollection) Combine ¶
func (c StringArrayCollection) Combine(value []interface{}) Collection
Combine combines the values of the collection, as keys, with the values of another array or collection.
func (StringArrayCollection) Concat ¶
func (c StringArrayCollection) Concat(value interface{}) Collection
Concat appends the given array or collection values onto the end of the collection.
func (StringArrayCollection) Contains ¶
func (c StringArrayCollection) Contains(value ...interface{}) bool
Contains determines whether the collection contains a given item.
func (StringArrayCollection) CountBy ¶
func (c StringArrayCollection) CountBy(callback ...interface{}) map[interface{}]int
CountBy counts the occurrences of values in the collection. By default, the method counts the occurrences of every element.
func (StringArrayCollection) CrossJoin ¶
func (c StringArrayCollection) CrossJoin(array ...[]interface{}) MultiDimensionalArrayCollection
CrossJoin cross joins the collection's values among the given arrays or collections, returning a Cartesian product with all possible permutations.
func (StringArrayCollection) Dd ¶
func (c StringArrayCollection) Dd()
Dd dumps the collection's items and ends execution of the script.
func (StringArrayCollection) Diff ¶
func (c StringArrayCollection) Diff(m interface{}) Collection
Diff compares the collection against another collection or a plain PHP array based on its values. This method will return the values in the original collection that are not present in the given collection.
func (StringArrayCollection) Dump ¶
func (c StringArrayCollection) Dump()
Dump dumps the collection's items.
func (StringArrayCollection) Each ¶
func (c StringArrayCollection) Each(cb func(item, value interface{}) (interface{}, bool)) Collection
Each iterates over the items in the collection and passes each item to a callback.
func (StringArrayCollection) Every ¶
func (c StringArrayCollection) Every(cb CB) bool
Every may be used to verify that all elements of a collection pass a given truth test.
func (StringArrayCollection) Filter ¶
func (c StringArrayCollection) Filter(cb CB) Collection
Filter filters the collection using the given callback, keeping only those items that pass a given truth test.
func (StringArrayCollection) First ¶
func (c StringArrayCollection) First(cbs ...CB) interface{}
First returns the first element in the collection that passes a given truth test.
func (StringArrayCollection) ForPage ¶
func (c StringArrayCollection) ForPage(page, size int) Collection
ForPage returns a new collection containing the items that would be present on a given page number.
func (StringArrayCollection) Intersect ¶
func (c StringArrayCollection) Intersect(keys []string) Collection
Intersect removes any values from the original collection that are not present in the given array or collection.
func (StringArrayCollection) IsEmpty ¶
func (c StringArrayCollection) IsEmpty() bool
IsEmpty returns true if the collection is empty; otherwise, false is returned.
func (StringArrayCollection) IsNotEmpty ¶
func (c StringArrayCollection) IsNotEmpty() bool
IsNotEmpty returns true if the collection is not empty; otherwise, false is returned.
func (StringArrayCollection) Join ¶
func (c StringArrayCollection) Join(delimiter string) string
Join joins the collection's values with a string.
func (StringArrayCollection) Last ¶
func (c StringArrayCollection) Last(cbs ...CB) interface{}
Last returns the last element in the collection that passes a given truth test.
func (StringArrayCollection) Length ¶
func (c StringArrayCollection) Length() int
Length return the length of the collection.
func (StringArrayCollection) Merge ¶
func (c StringArrayCollection) Merge(i interface{}) Collection
Merge merges the given array or collection with the original collection. If a string key in the given items matches a string key in the original collection, the given items's value will overwrite the value in the original collection.
func (StringArrayCollection) Mode ¶
func (c StringArrayCollection) Mode(key ...string) []interface{}
Mode returns the mode value of a given key.
func (StringArrayCollection) Pad ¶
func (c StringArrayCollection) Pad(num int, value interface{}) Collection
Pad will fill the array with the given value until the array reaches the specified size.
func (StringArrayCollection) Partition ¶
func (c StringArrayCollection) Partition(cb PartCB) (Collection, Collection)
Partition separate elements that pass a given truth test from those that do not.
func (StringArrayCollection) Pop ¶
func (c StringArrayCollection) Pop() interface{}
Pop removes and returns the last item from the collection.
func (StringArrayCollection) Prepend ¶
func (c StringArrayCollection) Prepend(values ...interface{}) Collection
Prepend adds an item to the beginning of the collection.
func (StringArrayCollection) Push ¶
func (c StringArrayCollection) Push(v interface{}) Collection
Push appends an item to the end of the collection.
func (StringArrayCollection) Random ¶
func (c StringArrayCollection) Random(num ...int) Collection
Random returns a random item from the collection.
func (StringArrayCollection) Reduce ¶
func (c StringArrayCollection) Reduce(cb ReduceCB) interface{}
Reduce reduces the collection to a single value, passing the result of each iteration into the subsequent iteration.
func (StringArrayCollection) Reject ¶
func (c StringArrayCollection) Reject(cb CB) Collection
Reject filters the collection using the given callback.
func (StringArrayCollection) Reverse ¶
func (c StringArrayCollection) Reverse() Collection
Reverse reverses the order of the collection's items, preserving the original keys.
func (StringArrayCollection) Search ¶
func (c StringArrayCollection) Search(v interface{}) int
Search searches the collection for the given value and returns its key if found. If the item is not found, -1 is returned.
func (StringArrayCollection) Shift ¶
func (c StringArrayCollection) Shift() Collection
Shift removes and returns the first item from the collection.
func (StringArrayCollection) Shuffle ¶
func (c StringArrayCollection) Shuffle() Collection
Shuffle randomly shuffles the items in the collection.
func (StringArrayCollection) Slice ¶
func (c StringArrayCollection) Slice(keys ...int) Collection
Slice returns a slice of the collection starting at the given index.
func (StringArrayCollection) Splice ¶
func (c StringArrayCollection) Splice(index ...int) Collection
Splice removes and returns a slice of items starting at the specified index.
func (StringArrayCollection) Split ¶
func (c StringArrayCollection) Split(num int) Collection
Split breaks a collection into the given number of groups.
func (StringArrayCollection) Take ¶
func (c StringArrayCollection) Take(num int) Collection
Take returns a new collection with the specified number of items.
func (StringArrayCollection) ToJson ¶
func (c StringArrayCollection) ToJson() string
ToJson converts the collection into a json string.
func (StringArrayCollection) ToStringArray ¶
func (c StringArrayCollection) ToStringArray() []string
ToStringArray converts the collection into a plain golang slice which contains string.
func (StringArrayCollection) Unique ¶
func (c StringArrayCollection) Unique() Collection
Unique returns all of the unique items in the collection.