Documentation
¶
Index ¶
- type ICollection
- func (c *ICollection) Clear() bool
- func (c *ICollection) Clone() *ICollection
- func (c *ICollection) Delete(key string) bool
- func (c *ICollection) Difference(against *ICollection) *ICollection
- func (c *ICollection) Each(fn IEachFunc) *ICollection
- func (c *ICollection) Every(fn IEveryFunc) bool
- func (c *ICollection) Execute(fn IExecuteFunc) *ICollection
- func (c *ICollection) Exists(key string) bool
- func (c *ICollection) Fetch(key string) any
- func (c *ICollection) Filter(fn IFilterFunc) *ICollection
- func (c *ICollection) Find(fn IFindFunc) any
- func (c *ICollection) First() any
- func (c *ICollection) Get(key string) any
- func (c *ICollection) GetIndex(key string) int
- func (c *ICollection) Has(key string) bool
- func (c *ICollection) Implement(collections ...*ICollection) *ICollection
- func (c *ICollection) Intersect(secondary *ICollection) *ICollection
- func (c *ICollection) Iterator() map[string]any
- func (c *ICollection) Last() any
- func (c *ICollection) Map(fn IMapFunc) []any
- func (c *ICollection) Merge(collections ...*ICollection) *ICollection
- func (c *ICollection) Reduce(fn IReduceFunc, initialAccumulator any) any
- func (c *ICollection) Set(key string, value any) *ICollection
- func (c *ICollection) Size() int
- func (c *ICollection) Some(fn ISomeFunc) bool
- func (c *ICollection) Sort(fn ISortFunc) *ICollection
- func (c *ICollection) Sweep(fn ISweepFunc) int
- func (c *ICollection) ToArray() []ICollectionAll
- func (c *ICollection) ToKeyArray() []string
- type ICollectionAll
- type IEachFunc
- type IEveryFunc
- type IExecuteFunc
- type IFilterFunc
- type IFindFunc
- type IMapFunc
- type IReduceFunc
- type ISomeFunc
- type ISortFunc
- type ISweepFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ICollection ¶
type ICollection struct {
// contains filtered or unexported fields
}
func New ¶
func New() *ICollection
New creates a new Collection instance and returns it.
Returns a new Collection instance.
func (*ICollection) Clear ¶
func (c *ICollection) Clear() bool
Clear removes all elements from the Collection.
Returns a boolean indicating whether the Collection has been cleared or not.
func (*ICollection) Clone ¶
func (c *ICollection) Clone() *ICollection
Clone creates a new Collection instance and populates it with the elements of the current Collection.
Returns a new Collection instance.
func (*ICollection) Delete ¶
func (c *ICollection) Delete(key string) bool
Delete removes any value associated to the key from the Collection.
The Delete function takes 1 parameter:
- key: a string representing the key to search for, which is associated to a string type.
The first parameter represents the key to search for, which is associated to a string type.
Returns a boolean indicating whether the key-value pair has been deleted or not.
func (*ICollection) Difference ¶
func (c *ICollection) Difference(against *ICollection) *ICollection
Difference returns a new Collection containing the elements of the current Collection that are not in the given Collection.
The Difference function takes 1 parameter:
- against: a Collection to compare the current Collection against.
The first parameter (against) represents a pointer to a Collection.
Returns a new Collection containing the elements of the current Collection that are not in the given Collection.
func (*ICollection) Each ¶
func (c *ICollection) Each(fn IEachFunc) *ICollection
Each applies the given function to each key-value pair in the Collection.
The Each function takes 1 parameter:
- fn: a function to be applied to each key-value pair in the Collection.
The first parameter (fn) represents a function to be applied to each key-value pair in the Collection.
The fn function takes three parameters:
- key: a string representing the key of the key-value pair.
- value: the value associated with the key.
- collection: a pointer to the Collection being filtered.
Returns the current Collection.
func (*ICollection) Every ¶
func (c *ICollection) Every(fn IEveryFunc) bool
Every applies the given function to each key-value pair in the Collection and returns a boolean indicating whether all key-value pairs have been processed or not.
The Every function takes 1 parameter:
- fn: a function to be applied to each key-value pair in the Collection.
The first parameter (fn) represents a function to be applied to each key-value pair in the Collection.
The fn function takes three parameters:
- key: a string representing the key of the key-value pair.
- value: the value associated with the key.
- collection: a pointer to the Collection being filtered.
Returns a boolean indicating whether all key-value pairs have been processed or not.
func (*ICollection) Execute ¶
func (c *ICollection) Execute(fn IExecuteFunc) *ICollection
Execute applies the given function to the Collection and returns the Collection.
The Execute function takes 1 parameter:
- fn: a function to be applied to the Collection.
The first parameter (fn) represents a function to be applied to the Collection.
The fn function takes two parameters:
- collection: a pointer to the Collection being filtered.
- size: an integer representing the size of the Collection.
Returns the current Collection.
func (*ICollection) Exists ¶
func (c *ICollection) Exists(key string) bool
Exists returns a Boolean asserting whether a value has been associated to the key in the Collection or not.
The Exists function takes 1 parameter:
- key: a string representing the key to search for, which is associated to a string type.
The first parameter represents the key to search for, which is associated to a string type.
Returns a Boolean whether or not the key exists in the Collection.
func (*ICollection) Fetch ¶
func (c *ICollection) Fetch(key string) any
Fetch returns the value associated to the key, or nil if there is none.
The Fetch function takes 1 parameter:
- key: a string representing the key to search for, which is associated to a string type.
The first parameter represents the key to search for, which is associated to a string type.
Returns the value associated to the key, or nil if there is none.
func (*ICollection) Filter ¶
func (c *ICollection) Filter(fn IFilterFunc) *ICollection
Filter applies the given function to each key-value pair in the Collection and returns a new Collection containing only the key-value pairs for which the function returns true.
The Filter function takes 1 parameter:
- fn: a function to be applied to each key-value pair in the Collection.
The first parameter (fn) represents a function to be applied to each key-value pair in the Collection. The function returns a boolean indicating whether the key-value pair should be included in the resulting ICollection.
The fn function takes three parameters:
- key: a string representing the key of the key-value pair.
- value: the value associated with the key.
- collection: a pointer to the Collection being filtered.
The function returns a pointer to the new ICollection containing the filtered key-value pairs.
func (*ICollection) Find ¶
func (c *ICollection) Find(fn IFindFunc) any
Find searches for a value in the Collection based on the provided function.
The Find function takes 1 parameter:
- fn: a function which is used to determine whether a value should be considered a match or not.
The first parameter represents a function to be applied to each key-value pair in the Collection. The function returns a boolean indicating whether the key-value pair should be considered a match.
The fn function takes three parameters:
- key: a string representing the key of the key-value pair.
- value: the value associated with the key.
- collection: a pointer to the Collection being searched.
Returns the value associated with the key that matches the provided function, or nil if no match is found.
func (*ICollection) First ¶
func (c *ICollection) First() any
First fetches the first item in the Collection.
Returns the first item in the Collection.
func (*ICollection) Get ¶
func (c *ICollection) Get(key string) any
Get returns the value associated to the key, or nil if there is none.
The Get function takes 1 parameter:
- key: a string representing the key to search for, which is associated to a string type.
The first parameter represents the key to search for, which is associated to a string type.
Returns the value associated to the key, or nil if there is none.
func (*ICollection) GetIndex ¶
func (c *ICollection) GetIndex(key string) int
GetIndex returns the index of the given key in the collection.
The GetIndex function takes 1 parameter:
- key: a string representing the key to search for, which is associated to a string type.
The first parameter represents the key to search for, which is associated to a string type.
Returns the index of the given key in the collection.
func (*ICollection) Has ¶
func (c *ICollection) Has(key string) bool
Has returns a Boolean asserting whether a value has been associated to the key in the Collection or not.
The Has function takes 1 parameter:
- key: a string representing the key to search for, which is associated to a string type.
The first parameter represents the key to search for, which is associated to a string type.
Returns a Boolean whether or not the key exists in the Collection.
func (*ICollection) Implement ¶
func (c *ICollection) Implement(collections ...*ICollection) *ICollection
Implement implements multiple collections into one.
The Implement function takes 1 parameter:
- collections: a slice of Collections.
The first parameter represents a slice of pointers to ICollection.
Returns a pointer to the new ICollection.
func (*ICollection) Intersect ¶
func (c *ICollection) Intersect(secondary *ICollection) *ICollection
Intersect returns a new Collection containing the intersection of the current Collection and the given Collection.
The Intersect function takes 1 parameter:
- secondary: a Collection.
The first parameter (secondary) represents a pointer to a Collection.
Returns a new Collection containing the intersection of the current Collection and the given Collection.
func (*ICollection) Iterator ¶
func (c *ICollection) Iterator() map[string]any
Iterator returns a map containing the elements of the ICollection.
Returns a regular map which can be used to iterate over.
func (*ICollection) Last ¶
func (c *ICollection) Last() any
Last fetches the last item in the Collection.
Returns the last item in the Collection.
func (*ICollection) Map ¶
func (c *ICollection) Map(fn IMapFunc) []any
Map applies a function to each key-value pair in the Collection and returns an array of the results.
The Map function takes 1 parameter:
- fn: a function that maps the key-value pair.
The first parameter represents a function that maps the key-value pair.
The fn function takes three parameters:
- key: a string representing the key of the key-value pair.
- value: the value associated with the key.
- collection: a pointer to the Collection being mapped.
Returns an array of the results.
func (*ICollection) Merge ¶
func (c *ICollection) Merge(collections ...*ICollection) *ICollection
Merge merges multiple collections into one.
The Merge function takes 1 parameter:
- collections: a slice of Collections.
The first parameter represents a slice of pointers to ICollection.
Returns a pointer to the new ICollection.
func (*ICollection) Reduce ¶
func (c *ICollection) Reduce(fn IReduceFunc, initialAccumulator any) any
Reduce applies a function against an accumulator and each value of the Collection (from left-to-right) to reduce it to a single value.
The Reduce function takes 2 parameters:
- fn: a function which is used to reduce the Collection.
- initialAccumulator: an initial accumulator value.
The first parameter represents a function to be applied to each key-value pair in the Collection. The function returns an accumulator value.
The second parameter represents the initial accumulator value.
The fn function takes three parameters:
- accumulator: an accumulator value.
- value: the value associated with the key.
- key: a string representing the key of the key-value pair.
- collection: a pointer to the Collection being reduced.
Returns the accumulator value.
func (*ICollection) Set ¶
func (c *ICollection) Set(key string, value any) *ICollection
Set sets the key-value pair in the Collection.
The Set function takes 2 parameters:
- key: a string representing the key of the key-value pair.
- value: the value associated with the key.
The first parameter represents a string representing the key of the key-value pair.
The second parameter represents the value associated with the key.
Returns a pointer to the Collection.
func (*ICollection) Size ¶
func (c *ICollection) Size() int
Size returns the amount of keys/values in the Collection.
Returns the amount of keys in the Collection.
func (*ICollection) Some ¶
func (c *ICollection) Some(fn ISomeFunc) bool
Some applies a function checks if at least one element in the Collection satisfies the given function.
The Some function takes 1 parameter:
- fn: a function that checks if an element satisfies the provided filter.
The first parameter represents a function that checks if an element satisfies the provided filter.
The fn function takes three parameters:
- key: a string representing the key of the key-value pair.
- value: the value associated with the key.
- collection: a pointer to the Collection being filtered.
Returns a Boolean asserting whether at least one element in the Collection satisfies the given function.
func (*ICollection) Sort ¶
func (c *ICollection) Sort(fn ISortFunc) *ICollection
Sort sorts the elements in the Collection.
The Sort function takes 1 parameter:
- fn: a function that compares two elements.
The first parameter represents a function that compares two elements.
The fn function takes two parameters:
- first: the first element to compare.
- second: the second element to compare.
Returns a pointer to the Collection.
func (*ICollection) Sweep ¶
func (c *ICollection) Sweep(fn ISweepFunc) int
Sweep removes all elements in the Collection that match the given function.
The Sweep function takes 1 parameter:
- fn: a function that removes an element based on the provided filter.
The first parameter represents a function that removes an element based on the provided filter.
The fn function takes three parameters:
- key: a string representing the key of the key-value pair.
- value: the value associated with the key.
- collection: a pointer to the Collection being filtered.
Returns the amount of elements removed from the Collection.
func (*ICollection) ToArray ¶
func (c *ICollection) ToArray() []ICollectionAll
ToArray returns all the key-value pairs in the Collection as an array of the struct ICollectionAll.
Returns an array indicating all the key-value pairs in the Collection.
func (*ICollection) ToKeyArray ¶
func (c *ICollection) ToKeyArray() []string
ToKeyArray returns an array of strings containing all the keys in the Collection.
Returns an array of strings containing all the keys in the Collection.
type ICollectionAll ¶
type IEachFunc ¶
type IEachFunc func(value any, key string, collection *ICollection)
type IEveryFunc ¶
type IEveryFunc func(value any, key string, collection *ICollection) bool
type IExecuteFunc ¶
type IExecuteFunc func(collection *ICollection, size int)
type IFilterFunc ¶
type IFilterFunc func(value any, key string, collection *ICollection) bool
type IReduceFunc ¶
type IReduceFunc func(accumulator any, value any, key string, collection *ICollection) any
type ISweepFunc ¶
type ISweepFunc func(value any, key string, collection *ICollection) bool