Documentation
¶
Index ¶
- Variables
- func AggregateMap[K comparable, V any, R any](src map[K]V, agg func(K, V, R) R, initial R) R
- func AggregateSlice[X any, Y any](src []X, agg func(X, Y) Y, initial Y) Y
- func Equals[T any](a, b T) bool
- func ProjectMapToMap[K1 comparable, V1 any, K2 comparable, V2 any](src map[K1]V1, project func(K1, V1) (K2, V2)) map[K2]V2
- func ProjectMapToSlice[K comparable, V any, R any](src map[K]V, project func(K, V) R) []R
- func ProjectSlice[X any, Y any](src []X, project func(X) Y) []Y
- type Collection
- type Comparable
- type LinkedList
- func (l *LinkedList[T]) Add(elements ...T) bool
- func (l *LinkedList[T]) AddAll(c Collection[T]) bool
- func (l *LinkedList[T]) AddIndex(element T, idx int) error
- func (l *LinkedList[T]) Clear()
- func (l *LinkedList[T]) Element() (T, error)
- func (l *LinkedList[T]) Fetch() (T, error)
- func (l *LinkedList[T]) Get(idx int) (T, error)
- func (l *LinkedList[T]) Iterator() iterators.Iterator[T]
- func (al *LinkedList) MarshalJSON() ([]byte, error)
- func (l *LinkedList[T]) New() Collection[T]
- func (l *LinkedList[T]) Peek() T
- func (l *LinkedList[T]) Poll() T
- func (l *LinkedList[T]) Push(elements ...T) error
- func (l *LinkedList[T]) Remove(elements ...T) bool
- func (l *LinkedList[T]) RemoveAllOf(elements ...T) bool
- func (l *LinkedList[T]) RemoveIf(filter Predicate[T]) bool
- func (l *LinkedList[T]) RemoveIndex(idx int) error
- func (l *LinkedList[T]) Size() int
- func (l *LinkedList[T]) ToSlice() []T
- func (al *LinkedList) UnmarshalJSON(data []byte) error
- type List
- type Predicate
- type Queue
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = fmt.Errorf("not implemented")
Functions ¶
func AggregateMap ¶ added in v0.12.0
func AggregateMap[K comparable, V any, R any](src map[K]V, agg func(K, V, R) R, initial R) R
AggregateMap takes a map, an aggregation function and an initial value. It applies the aggregation function to each key-value pair in the map, also passing in the current result. For the first key-value pair, it uses the initial value as the current result. Returns initial if the aggregation function is nil. Note that the iteration order over the map elements is undefined and may vary between executions.
func AggregateSlice ¶ added in v0.12.0
AggregateSlice takes a slice, an aggregation function and an initial value. It applies the aggregation function to each element of the slice, also passing in the current result. For the first element, it uses the initial value as the current result. Returns initial if the aggregation function is nil.
func Equals ¶
Equals compares two values of the same type. If the type implements the Comparable[T] interface, its Equals method is used for comparison. Otherwise, the standard comparison is used. Panics if the type is not comparable and does not implement Comparable[T].
func ProjectMapToMap ¶ added in v0.12.0
func ProjectMapToMap[K1 comparable, V1 any, K2 comparable, V2 any](src map[K1]V1, project func(K1, V1) (K2, V2)) map[K2]V2
ProjectMapToMap takes a map and a projection function and applies this function to each key-value pair in the map. It returns a new map containing the results of the projection. The original map is not modified. Note that the resulting map may be smaller if the projection function does not guarantee unique keys. If the projection function is nil, it returns nil.
func ProjectMapToSlice ¶ added in v0.12.0
func ProjectMapToSlice[K comparable, V any, R any](src map[K]V, project func(K, V) R) []R
ProjectMapToSlice takes a map and a projection function and applies this function to each key-value pair in the map. It returns a new slice containing the results of the projection. The original map is not modified. If the projection function is nil, it returns nil.
func ProjectSlice ¶ added in v0.12.0
ProjectSlice takes a slice and a projection function and applies this function to each element of the slice. It returns a new slice containing the results of the projection. The original slice is not modified. If the projection function is nil, it returns nil.
Types ¶
type Collection ¶
type Collection[T any] interface { iterators.Iterable[T] // Add ensures that this collection contains the specified elements. // Returns true if the collection changed as a result of the operation. // (returns false if the collection does not support duplicates and already contained all given elements). Add(elements ...T) bool // AddAll adds all elements from the given collection to this one. // Returns true if the collection changed as a result of the operation. AddAll(c Collection[T]) bool // Clear removes all of the elements from this collection. Clear() // Returns true if this collection contains the specified element. Contains(element T) bool // ContainsAll returns true if this collection contains all of the elements in the specified collection. ContainsAll(c Collection[T]) bool // Compares the specified object with this collection for equality. Equals(c Collection[T]) bool // IsEmpty returns true if this collection contains no elements. IsEmpty() bool // Removes all given elements from the collection, if they are present. // Each specified element is removed only once, even if it is contained multiple times in the collection. // Returns true if the collection changed as a result of the operation. Remove(elements ...T) bool // RemoveAllOf removes all instances of the given elements from the collection. // Returns true if the collection changed as a result of the operation. RemoveAllOf(elements ...T) bool // Removes all of this collection's elements that are also contained in the specified collection. // Returns true if the collection changed as a result of the operation. RemoveAll(c Collection[T]) bool // RetainAll removes all elements from the collection that are not contained in the specified collection. // Returns true if the collection changed as a result of the operation. RetainAll(c Collection[T]) bool // RemoveIf removes all elements from the collection that satisfy the given predicate. // Returns true if the collection changed as a result of the operation. RemoveIf(filter Predicate[T]) bool // Size returns the number of elements in this collection. Size() int // ToSlice returns a slice containing the elements in this collection. ToSlice() []T // New returns a new Collection of the same type. New() Collection[T] }
Collection represents a collection of elements. Note that T must be either comparable or implement the Comparable interface, otherwise runtime panics could occur.
type Comparable ¶
type Comparable[T any] interface { // Equals returns true if the receiver and the argument are equal. Equals(T) bool }
Comparable is an interface that can be implemented to use types as generic argument which don't satisfy the 'comparable' constraint.
type LinkedList ¶
type LinkedList[T any] struct { // contains filtered or unexported fields }
func NewLinkedList ¶
func NewLinkedList[T any](elements ...T) *LinkedList[T]
func NewLinkedListFromCollection ¶
func NewLinkedListFromCollection[T any](c Collection[T]) *LinkedList[T]
func (*LinkedList[T]) Add ¶
func (l *LinkedList[T]) Add(elements ...T) bool
Add ensures that this collection contains the specified elements. Returns true if the collection changed as a result of the operation. (returns false if the collection does not support duplicates and already contained all given elements).
func (*LinkedList[T]) AddAll ¶
func (l *LinkedList[T]) AddAll(c Collection[T]) bool
AddAll adds all elements from the given collection to this one. Returns true if the collection changed as a result of the operation.
func (*LinkedList[T]) AddIndex ¶
func (l *LinkedList[T]) AddIndex(element T, idx int) error
func (*LinkedList[T]) Clear ¶
func (l *LinkedList[T]) Clear()
Clear removes all of the elements from this collection.
func (*LinkedList[T]) Element ¶
func (l *LinkedList[T]) Element() (T, error)
func (*LinkedList[T]) Fetch ¶
func (l *LinkedList[T]) Fetch() (T, error)
func (*LinkedList[T]) Get ¶
func (l *LinkedList[T]) Get(idx int) (T, error)
func (*LinkedList[T]) Iterator ¶
func (l *LinkedList[T]) Iterator() iterators.Iterator[T]
Returns an iterator over the elements in this collection.
func (*LinkedList) MarshalJSON ¶
func (*LinkedList[T]) New ¶
func (l *LinkedList[T]) New() Collection[T]
New returns a new Collection of the same type.
func (*LinkedList[T]) Peek ¶
func (l *LinkedList[T]) Peek() T
func (*LinkedList[T]) Poll ¶
func (l *LinkedList[T]) Poll() T
func (*LinkedList[T]) Push ¶
func (l *LinkedList[T]) Push(elements ...T) error
func (*LinkedList[T]) Remove ¶
func (l *LinkedList[T]) Remove(elements ...T) bool
Removes all given elements from the collection, if they are present. Each specified element is removed only once, even if it is contained multiple times in the collection. Returns true if the collection changed as a result of the operation.
func (*LinkedList[T]) RemoveAllOf ¶
func (l *LinkedList[T]) RemoveAllOf(elements ...T) bool
RemoveAllOf removes all instances of the given elements from the collection. Returns true if the collection changed as a result of the operation.
func (*LinkedList[T]) RemoveIf ¶
func (l *LinkedList[T]) RemoveIf(filter Predicate[T]) bool
RemoveIf removes all elements from the collection that satisfy the given predicate. Returns true if the collection changed as a result of the operation.
func (*LinkedList[T]) RemoveIndex ¶
func (l *LinkedList[T]) RemoveIndex(idx int) error
func (*LinkedList[T]) Size ¶
func (l *LinkedList[T]) Size() int
Size returns the number of elements in this collection.
func (*LinkedList[T]) ToSlice ¶
func (l *LinkedList[T]) ToSlice() []T
ToSlice returns a slice containing the elements in this collection.
func (*LinkedList) UnmarshalJSON ¶
type List ¶
type List[T any] interface { Collection[T] json.Marshaler json.Unmarshaler // AddIndex adds the given element at the specified index. // Returns an IndexOutOfBoundsError if the index is not within the list's size or equal to l.Size(). AddIndex(element T, idx int) error // RemoveIndex removes the element at the specified index. // Returns an IndexOutOfBoundsError if the index is not within the list's size. RemoveIndex(idx int) error // Get returns the element at the specified index. // Returns an IndexOutOfBoundsError if the index is not within the list's size. Get(idx int) (T, error) }
type Queue ¶
type Queue[T any] interface { Collection[T] // Push adds the given elements to the queue. // Returns an error, if the queue's size restriction prevents the elements from being added. Push(elements ...T) error // Peek returns the first element without removing it. // Returns T's zero value, if the queue is empty. Peek() T // Element returns the first element without removing it. // Returns an error, if the queue is empty. Element() (T, error) // Poll returns the first element and removes it from the queue. // Returns T's zero value, if the queue is empty. Poll() T // Fetch returns the first element and removes it from the queue. // Returns an error, if the queue is empty. Fetch() (T, error) }