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 CollectionIterator
- type ComparableIterator
- type Container
- type ForwardIterator
- type Iterator
- type JSONDeserializer
- type JSONSerializer
- type OrderedIterator
- type RWOrdCompBidRandCollIterator
- type RWOrdCompBidRevRandCollIterator
- type RandomAccessIterator
- type RandomAccessReadableIterator
- type RandomAccessWriteableIterator
- type ReadableIterator
- type ReversedIterator
- type SizedIterator
- type UnorderedBackwardIterator
- type UnorderedForwardIterator
- 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()
// NextN moves the iterator backward by n positions.
PreviousN(n int)
}
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)
}
BidirectionalIterator defines a ForwardIterator and BackwardIterator, which can be moved forward and backward according to the underlying data structure's ordering.
type CollectionIterator ¶
type CollectionIterator[TIndex any] interface { // ********************* Inherited methods ********************// SizedIterator // Index returns the index of the iterator's position in the collection. Index() TIndex }
CollectionIterator defines a SizedIterator, which can be said to reference a collection of elements.
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 ForwardIterator ¶
type ForwardIterator interface {
// ********************* Inherited methods ********************//
Iterator
// Next moves the iterator forward by one position.
Next()
// NextN moves the iterator forward by n positions.
NextN(i int)
}
ForwardIterator defines an ordered Iterator, which can be moved forward according to the indexes ordering.
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 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 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 RWOrdCompBidRandCollIterator ¶
type RWOrdCompBidRandCollIterator[T any, TIndex any] interface { OrderedIterator ComparableIterator BidirectionalIterator RandomAccessReadableIterator[TIndex, T] RandomAccessWriteableIterator[TIndex, T] }
type RWOrdCompBidRevRandCollIterator ¶
type RWOrdCompBidRevRandCollIterator[T any, TIndex any] interface { OrderedIterator ComparableIterator ReversedIterator BackwardIterator RandomAccessReadableIterator[TIndex, T] RandomAccessWriteableIterator[TIndex, T] }
type RandomAccessIterator ¶
type RandomAccessIterator[TIndex any] interface { // ********************* Inherited methods ********************// BidirectionalIterator CollectionIterator[TIndex] // MoveTo moves the iterator to the given index. MoveTo(i TIndex) }
RandomAccessIterator defines a BidirectionalIterator and CollectionIterator, which can be moved to every position in the iterator.
type RandomAccessReadableIterator ¶
type RandomAccessReadableIterator[T any, V any] interface { // ********************* Inherited methods ********************// RandomAccessIterator[T] ReadableIterator[V] // GetAt returns the value at the given index of the iterator. GetAt(i T) (value V, found bool) }
RandomAccessReadableIterator defines a RandomAccessIterator and ReadableIterator, which can read from every index in the iterator.
type RandomAccessWriteableIterator ¶
type RandomAccessWriteableIterator[T any, V any] interface { // ********************* Inherited methods ********************// RandomAccessIterator[T] WritableIterator[V] // GetAt sets the value at the given index of the iterator. SetAt(i T, value V) bool }
RandomAccessWriteableIterator defines a RandomAccessIterator and WritableIterator, which can write from every index in the iterator.
type ReadableIterator ¶
type ReadableIterator[T 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 T, found bool) }
ReadableIterator defines an Iterator, which can be used to read the underlying values.
type ReversedIterator ¶
type ReversedIterator interface {
// ********************* Inherited methods ********************//
ForwardIterator
}
ReversedIterator defines a a ForwardIterator, whose iteration direction is reversed. This allows using ForwardIterator and ReversedIterator with the same API.
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 UnorderedBackwardIterator ¶
type UnorderedBackwardIterator interface {
// ********************* Inherited methods ********************//
BackwardIterator
// PreviousOrdered moves the iterator backward by one position according to the indexes lexographical ordering instead of the underlying data structure's ordering.
PreviousOrdered()
// PreviousOrdered moves the iterator backward by n positions according to the indexes lexographical ordering instead of the underlying data structure's ordering.
PreviousOrderedN(n int)
}
UnorderedBackwardIterator defines an unordered BackwardIterator, which can be moved backward according to the indexes ordering in addition to the underlying data structure's ordering. This iterator would allow you to e.g. iterate over a builtin map in the reverse lexographical order of the keys.
type UnorderedForwardIterator ¶
type UnorderedForwardIterator interface {
// ********************* Inherited methods ********************//
ForwardIterator
// NextOrdered moves the iterator forward by one position according to the indexes lexographical ordering instead of the underlying data structure's ordering.
NextOrdered()
// NextOrdered moves the iterator forward by n positions according to the indexes lexographical ordering instead of the underlying data structure's ordering.
NextOrderedN(n int)
}
UnorderedForwardIterator defines an unordered ForwardIterator, which can be moved forward according to the indexes ordering in addition to the underlying data structure's ordering. This iterator would allow you to e.g. iterate over a builtin map in the lexographical order of the keys.
type WritableIterator ¶
type WritableIterator[T any] interface { // ********************* Inherited methods ********************// Iterator // Set sets the value at the iterator's position. Set(value T) bool }
WritableIterator defines an Iterator, which can be used to write to the underlying values.