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.
Serialization provides serializers (marshalers) and deserializers (unmarshalers).
Index ¶
- Constants
- type BackwardIterator
- type BidirectionalIterator
- type BoundsSentinel
- type CollectionIterator
- type CompIndexIterator
- type CompIndexMapIterator
- type ComparableIterator
- type Container
- type ForwardIterator
- type IndexedIterator
- type Iterator
- type IteratorWithIndex
- type IteratorWithKey
- type JSONDeserializer
- type JSONSerializer
- type MappingIterator
- type OrderedIterator
- type RandomAccessIterator
- type RandomAccessMappingIterator
- type RandomAccessReadableIterator
- type RandomAccessReadableMappingIterator
- type RandomAccessWriteableIterator
- type RandomAccessWriteableMappingIterator
- type ReadCompForIndexIterator
- type ReadCompForIndexMapIterator
- type ReadCompForIterator
- type ReadCompIterator
- type ReadForIterator
- type ReadWriteCompForRandCollIterator
- type ReadWriteOrdCompBidRandCollIterator
- type ReadWriteOrdCompBidRandCollMapIterator
- type ReadWriteOrdCompForRandCollIterator
- type ReadableIterator
- type ReverseIteratorWithIndex
- type ReverseIteratorWithKey
- type SizedIterator
- type WritableIterator
Constants ¶
const (
CanOnlyCompareEqualIteratorTypes = "Can only compare iterators of equal concrete type"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackwardIterator ¶
type BackwardIterator interface {
// ********************* Inherited methods ********************//
Iterator
// Next moves the iterator backward by one position.
Previous() bool
// NextN moves the iterator backward by n positions.
PreviousN(n int) bool
}
BackwardIterator defines an Iterator, which can be moved backward according to the indexes ordering.
type BidirectionalIterator ¶
type BidirectionalIterator interface {
// ********************* Inherited methods ********************//
ForwardIterator
BackwardIterator
// Next moves the iterator forward/backward by n positions.
MoveBy(n int) bool
}
BidirectionalIterator defines a ForwardIterator and BackwardIterator, which can be moved forward and backward according to the underlying data structure's ordering.
type BoundsSentinel ¶ added in v0.6.0
type BoundsSentinel int
const ( SentinelBegin BoundsSentinel = iota SentinelEnd SentinelFirst SentinelLast SentinelInRange )
type CollectionIterator ¶
type CollectionIterator interface {
// ********************* Inherited methods ********************//
SizedIterator
IndexedIterator
}
CollectionIterator defines a SizedIterator, which can be said to reference a collection of elements.
type CompIndexIterator ¶ added in v0.6.0
type CompIndexIterator interface {
IndexedIterator
ComparableIterator
}
type CompIndexMapIterator ¶ added in v0.17.0
type CompIndexMapIterator interface {
IndexedIterator
ComparableIterator
}
type ComparableIterator ¶
type ComparableIterator interface {
// ********************* Inherited methods ********************//
Iterator
// IsEqualTo checks if the iterator's position is said to be equal to other's position.
IsEqual(other ComparableIterator) bool
}
ComparableIterator defines an Iterator, which can be said to be in a position equal to other's position.
type Container ¶
type Container[TValue any] interface { IsEmpty() bool Size() int Clear() GetValues() []TValue ToString() string }
Container defines the minimum functionality required for all other containers.
type ForwardIterator ¶
type ForwardIterator interface {
// ********************* Inherited methods ********************//
Iterator
// Next moves the iterator forward by one position.
Next() bool
// NextN moves the iterator forward by n positions.
NextN(i int) bool
}
ForwardIterator defines an ordered Iterator, which can be moved forward according to the indexes ordering.
type IndexedIterator ¶ added in v0.6.0
type IndexedIterator interface {
// ********************* Inherited methods ********************//
SizedIterator
// Index returns the index of the iterator's position in the collection.
Index() (int, bool)
}
IndexedIterator defines an Iterator, which defines an an iterator with an index. This iterator can be combined with a ReadableIterator to hold key-value or index-value pairs.
type Iterator ¶
type Iterator interface {
// IsBegin checks if the iterator is pointing to one element before it's first element, unless Next() is called, the iterator is in an invalid state.
IsBegin() bool
// IsEnd checks if the iterator is pointing to one element past it's last element, unless Previous() is called, the iterator is in an invalid state.
IsEnd() bool
// IsFirst checks if the iterator is pointing to it's first element, when Next() is called, the iterator is in an invalid state.
IsFirst() bool
// IsBegin checks if the iterator is pointing to it's last element, when Previous() is called, the iterator is in an invalid state.
IsLast() bool
// IsValid checks if the iterator is in a valid position and not e.g. out of bounds.
IsValid() bool
}
Iterator defines the minimum functionality required for all other iterators.
type IteratorWithIndex ¶ added in v0.6.0
type IteratorWithIndex[TKey any, TValue any] 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(). // If Next() was called for the first time, then it will point the iterator to the first element if it exists. // Modifies the state of the iterator. Next() bool // Value returns the current element's value. // Does not modify the state of the iterator. Value() TValue // Index returns the current element's index. // Does not modify the state of the iterator. Index() int // Begin resets the iterator to its initial state (one-before-first) // Call Next() to fetch the first element if any. Begin() // First moves the iterator to the first element and returns true if there was a first element in the container. // If First() returns true, then first element's index and value can be retrieved by Index() and Value(). // Modifies the state of the iterator. First() bool // NextTo moves the iterator to the next element from current position that satisfies the condition given by the // passed function, and returns true if there was a next element in the container. // If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). // Modifies the state of the iterator. NextTo(func(index int, value TValue) bool) bool }
IteratorWithIndex is stateful iterator for ordered containers whose values can be fetched by an index.
type IteratorWithKey ¶ added in v0.6.0
type IteratorWithKey[TKey any, TValue any] 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(). // If Next() was called for the first time, then it will point the iterator to the first element if it exists. // Modifies the state of the iterator. Next() bool // Value returns the current element's value. // Does not modify the state of the iterator. Value() TValue // Key returns the current element's key. // Does not modify the state of the iterator. Key() TKey // Begin resets the iterator to its initial state (one-before-first) // Call Next() to fetch the first element if any. Begin() // First moves the iterator to the first element and returns true if there was a first element in the container. // If First() returns true, then first element's key and value can be retrieved by Key() and Value(). // Modifies the state of the iterator. First() bool // NextTo moves the iterator to the next element from current position that satisfies the condition given by the // passed function, and returns true if there was a next element in the container. // If NextTo() returns true, then next element's key and value can be retrieved by Key() and Value(). // Modifies the state of the iterator. NextTo(func(key TKey, value TValue) bool) bool }
IteratorWithKey is a stateful iterator for ordered containers whose elements are key value pairs.
type JSONDeserializer ¶
type JSONDeserializer interface {
// FromJSON populates containers's elements from the input JSON representation.
FromJSON([]byte) error
// UnmarshalJSON @implements json.Unmarshaler
UnmarshalJSON([]byte) error
}
JSONDeserializer provides JSON deserialization.
type JSONSerializer ¶
type JSONSerializer interface {
// ToJSON outputs the JSON representation of containers's elements.
ToJSON() ([]byte, error)
// MarshalJSON @implements json.Marshaler
MarshalJSON() ([]byte, error)
}
JSONSerializer provides JSON serialization.
type MappingIterator ¶ added in v0.17.0
type MappingIterator[TKey any] interface { // ********************* Inherited methods ********************// SizedIterator // GetKey returns the key of the iterator's position in the collection. GetKey() (TKey, bool) }
MappingIterator defines an Iterator, which defines an an iterator holding a key and a value. This iterator can be combined with a ReadableIterator to hold key-value or index-value pairs.
type OrderedIterator ¶
type OrderedIterator interface {
// ********************* Inherited methods ********************//
Iterator
// IsBefore checks if the iterator's position is said to come before other's position.
IsBefore(other OrderedIterator) bool
// IsBefore checks if the iterator's position is said to come after other's position.
IsAfter(other OrderedIterator) bool
// DistanceTo returns the signed distance of the iterator's position to other's position.
DistanceTo(other OrderedIterator) int
}
OrderedIterator defines an Iterator, which can be said to be in a position before or after others's position.
type RandomAccessIterator ¶
type RandomAccessIterator interface {
// ********************* Inherited methods ********************//
CollectionIterator
// MoveTo moves the iterator to the given index, if it is reachable.
MoveTo(i int) bool
}
RandomAccessIterator defines a CollectionIterator, which can be moved to every position in the iterable direction. A RandomAccessIterator does not imply bidirectional iteration.
type RandomAccessMappingIterator ¶ added in v0.17.0
type RandomAccessMappingIterator[TKey any] interface { // ********************* Inherited methods ********************// CollectionIterator MappingIterator[TKey] // MoveTo moves the iterator to the given index, if it is reachable. MoveToKey(i TKey) bool }
RandomAccessMappingIterator defines a CollectionIterator, which can be moved to every position in the iterable direction. A RandomAccessMappingIterator does not imply bidirectional iteration.
type RandomAccessReadableIterator ¶
type RandomAccessReadableIterator[TIndex any, TValue any] interface { // ********************* Inherited methods ********************// RandomAccessIterator ReadableIterator[TValue] // GetAt returns the value at the given index of the iterator. GetAt(i TIndex) (value TValue, found bool) }
RandomAccessReadableIterator defines a RandomAccessIterator and ReadableIterator, which can read from every index in the iterator.
type RandomAccessReadableMappingIterator ¶ added in v0.17.0
type RandomAccessReadableMappingIterator[TKey any, TValue any] interface { // ********************* Inherited methods ********************// RandomAccessMappingIterator[TKey] ReadableIterator[TValue] // GetAt returns the value at the given index of the iterator. GetAtKey(i TKey) (value TValue, found bool) }
RandomAccessReadableMappingIterator defines a RandomAccessMappingIterator and ReadableIterator, which can read from every key in the iterator.
type RandomAccessWriteableIterator ¶
type RandomAccessWriteableIterator[TIndex any, TValue any] interface { // ********************* Inherited methods ********************// RandomAccessIterator WritableIterator[TValue] // GetAt sets the value at the given index of the iterator. SetAt(i TIndex, value TValue) bool }
RandomAccessWriteableIterator defines a RandomAccessIterator and WritableIterator, which can write from every index in the iterator.
type RandomAccessWriteableMappingIterator ¶ added in v0.17.0
type RandomAccessWriteableMappingIterator[TKey any, TValue any] interface { // ********************* Inherited methods ********************// RandomAccessMappingIterator[TKey] WritableIterator[TValue] // GetAt sets the value at the given index of the iterator. SetAtKey(i TKey, value TValue) bool }
RandomAccessWriteableMappingIterator defines a RandomAccessMappingIterator and WritableIterator, which can write to every key in the iterator.
type ReadCompForIndexIterator ¶ added in v0.6.0
type ReadCompForIndexIterator[TValue any] interface { ReadableIterator[TValue] IndexedIterator ComparableIterator ForwardIterator }
type ReadCompForIndexMapIterator ¶ added in v0.17.0
type ReadCompForIndexMapIterator[TIndex any, TValue any] interface { ReadableIterator[TValue] IndexedIterator MappingIterator[TIndex] ComparableIterator ForwardIterator }
type ReadCompForIterator ¶ added in v0.6.0
type ReadCompForIterator[TValue any] interface { ReadableIterator[TValue] ComparableIterator ForwardIterator }
type ReadCompIterator ¶ added in v0.6.0
type ReadCompIterator[TValue any] interface { ReadableIterator[TValue] ComparableIterator }
type ReadForIterator ¶ added in v0.6.0
type ReadForIterator[TValue any] interface { ReadableIterator[TValue] ForwardIterator }
type ReadWriteCompForRandCollIterator ¶ added in v0.4.0
type ReadWriteCompForRandCollIterator[TIndex any, TValue any] interface { ComparableIterator CollectionIterator ForwardIterator RandomAccessReadableIterator[TIndex, TValue] RandomAccessWriteableIterator[TIndex, TValue] }
type ReadWriteOrdCompBidRandCollIterator ¶ added in v0.4.0
type ReadWriteOrdCompBidRandCollIterator[TIndex any, TValue any] interface { ComparableIterator OrderedIterator BidirectionalIterator RandomAccessReadableIterator[TIndex, TValue] RandomAccessWriteableIterator[TIndex, TValue] }
type ReadWriteOrdCompBidRandCollMapIterator ¶ added in v0.17.0
type ReadWriteOrdCompBidRandCollMapIterator[TIndex any, TValue any] interface { ComparableIterator OrderedIterator BidirectionalIterator RandomAccessReadableMappingIterator[TIndex, TValue] RandomAccessWriteableMappingIterator[TIndex, TValue] }
type ReadWriteOrdCompForRandCollIterator ¶ added in v0.7.0
type ReadWriteOrdCompForRandCollIterator[TValue any] interface { OrderedIterator ComparableIterator ForwardIterator ReadableIterator[TValue] WritableIterator[TValue] RandomAccessIterator }
type ReadableIterator ¶
type ReadableIterator[TValue any] interface { // ********************* Inherited methods ********************// Iterator // Get returns the value at the iterator's position. // found will be false if the iterator is in an invalid state or the collection is empty. Get() (value TValue, found bool) }
ReadableIterator defines an Iterator, which can be used to read the underlying values.
type ReverseIteratorWithIndex ¶ added in v0.6.0
type ReverseIteratorWithIndex[TKey any, TValue any] 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 // End moves the iterator past the last element (one-past-the-end). // Call Prev() to fetch the last element if any. End() // Last moves the iterator to the last element and returns true if there was a last element in the container. // If Last() returns true, then last element's index and value can be retrieved by Index() and Value(). // Modifies the state of the iterator. Last() bool // PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the // passed function, and returns true if there was a next element in the container. // If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value(). // Modifies the state of the iterator. PrevTo(func(index int, value TValue) bool) bool IteratorWithKey[TKey, TValue] }
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 ¶
Last() function to move the iterator to the last element.
End() function to move the iterator past the last element (one-past-the-end).
type ReverseIteratorWithKey ¶ added in v0.6.0
type ReverseIteratorWithKey[TKey any, TValue any] 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 key and value can be retrieved by Key() and Value(). // Modifies the state of the iterator. Prev() bool // End moves the iterator past the last element (one-past-the-end). // Call Prev() to fetch the last element if any. End() // Last moves the iterator to the last element and returns true if there was a last element in the container. // If Last() returns true, then last element's key and value can be retrieved by Key() and Value(). // Modifies the state of the iterator. Last() bool // PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the // passed function, and returns true if there was a next element in the container. // If PrevTo() returns true, then next element's key and value can be retrieved by Key() and Value(). // Modifies the state of the iterator. PrevTo(func(key TKey, value TValue) bool) bool IteratorWithKey[TKey, TValue] }
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 ¶
Last() function to move the iterator to the last element.
type SizedIterator ¶
type SizedIterator interface {
// ********************* Inherited methods ********************//
Iterator
// Size returns the number of elements in the iterator.
Size() int
}
SizedIterator defines an Iterator, which can be said to have a fixed size.
type WritableIterator ¶
type WritableIterator[TValue any] interface { // ********************* Inherited methods ********************// Iterator // Set sets the value at the iterator's position. Set(value TValue) bool }
WritableIterator defines an Iterator, which can be used to write to the underlying values.