Documentation ¶
Overview ¶
Package containers provides core interfaces and functions for data structures.
Container is the base interface for all data structures to implement.
Iterators provide stateful iterators.
Enumerable provides Ruby inspired (each, select, map, find, any?, etc.) container functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSortedValues ¶
func GetSortedValues(container Container, comparator utils.Comparator) []interface{}
GetSortedValues returns sorted container's elements with respect to the passed comparator. Does not effect the ordering of elements within the container.
Types ¶
type EnumerableWithIndex ¶
type EnumerableWithIndex interface { // Each calls the given function once for each element, passing that element's index and value. Each(func(index int, value interface{})) // Any passes each element of the container to the given function and // returns true if the function ever returns true for any element. Any(func(index int, value interface{}) bool) bool // All passes each element of the container to the given function and // returns true if the function returns true for all elements. All(func(index int, value interface{}) bool) bool // Find passes each element of the container to the given function and returns // the first (index,value) for which the function is true or -1,nil otherwise // if no element matches the criteria. Find(func(index int, value interface{}) bool) (int, interface{}) }
EnumerableWithIndex provides functions for ordered containers whose values can be fetched by an index.
type EnumerableWithKey ¶
type EnumerableWithKey interface { // Each calls the given function once for each element, passing that element's key and value. Each(func(key interface{}, value interface{})) // Any passes each element of the container to the given function and // returns true if the function ever returns true for any element. Any(func(key interface{}, value interface{}) bool) bool // All passes each element of the container to the given function and // returns true if the function returns true for all elements. All(func(key interface{}, value interface{}) bool) bool // Find passes each element of the container to the given function and returns // the first (key,value) for which the function is true or nil,nil otherwise if no element // matches the criteria. Find(func(key interface{}, value interface{}) bool) (interface{}, interface{}) }
EnumerableWithKey provides functions for ordered containers whose values whose elements are key/value pairs.
type IteratorWithIndex ¶
type IteratorWithIndex interface { // Next moves the iterator to the next element and returns true if there was a next element in the container. // If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). // Modifies the state of the iterator. Next() bool // Value returns the current element's value. // Does not modify the state of the iterator. Value() interface{} // Index returns the current element's index. // Does not modify the state of the iterator. Index() int }
IteratorWithIndex is stateful iterator for ordered containers whose values can be fetched by an index.
type IteratorWithKey ¶
type IteratorWithKey interface { // Next moves the iterator to the next element and returns true if there was a next element in the container. // If Next() returns true, then next element's key and value can be retrieved by Key() and Value(). // Modifies the state of the iterator. Next() bool // Value returns the current element's value. // Does not modify the state of the iterator. Value() interface{} // Key returns the current element's key. // Does not modify the state of the iterator. Key() interface{} }
IteratorWithKey is a stateful iterator for ordered containers whose elements are key value pairs.
type ReverseIteratorWithIndex ¶ added in v1.1.0
type ReverseIteratorWithIndex interface { // Prev moves the iterator to the previous element and returns true if there was a previous element in the container. // If Prev() returns true, then previous element's index and value can be retrieved by Index() and Value(). // Modifies the state of the iterator. Prev() bool IteratorWithIndex }
ReverseIteratorWithIndex is stateful iterator for ordered containers whose values can be fetched by an index.
Essentially it is the same as IteratorWithIndex, but provides additional Prev() function to enable traversal in reverse.
type ReverseIteratorWithKey ¶ added in v1.1.0
type ReverseIteratorWithKey interface { // Prev moves the iterator to the previous element and returns true if there was a previous element in the container. // If Prev() returns true, then previous element's index and value can be retrieved by Key() and Value(). // Modifies the state of the iterator. Prev() bool IteratorWithKey }
ReverseIteratorWithKey is a stateful iterator for ordered containers whose elements are key value pairs.
Essentially it is the same as IteratorWithKey, but provides additional Prev() function to enable traversal in reverse.