Documentation ¶
Overview ¶
package dt provides container type implementations and interfaces.
All top level structures in this package can be trivially constructed and provide high level interfaces for most common operations. These structures are not safe for access from multiple concurrent go routines (see the queue/deque in the pubsub package as an alternative for these use cases.)
GENERATED FILE FROM PAIR IMPLEMENTATION
Index ¶
- Constants
- func ConsumePairs[K comparable, V any](iter *fun.Iterator[Pair[K, V]]) fun.Producer[*Pairs[K, V]]
- func ConsumeTuples[K any, V any](iter *fun.Iterator[Tuple[K, V]]) fun.Producer[*Tuples[K, V]]
- func DefaultMap[K comparable, V any](input map[K]V, args ...int) map[K]V
- func MapIterator[K comparable, V any](in map[K]V) *fun.Iterator[Pair[K, V]]
- func MapKeys[K comparable, V any](in map[K]V) *fun.Iterator[K]
- func MapValues[K comparable, V any](in map[K]V) *fun.Iterator[V]
- func Transform[T any, O any](in Slice[T], op fun.Transform[T, O]) fun.Producer[Slice[O]]
- func Unwind[T any](in T) []T
- func Unwrap[T any](in T) (out T)
- type Element
- func (e *Element[T]) Append(new *Element[T]) *Element[T]
- func (e *Element[T]) Drop()
- func (e *Element[T]) In(l *List[T]) bool
- func (e *Element[T]) Next() *Element[T]
- func (e *Element[T]) Ok() bool
- func (e *Element[T]) Previous() *Element[T]
- func (e *Element[T]) Remove() bool
- func (e *Element[T]) Set(v T) bool
- func (e *Element[T]) String() string
- func (e *Element[T]) Swap(with *Element[T]) bool
- func (e *Element[T]) UnmarshalJSON(in []byte) error
- func (e *Element[T]) Value() T
- type Heap
- type Item
- func (it *Item[T]) Append(n *Item[T]) *Item[T]
- func (it *Item[T]) Attach(stack *Stack[T]) bool
- func (it *Item[T]) Detach() *Stack[T]
- func (it *Item[T]) In(s *Stack[T]) bool
- func (it *Item[T]) MarshalJSON() ([]byte, error)
- func (it *Item[T]) Next() *Item[T]
- func (it *Item[T]) Ok() bool
- func (it *Item[T]) Remove() bool
- func (it *Item[T]) Set(v T) bool
- func (it *Item[T]) String() string
- func (it *Item[T]) UnmarshalJSON(in []byte) error
- func (it *Item[T]) Value() T
- type List
- func (l *List[T]) Append(items ...T)
- func (l *List[T]) Back() *Element[T]
- func (l *List[T]) Copy() *List[T]
- func (l *List[T]) Extend(input *List[T])
- func (l *List[T]) Front() *Element[T]
- func (l *List[T]) IsSorted(lt cmp.LessThan[T]) bool
- func (l *List[T]) Iterator() *fun.Iterator[T]
- func (l *List[T]) Len() int
- func (l *List[T]) MarshalJSON() ([]byte, error)
- func (l *List[T]) PopBack() *Element[T]
- func (l *List[T]) PopFront() *Element[T]
- func (l *List[T]) PopIterator() *fun.Iterator[T]
- func (l *List[T]) PopReverse() *fun.Iterator[T]
- func (l *List[T]) Populate(iter *fun.Iterator[T]) fun.Worker
- func (l *List[T]) Producer() fun.Producer[T]
- func (l *List[T]) ProducerPop() fun.Producer[T]
- func (l *List[T]) ProducerReverse() fun.Producer[T]
- func (l *List[T]) ProducerReversePop() fun.Producer[T]
- func (l *List[T]) PushBack(it T)
- func (l *List[T]) PushFront(it T)
- func (l *List[T]) Reverse() *fun.Iterator[T]
- func (l *List[T]) Slice() Slice[T]
- func (l *List[T]) SortMerge(lt cmp.LessThan[T])
- func (l *List[T]) SortQuick(lt cmp.LessThan[T])
- func (l *List[T]) UnmarshalJSON(in []byte) error
- type Map
- func (m Map[K, V]) Add(k K, v V)
- func (m Map[K, V]) AddPair(p Pair[K, V])
- func (m Map[K, V]) AddTuple(p Tuple[K, V])
- func (m Map[K, V]) Append(pairs ...Pair[K, V])
- func (m Map[K, V]) Check(key K) bool
- func (m Map[K, V]) ConsumeMap(in Map[K, V])
- func (m Map[K, V]) ConsumePairs(pairs *Pairs[K, V])
- func (m Map[K, V]) ConsumeSlice(in []V, keyf func(V) K)
- func (m Map[K, V]) ConsumeTuples(tuples *Tuples[K, V])
- func (m Map[K, V]) ConsumeValues(iter *fun.Iterator[V], keyf func(V) K) fun.Worker
- func (m Map[K, V]) Delete(k K)
- func (m Map[K, V]) Extend(pairs *Pairs[K, V])
- func (m Map[K, V]) Get(key K) V
- func (m Map[K, V]) Iterator() *fun.Iterator[Pair[K, V]]
- func (m Map[K, V]) Keys() *fun.Iterator[K]
- func (m Map[K, V]) Len() int
- func (m Map[K, V]) Load(key K) (V, bool)
- func (m Map[K, V]) Pairs() *Pairs[K, V]
- func (m Map[K, V]) Producer() fun.Producer[Pair[K, V]]
- func (m Map[K, V]) ProducerKeys() fun.Producer[K]
- func (m Map[K, V]) ProducerValues() fun.Producer[V]
- func (m Map[K, V]) SetDefault(key K)
- func (m Map[K, V]) Tuples() *Tuples[K, V]
- func (m Map[K, V]) Values() *fun.Iterator[V]
- type Optional
- func (o *Optional[T]) Default(in T)
- func (o *Optional[T]) DefaultFuture(in fun.Future[T])
- func (o *Optional[T]) Future() fun.Future[T]
- func (o *Optional[T]) Get() (T, bool)
- func (o *Optional[T]) Handler() fun.Handler[T]
- func (o Optional[T]) MarshalBinary() ([]byte, error)
- func (o Optional[T]) MarshalText() ([]byte, error)
- func (o Optional[T]) Ok() bool
- func (o *Optional[T]) Reset()
- func (o *Optional[T]) Resolve() T
- func (o *Optional[T]) Scan(src any) (err error)
- func (o *Optional[T]) Set(in T)
- func (o *Optional[T]) SetWhen(cond bool, v T)
- func (o *Optional[T]) SetWhenFuture(cond bool, v fun.Future[T])
- func (o *Optional[T]) Swap(next T) (prev T)
- func (o *Optional[T]) UnmarshalBinary(in []byte) (err error)
- func (o *Optional[T]) UnmarshalText(in []byte) (err error)
- func (o Optional[T]) Value() (driver.Value, error)
- type Pair
- type Pairs
- func (p *Pairs[K, V]) Add(k K, v V) *Pairs[K, V]
- func (p *Pairs[K, V]) Append(new ...Pair[K, V])
- func (p *Pairs[K, V]) Consume(iter *fun.Iterator[Pair[K, V]]) fun.Worker
- func (p *Pairs[K, V]) ConsumeMap(in map[K]V)
- func (p *Pairs[K, V]) ConsumeSlice(in []V, keyf func(V) K)
- func (p *Pairs[K, V]) ConsumeValues(iter *fun.Iterator[V], keyf func(V) K) fun.Worker
- func (p *Pairs[K, V]) Copy() *Pairs[K, V]
- func (p *Pairs[K, V]) Extend(toAdd *Pairs[K, V])
- func (p *Pairs[K, V]) Iterator() *fun.Iterator[Pair[K, V]]
- func (p *Pairs[K, V]) Keys() *fun.Iterator[K]
- func (p *Pairs[K, V]) Len() int
- func (p *Pairs[K, V]) List() *List[Pair[K, V]]
- func (p *Pairs[K, V]) Map() map[K]V
- func (p *Pairs[K, V]) MarshalJSON() ([]byte, error)
- func (p *Pairs[K, V]) Observe(hf fun.Handler[Pair[K, V]])
- func (p *Pairs[K, V]) Process(pf fun.Processor[Pair[K, V]]) fun.Worker
- func (p *Pairs[K, V]) Push(pair Pair[K, V])
- func (p *Pairs[K, V]) Slice() []Pair[K, V]
- func (p *Pairs[K, V]) SortMerge(c cmp.LessThan[Pair[K, V]])
- func (p *Pairs[K, V]) SortQuick(c cmp.LessThan[Pair[K, V]])
- func (p *Pairs[K, V]) UnmarshalJSON(in []byte) error
- func (p *Pairs[K, V]) Values() *fun.Iterator[V]
- type Set
- func (s *Set[T]) Add(in T)
- func (s *Set[T]) AddCheck(in T) (ok bool)
- func (s *Set[T]) Check(in T) bool
- func (s *Set[T]) Delete(in T)
- func (s *Set[T]) DeleteCheck(in T) bool
- func (s *Set[T]) Equal(other *Set[T]) bool
- func (s *Set[T]) Extend(extra *Set[T])
- func (s *Set[T]) Iterator() *fun.Iterator[T]
- func (s *Set[T]) Len() int
- func (s *Set[T]) MarshalJSON() ([]byte, error)
- func (s *Set[T]) Order()
- func (s *Set[T]) Populate(iter *fun.Iterator[T])
- func (s *Set[T]) Producer() (out fun.Producer[T])
- func (s *Set[T]) SortMerge(lt cmp.LessThan[T])
- func (s *Set[T]) SortQuick(lt cmp.LessThan[T])
- func (s *Set[T]) Synchronize()
- func (s *Set[T]) UnmarshalJSON(in []byte) error
- func (s *Set[T]) WithLock(mtx *sync.Mutex)
- type Slice
- func DefaultSlice[T any](input []T, args ...int) Slice[T]
- func MergeSlices[T any](sls ...[]T) Slice[T]
- func NewSlice[T any](in []T) Slice[T]
- func SlicePtrs[T any](in []T) Slice[*T]
- func SliceRefs[T any](in []*T) Slice[T]
- func SliceSparseRefs[T any](in []*T) Slice[T]
- func Sliceify[T any](in []T) Slice[T]deprecated
- func Variadic[T any](in ...T) Slice[T]
- func (s *Slice[T]) Add(in T)
- func (s *Slice[T]) AddWhen(cond bool, in T)
- func (s *Slice[T]) Append(in ...T)
- func (s *Slice[T]) AppendWhen(cond bool, in ...T)
- func (s Slice[T]) Cap() int
- func (s Slice[T]) Copy() Slice[T]
- func (s *Slice[T]) Empty()
- func (s *Slice[T]) Extend(in []T)
- func (s *Slice[T]) ExtendWhen(cond bool, in []T)
- func (s Slice[T]) FillTo(length int) Slice[T]
- func (s *Slice[T]) Filter(p func(T) bool) (o Slice[T])
- func (s *Slice[T]) FilterFuture(p func(T) bool) fun.Future[Slice[T]]
- func (s *Slice[T]) Grow(size int)
- func (s *Slice[T]) GrowCapacity(size int)
- func (s Slice[T]) Index(index int) T
- func (s Slice[T]) IsEmpty() bool
- func (s Slice[T]) Iterator() *fun.Iterator[T]
- func (s Slice[T]) Last() int
- func (s Slice[T]) Len() int
- func (s Slice[T]) Observe(of fun.Handler[T])
- func (s *Slice[T]) Populate(iter *fun.Iterator[T]) fun.Worker
- func (s *Slice[T]) Prepend(in ...T)
- func (s Slice[T]) Process(pf fun.Processor[T]) fun.Worker
- func (s Slice[T]) Ptr(index int) *T
- func (s Slice[T]) Ptrs() []*T
- func (s *Slice[T]) Reset()
- func (s *Slice[T]) Reslice(start, end int)
- func (s *Slice[T]) ResliceBeginning(start int)
- func (s *Slice[T]) ResliceEnd(end int)
- func (s Slice[T]) Sort(cp func(a, b T) bool)
- func (s Slice[T]) Sparse() Slice[T]
- func (s *Slice[T]) Truncate(n int)
- func (s Slice[T]) Zero()
- func (s Slice[T]) ZeroRange(start, end int)
- type Stack
- func (s *Stack[T]) Append(items ...T)
- func (s *Stack[T]) Head() *Item[T]
- func (s *Stack[T]) Iterator() *fun.Iterator[T]
- func (s *Stack[T]) Len() int
- func (s *Stack[T]) MarshalJSON() ([]byte, error)
- func (s *Stack[T]) Pop() *Item[T]
- func (s *Stack[T]) PopIterator() *fun.Iterator[T]
- func (s *Stack[T]) Populate(iter *fun.Iterator[T]) fun.Worker
- func (s *Stack[T]) Producer() fun.Producer[T]
- func (s *Stack[T]) ProducerPop() fun.Producer[T]
- func (s *Stack[T]) Push(it T)
- func (s *Stack[T]) UnmarshalJSON(in []byte) error
- type Tuple
- type Tuples
- func (p *Tuples[K, V]) Add(k K, v V) *Tuples[K, V]
- func (p *Tuples[K, V]) Append(new ...Tuple[K, V])
- func (p *Tuples[K, V]) Consume(iter *fun.Iterator[Tuple[K, V]]) fun.Worker
- func (p *Tuples[K, V]) Copy() *Tuples[K, V]
- func (p *Tuples[K, V]) Extend(toAdd *Tuples[K, V])
- func (p *Tuples[K, V]) Iterator() *fun.Iterator[Tuple[K, V]]
- func (p *Tuples[K, V]) Len() int
- func (p *Tuples[K, V]) List() *List[Tuple[K, V]]
- func (p *Tuples[K, V]) MarshalJSON() ([]byte, error)
- func (p *Tuples[K, V]) Observe(hf fun.Handler[Tuple[K, V]])
- func (p *Tuples[K, V]) Ones() *fun.Iterator[K]
- func (p *Tuples[K, V]) Process(pf fun.Processor[Tuple[K, V]]) fun.Worker
- func (p *Tuples[K, V]) Push(tuple Tuple[K, V])
- func (p *Tuples[K, V]) Slice() []Tuple[K, V]
- func (p *Tuples[K, V]) SortMerge(c cmp.LessThan[Tuple[K, V]])
- func (p *Tuples[K, V]) SortQuick(c cmp.LessThan[Tuple[K, V]])
- func (p *Tuples[K, V]) Twos() *fun.Iterator[V]
- func (p *Tuples[K, V]) UnmarshalJSON(in []byte) error
Constants ¶
const ErrUninitializedContainer ers.Error = ers.Error("uninitialized container")
ErrUninitializedContainer is the content of the panic produced when you attempt to perform an operation on an uninitialized sequence.
Variables ¶
This section is empty.
Functions ¶
func ConsumePairs ¶ added in v0.10.3
ConsumePairs creates a *Pairs[K,V] object from an iterator of Pair[K,V] objects.
func ConsumeTuples ¶ added in v0.10.5
ConsumeTuples creates a *Tuples[K,V] object from an iterator of Tuple[K,V] objects.
func DefaultMap ¶ added in v0.10.4
func DefaultMap[K comparable, V any](input map[K]V, args ...int) map[K]V
DefaultMap takes a map value and returns it if it's non-nil. If the map is nil, it constructs and returns a new map, with the (optionally specified length.
func MapIterator ¶
func MapIterator[K comparable, V any](in map[K]V) *fun.Iterator[Pair[K, V]]
MapIterator converts a map into an iterator of dt.Pair objects. The iterator is panic-safe, and uses one go routine to track the progress through the map. As a result you should always, either exhaust the iterator, cancel the context that you pass to the iterator OR call iterator.Close().
To use this iterator the items in the map are not copied, and the iteration order is randomized following the convention in go.
Use in combination with other iterator processing tools (generators, observers, transformers, etc.) to limit the number of times a collection of data must be coppied.
func MapKeys ¶
func MapKeys[K comparable, V any](in map[K]V) *fun.Iterator[K]
MapKeys takes an arbitrary map and produces an iterator over only the keys.
func MapValues ¶
func MapValues[K comparable, V any](in map[K]V) *fun.Iterator[V]
MapValues takes an arbitrary map and produces an iterator over only the values.
func Transform ¶
Transform processes a slice of one type into a slice of another type using the transformation function. Errors abort the transformation, with the exception of fun.ErrIteratorSkip. All errors are returned to the caller, except io.EOF which indicates the (early) end of iteration.
Types ¶
type Element ¶
type Element[T any] struct { // contains filtered or unexported fields }
Element is the underlying component of a list, provided by iterators, the Pop operations, and the Front/Back accesses in the list. You can use the methods on this objects to iterate through the list, and the Ok() method for validating zero-valued items.
func NewElement ¶
NewElement produces an unattached Element that you can use with Append. Element.Append(NewElement()) is essentially the same as List.PushBack().
func (*Element[T]) Append ¶
Append adds the element 'new' after the element 'e', inserting it in the next position in the list. Will return 'e' if 'new' is not valid for insertion into this list (e.g. it belongs to another list, or is attached to other elements, is already a member of this list, or is otherwise invalid.) PushBack and PushFront, are implemented in terms of Append.
func (*Element[T]) Drop ¶
func (e *Element[T]) Drop()
Drop wraps remove, and additionally, if the remove was successful, drops the value and sets the Ok value to false.
func (*Element[T]) In ¶
In checks to see if an element is in the specified list. Because elements hold a pointer to their list, this is an O(1) operation.
Returns false when the element is nil.
func (*Element[T]) Next ¶
Next produces the next element. This is always non-nil, *unless* the element is not a member of a list. At the ends of a list, the value is non-nil, but would return false for Ok.
func (*Element[T]) Ok ¶
Ok checks that an element is valid. Invalid elements can be produced at the end of iterations (e.g. the list's root object,) or if you attempt to Pop an element off of an empty list.
Returns false when the element is nil.
func (*Element[T]) Previous ¶
Previous produces the next element. This is always non-nil, *unless* the element is not a member of a list. At the ends of a list, the value is non-nil, but would return false for Ok.
func (*Element[T]) Remove ¶
Remove removes the elemtn from the list, returning true if the operation was successful. Remove returns false when the element is not valid to be removed (e.g. is not part of a list, is the root element of the list, etc.)
func (*Element[T]) Set ¶
Set allows you to change set the value of an item in place. Returns true if the operation is successful. The operation fails if the Element is the root item in a list or not a member of a list.
Set is safe to call on nil elements.
func (*Element[T]) Swap ¶
Swap exchanges the location of two elements in a list, returning true if the operation was successful, and false if the elements are not eligible to be swapped. It is valid/possible to swap the root element of the list with another element to "move the head", causing a wrap around effect. Swap will not operate if either element is nil, or not a member of the same list.
func (*Element[T]) UnmarshalJSON ¶
UnmarshalJSON reads the json value, and sets the value of the element to the value in the json, potentially overriding an existing value. By supporting json.Marshaler and json.Unmarshaler, Elements and lists can behave as arrays in larger json objects, and can be as the output/input of json.Marshal and json.Unmarshal.
type Heap ¶
Heap provides a min-order heap using the Heap.LT comparison operator to sort from lowest to highest. Push operations will panic if LT is not set.
func NewHeapFromIterator ¶
func NewHeapFromIterator[T any](ctx context.Context, cmp cmp.LessThan[T], iter *fun.Iterator[T]) (*Heap[T], error)
NewHeapFromIterator constructs and populates a heap using the input iterator and corresponding comparison function. Will return the input iterators Close() error if one exists, and otherwise will return the populated heap.
func (*Heap[T]) Iterator ¶
Iterator provides an fun.Iterator interface to the heap. The iterator consumes items from the heap, and will return when the heap is empty.
func (*Heap[T]) Len ¶
Len reports the size of the heap. Because the heap tracks its size with Push/Pop operations, this is a constant time operation.
type Item ¶
type Item[T any] struct { // contains filtered or unexported fields }
Item is a common wrapper for the elements in a stack.
func (*Item[T]) Append ¶
Append inserts a new item after the following item in the stack, returning the new item, or if the new item is not valid, the item itself.
func (*Item[T]) Attach ¶
Attach removes items from the back of the stack and appends them to the current item. This inverts the order of items in the input stack.
func (*Item[T]) Detach ¶
Detach splits a stack into two, using the current Item as the head of the new stack. The output is always non-nil: if the item is not valid or not the member of a stack Detach creates a new empty stack. If this item is currently the head of a stack, Detach returns that stack.
func (*Item[T]) In ¶
In reports if an item is a member of a stack. Because item's track references to the stack, this is an O(1) operation.
func (*Item[T]) MarshalJSON ¶
MarshalJSON returns the result of json.Marshal on the value of the item. By supporting json.Marshaler and json.Unmarshaler, Items and stacks can behave as arrays in larger json objects, and can be as the output/input of json.Marshal and json.Unmarshal.
func (*Item[T]) Ok ¶
Ok return true if the Value() has been set. Returns false for incompletely initialized values.
Returns false when the item is nil.
func (*Item[T]) Remove ¶
Remove removes the item from the stack, (at some expense, for items deeper in the stack.) If the operation isn't successful or possible the operation returns false.
func (*Item[T]) Set ¶
Set mutates the value of an Item, returning true if the operation has been successful. The operation fails if the Item is the head item in a stack or not a member of a stack.
func (*Item[T]) String ¶
String implements fmt.Stringer, and returns the string value of the item's value.
func (*Item[T]) UnmarshalJSON ¶
UnmarshalJSON reads the json value, and sets the value of the item to the value in the json, potentially overriding an existing value. By supporting json.Marshaler and json.Unmarshaler, Items and stacks can behave as arrays in larger json objects, and can be as the output/input of json.Marshal and json.Unmarshal.
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List provides a doubly linked list. Callers are responsible for their own concurrency control and bounds checking, and should generally use with the same care as a slice.
The Deque implementation in the pubsub package provides a similar implementation with locking and a notification system.
func NewListFromIterator ¶
NewListFromIterator builds a list from the elements in the iterator. Any error returned is either a context cancellation error or the result of a panic in the input iterator. The close method on the input iterator is not called.
func (*List[T]) Append ¶
func (l *List[T]) Append(items ...T)
Append adds a variadic sequence of items to the end of the list.
func (*List[T]) Back ¶
Back returns a pointer to the last element of the list. If the list is empty, this is also the first element of the list. The operation is non-destructive. You can use this pointer to begin a c-style iteration over the list:
for e := list.Back(); e.Ok(); e = e.Previous() { // operate }
func (*List[T]) Copy ¶
Copy duplicates the list. The element objects in the list are distinct, though if the Values are themselves references, the values of both lists would be shared.
func (*List[T]) Front ¶
Front returns a pointer to the first element of the list. If the list is empty, this is also the last element of the list. The operation is non-destructive. You can use this pointer to begin a c-style iteration over the list:
for e := list.Front(); e.Ok(); e = e.Next() { // operate }
func (*List[T]) IsSorted ¶
IsSorted reports if the list is sorted from low to high, according to the LessThan function.
func (*List[T]) Iterator ¶
Iterator returns an iterator over the values in the list in front-to-back order. The Iterator is not synchronized with the values in the list, and will be exhausted when you reach the end of the list.
If you add values to the list during iteration *behind* where the iterator is, these values will not be present in the iterator; however, values added ahead of the iterator, will be visible.
func (*List[T]) Len ¶
Len returns the length of the list. As the Append/Remove operations track the length of the list, this is an O(1) operation.
func (*List[T]) MarshalJSON ¶
MarshalJSON produces a JSON array representing the items in the list. By supporting json.Marshaler and json.Unmarshaler, Elements and lists can behave as arrays in larger json objects, and can be as the output/input of json.Marshal and json.Unmarshal.
func (*List[T]) PopBack ¶
PopBack removes the last element from the list. If the list is empty, this returns a detached non-nil value, that will report an Ok() false value. You can use this element to produce a C-style iterator over the list, that removes items during the iteration:
for e := list.PopBack(); e.Ok(); e = input.PopBack() { // do work }
func (*List[T]) PopFront ¶
PopFront removes the first element from the list. If the list is empty, this returns a nil value, that will report an Ok() false You can use this element to produce a C-style iterator over the list, that removes items during the iteration:
for e := list.PopFront(); e.Ok(); e = input.PopFront() { // do work }
func (*List[T]) PopIterator ¶
PopIterator produces an iterator that consumes elements from the list as it iterates, moving front-to-back.
If you add values to the list during iteration *behind* where the iterator is, these values will not be present in the iterator; however, values added ahead of the iterator, will be visible.
func (*List[T]) PopReverse ¶
PopReverse produces an iterator that consumes elements from the list as it iterates, moving back-to-front. To access an iterator of the *values* in the list, use PopReverseValues() for an iterator over the values.
If you add values to the list during iteration *behind* where the iterator is, these values will not be present in the iterator; however, values added ahead of the iterator, will be visible.
func (*List[T]) Populate ¶ added in v0.10.4
Populate returns a worker that adds items from the iterator to the list. Any error returned is either a context cancellation error or the result of a panic in the input iterator. The close method on the input iterator is not called.
func (*List[T]) Producer ¶
Producer provides a producer function that iterates through the contents of the list. When the producer reaches has fully iterated through the list, or iterates to an item that has been removed (likely due to concurrent access,) the producer returns io.EOF.
The Producer starts at the front of the list and iterates in order.
func (*List[T]) ProducerPop ¶
ProducerPop provides a producer function that iterates through the contents of the list, removing each item from the list as it encounters it. When the producer reaches has fully iterated through the list, or iterates to an item that has been removed (likely due to concurrent access,) the producer returns io.EOF.
In most cases, for destructive iteration, use the pubsub.Queue, pubsub.Deque, or one of the pubsub.Distributor implementations.
The Producer starts at the front of the list and iterates in order.
func (*List[T]) ProducerReverse ¶
ProducerReverse provides the same semantics and operation as the Producer operation, but starts at the end/tail of the list and works forward.
func (*List[T]) ProducerReversePop ¶
ProducerReverse provides the same semantics and operation as the ProducerPop operation, but starts at the end/tail of the list and works forward.
func (*List[T]) PushBack ¶
func (l *List[T]) PushBack(it T)
PushBack creates an element and appends it to the list. The performance of PushFront and PushBack are the same.
func (*List[T]) PushFront ¶
func (l *List[T]) PushFront(it T)
PushFront creates an element and prepends it to the list. The performance of PushFront and PushBack are the same.
func (*List[T]) Reverse ¶
Reverse returns an iterator that produces elements from the list, from the back to the front. The iterator is not synchronized with the values in the list, and will be exhausted when you reach the front of the list.
If you add values to the list during iteration *behind* where the iterator is, these values will not be present in the iterator; however, values added ahead of the iterator, will be visible.
func (*List[T]) SortMerge ¶
SortMerge sorts the list, using the provided comparison function and a Merge Sort operation. This is something of a novelty in most cases, as removing the elements from the list, adding to a slice and then using sort.Slice() from the standard library, and then re-adding those elements to the list, will perform better.
The operation will modify the input list, replacing it with an new list operation.
func (*List[T]) SortQuick ¶
SortQuick sorts the list, by removing the elements, adding them to a slice, and then using sort.SliceStable(). In many cases this performs better than the merge sort implementation.
func (*List[T]) UnmarshalJSON ¶
UnmarshalJSON reads json input and adds that to values in the list. If there are elements in the list, they are not removed. By supporting json.Marshaler and json.Unmarshaler, Elements and lists can behave as arrays in larger json objects, and can be as the output/input of json.Marshal and json.Unmarshal.
type Map ¶
type Map[K comparable, V any] map[K]V
Map is just a generic type wrapper around a map, mostly for the purpose of being able to interact with Pair[K,V] objects and Iterators.
All normal map operations are still accessible, these methods exist to provide accessible function objects for use in contexts where that may be useful and to improve the readability of some call sites, where default map access may be awkward.
func Mapify
deprecated
func Mapify[K comparable, V any](in map[K]V) Map[K, V]
Mapify provides a constructor that will produce a fun.Map without specifying types.
Deprecated: use NewMap() for this case.
func NewMap ¶ added in v0.10.7
func NewMap[K comparable, V any](in map[K]V) Map[K, V]
NewMap provides a constructor that will produce a fun.Map without specifying types.
func (Map[K, V]) Add ¶
func (m Map[K, V]) Add(k K, v V)
Add adds a key value pair directly to the map.
func (Map[K, V]) ConsumeMap ¶
ConsumeMap adds all the keys from the input map the map.
func (Map[K, V]) ConsumePairs ¶ added in v0.10.5
ConsumePairs adds items to the map from a Pairs object. Existing values for K are always overwritten.
func (Map[K, V]) ConsumeSlice ¶
func (m Map[K, V]) ConsumeSlice(in []V, keyf func(V) K)
ConsumeSlice adds a slice of values to the map, using the provided function to generate the key for the value. Existing values in the map are overridden.
func (Map[K, V]) ConsumeTuples ¶ added in v0.10.5
ConsumeTuples adds items to the map from a Tuples object. Existing values for K are always overwritten.
func (Map[K, V]) ConsumeValues ¶
ConsumeValues adds items to the map, using the function to generate the keys for the values.
This operation will panic (with an ErrInvariantValidation) if the keyf panics.
func (Map[K, V]) Delete ¶ added in v0.10.8
func (m Map[K, V]) Delete(k K)
Delete removes a key from the map.
func (Map[K, V]) Get ¶
func (m Map[K, V]) Get(key K) V
Get returns the value from the map, and is the same thing as:
foo := mp[key]
If the key is not present in the map, as with a normal map, this is the zero value for V.
func (Map[K, V]) Iterator ¶
Iterator converts a map into an iterator of dt.Pair objects. The iterator is panic-safe, and uses one go routine to track the progress through the map. As a result you should always, either exhaust the iterator, cancel the context that you pass to the iterator OR call iterator.Close().
To use this iterator the items in the map are not copied, and the iteration order is randomized following the convention in go.
Use in combination with other iterator processing tools (generators, observers, transformers, etc.) to limit the number of times a collection of data must be coppied.
func (Map[K, V]) Len ¶
Len returns the length. It is equivalent to len(Map), but is provided for consistency.
func (Map[K, V]) Load ¶
Load returns the value in the map for the key, and an "ok" value which is true if that item is present in the map.
func (Map[K, V]) Producer ¶
Producer constructs a fun.Producer function for the pairs in the map. The operation starts a goroutine on the first iteration that tracks the state of the iterator. Iteration order is randomized.
func (Map[K, V]) ProducerKeys ¶
ProducerKeys returns a generator that generates the keys of the map. The operation requires a goroutine to keep track of the state of the iteration, but does not buffer or cache keys.
func (Map[K, V]) ProducerValues ¶
ProducerValues returns a generator that generates the values of the map. The operation requires a goroutine to keep track of the state of the iteration, but does not buffer or cache values.
func (Map[K, V]) SetDefault ¶
func (m Map[K, V]) SetDefault(key K)
SetDefault set's sets the provided key in the map to the zero value for the value type.
type Optional ¶ added in v0.10.5
type Optional[T any] struct { // contains filtered or unexported fields }
Optional is a wrapper type for optional value, where using a pointer is unsuitable or awkward. The type provides a reasonable interface for manipulating the value, does not need to be initialized upon construction (i.e. safe to put in structs without needing to specify an initial value.) MarshalText and MarshalBinary (with corresponding) unmarshal) interfaces make Optional types easy to embed.
Marshal/Unmarshal methods are provided to support using optional in primary structs and to avoid the need to duplicate structs.
func NewOptional ¶ added in v0.10.5
NewOptional is simple constructor that constructs a new populated Optional value.
func (*Optional[T]) Default ¶ added in v0.10.5
func (o *Optional[T]) Default(in T)
Default sets value of the optional to the provided value if it is not already been defined.
func (*Optional[T]) DefaultFuture ¶ added in v0.10.5
DefaultFuture resolves the future if the optional has not yet been set.
func (*Optional[T]) Future ¶ added in v0.10.5
Future provides access to the value of the optional as a Future function. This does not disambiguate zero values. Use in conjunction with Optional.Handler and adt.AccessorsWithLock and adt.AccessorsWithReadLock to handle concurency control.
func (*Optional[T]) Get ¶ added in v0.10.5
Get returns the current value of the optional and the ok value. Use this to disambiguate zero values.
func (*Optional[T]) Handler ¶ added in v0.10.5
Handler provides access to setting the optional value as fun.Handler function. Use in conjunction with Optional.Future and adt.AccessorsWithLock and adt.AccessorsWithReadLock to handle concurency control.
func (Optional[T]) MarshalBinary ¶ added in v0.10.5
MarshalBinary supports marshaling optional values into binary formats and uses the value of the optional to dictate behavior. The underlying value must implement encoding.BinaryMarshaler, bson.Marshaler or a generic Marshal() interface. byte slices are passed through.
func (Optional[T]) MarshalText ¶ added in v0.10.5
MarshalText defines how to marshal the optional value in text-based contexts. In most cases it falls back on the value of the optional: using encoding.TextMarshaler, json.Marshaler, yaml.Marahaler, or a generic Marshal() ([]byte,error) interface are called. Strings and []byte values are through directly, and failing all of these options, this falls back to json.Marshal().
func (*Optional[T]) Reset ¶ added in v0.10.5
func (o *Optional[T]) Reset()
Reset unsets the OK value of the optional, and unsets the reference to the existing value.
func (*Optional[T]) Resolve ¶ added in v0.10.5
func (o *Optional[T]) Resolve() T
Resolve returns the current value of the optional. Zero values of T are ambiguous.
func (*Optional[T]) Scan ¶ added in v0.10.5
Scan implements the sql Scanner interface. This is invalid if the type of the optional value is not a primitive value type.
func (*Optional[T]) Set ¶ added in v0.10.5
func (o *Optional[T]) Set(in T)
Set marks the optional value as defined, and sets the optional value. You can set an optional to the zero value for type T. To "unset" a value use the Reset().
func (*Optional[T]) SetWhen ¶ added in v0.10.5
Set changes the value of the, only when the boolean cond value is positive.
func (*Optional[T]) SetWhenFuture ¶ added in v0.10.5
SetWhenFuture resolves the future only when
func (*Optional[T]) Swap ¶ added in v0.10.5
func (o *Optional[T]) Swap(next T) (prev T)
Swap returns the previous value of the optional and replaces it with the provided value
func (*Optional[T]) UnmarshalBinary ¶ added in v0.10.5
UnmarshalBinary provides a compliment to MarshalBinary, and serves as a passthrough for encoding.BinaryUnmarshaler, bson.Unmarshaler and the generic Unmarshal interface.
func (*Optional[T]) UnmarshalText ¶ added in v0.10.5
UnmarshalText provides an inverse version of MarshalText for the encoding.UnmarshalText interface. encoding.TextUnmarshaler, json.Unmarshaler, yaml.Unmarshaler, and a generic Unmarshler interface. Strings and bytes slices pass through directly, and json.Unmarshal() is used in all other situations.
type Pair ¶
type Pair[K comparable, V any] struct { Key K Value V }
Pair represents a key-value pair. Used by the adt synchronized map implementation and the set package to handle ordered key-value pairs.
func MakePair ¶
func MakePair[K comparable, V any](k K, v V) Pair[K, V]
MakePair constructs a pair object. This is identical to using the literal constructor but may be more ergonomic as the compiler seems to be better at inferring types in function calls over literal constructors.
type Pairs ¶
type Pairs[K comparable, V any] struct { // contains filtered or unexported fields }
Pairs implements a collection of key-value pairs.
func MakePairs ¶
func MakePairs[K comparable, V any](in ...Pair[K, V]) *Pairs[K, V]
MakePairs constructs a Pairs object from a sequence of Pairs. This is identical to using the literal constructor but may be more ergonomic as the compiler seems to be better at inferring types in function calls over literal constructors.
To build Pairs objects from other types, use the Consume methods.
func (*Pairs[K, V]) Add ¶
Add adds a new value to the underlying slice. This may add a duplicate key. The return value is provided to support chaining Add() operations
func (*Pairs[K, V]) Consume ¶
Consume adds items from an iterator of pairs to the current Pairs slice.
func (*Pairs[K, V]) ConsumeMap ¶
func (p *Pairs[K, V]) ConsumeMap(in map[K]V)
ConsumeMap adds all of the items in a map to the Pairs object.
func (*Pairs[K, V]) ConsumeSlice ¶
func (p *Pairs[K, V]) ConsumeSlice(in []V, keyf func(V) K)
ConsumeSlice adds all the values in the input slice to the Pairs object, creating the keys using the function provide.
func (*Pairs[K, V]) ConsumeValues ¶
ConsumeValues adds all of the values in the input iterator, generating the keys using the function provided.
func (*Pairs[K, V]) Extend ¶
Extend adds the items from a Pairs object (slice of Pair) without modifying the donating object.
func (*Pairs[K, V]) Keys ¶
Keys returns an iterator over only the keys in a sequence of iterator items.
func (*Pairs[K, V]) Map ¶
func (p *Pairs[K, V]) Map() map[K]V
Map converts a list of pairs to the equivalent map. If there are duplicate keys in the Pairs list, only the first occurrence of the key is retained.
func (*Pairs[K, V]) MarshalJSON ¶
MarshalJSON produces a JSON encoding for the Pairs object by first converting it to a map and then encoding that map as JSON. The JSON serialization does not necessarily preserve the order of the pairs object.
func (*Pairs[K, V]) Observe ¶ added in v0.10.3
Observe calls the handler function for every pair in the container.
func (*Pairs[K, V]) Process ¶ added in v0.10.3
Process returns a worker, that when executed calls the processor function for every pair in the container.
func (*Pairs[K, V]) Push ¶ added in v0.10.5
Push adds a single pair to the slice of pairs. This may add a duplicate key.
func (*Pairs[K, V]) SortMerge ¶ added in v0.10.2
SortMerge performs a merge sort on the collected pairs.
func (*Pairs[K, V]) SortQuick ¶ added in v0.10.2
SortQuick does a quick sort using sort.StableSort. Typically faster than SortMerge, but potentially more memory intensive for some types.
func (*Pairs[K, V]) UnmarshalJSON ¶
UnmarshalJSON provides consistent JSON decoding for Pairs objects. It reads a JSON document into a map and converts it to pairs, and appends it to the existing Pairs objects without removing or resetting the current object.
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set provides a flexible generic set implementation, with optional safety for concurrent use (via Synchronize() and WithLock() methods,) and optional order tracking (via Order().)
func NewSetFromMap ¶ added in v0.10.3
func NewSetFromMap[K, V comparable](in map[K]V) *Set[Pair[K, V]]
NewSetFromMap constructs a Set of pairs derived from the input map. The resulting set is constrained by both the keys and the values, and so would permit duplicate "keys" from the perspective of the map, and may not therefore roundtrip.
func NewSetFromSlice ¶ added in v0.10.3
func NewSetFromSlice[T comparable](in []T) *Set[T]
NewSetFromSlice constructs a map and adds all items from the input slice to the new set.
func (*Set[T]) Add ¶
func (s *Set[T]) Add(in T)
Add attempts to add the item to the mutex, and is a noop otherwise.
func (*Set[T]) AddCheck ¶
AddCheck adds an item to the set and returns true if the item had been in the set before AddCheck. In all cases when AddCheck returns, the item is a member of the set.
func (*Set[T]) Delete ¶
func (s *Set[T]) Delete(in T)
Delete attempts to remove the item from the set.
func (*Set[T]) DeleteCheck ¶
DeleteCheck removes the item from the set, return true when the item had been in the Set, and returning false othewise
func (*Set[T]) Equal ¶
Equal tests two sets, returning true if the items in the sets have equal values. If the iterators are ordered, order is considered.
func (*Set[T]) Iterator ¶
Iterator provides a way to iterate over the items in the set. Provides items in iteration order if the set is ordered.
func (*Set[T]) MarshalJSON ¶
MarshalJSON generates a JSON array of the items in the set.
func (*Set[T]) Order ¶
func (s *Set[T]) Order()
Order enables order tracking for the Set. The method panics if there is more than one item in the map. If order tracking is enabled, this operation is a noop.
func (*Set[T]) Producer ¶
Producer will produce each item from set on successive calls. If the Set is ordered, then the producer produces items in the set's order. If the Set is synchronize, then the Producer always holds the Set's lock when called.
func (*Set[T]) SortMerge ¶ added in v0.10.4
SortMerge sorts the elements in an ordered set using a merge sort algorithm. If the set is not ordered, it will become ordered. Unlike the Order() method, you can use this method on a populated but unordered set.
func (*Set[T]) SortQuick ¶ added in v0.10.4
SortQuick sorts the elements in the set using sort.StableSort. Typically faster than SortMerge, but potentially more memory intensive for some types. If the set is not ordered, it will become ordered. Unlike the Order() method, you can use this method on a populated but unordered set.
func (*Set[T]) Synchronize ¶
func (s *Set[T]) Synchronize()
Synchronize creates a mutex and enables its use in the Set. This operation is safe to call more than once,
func (*Set[T]) UnmarshalJSON ¶
UnmarshalJSON reads input JSON data, constructs an array in memory and then adds items from the array to existing set. Items that are in the set when UnmarshalJSON begins are not modified.
type Slice ¶
type Slice[T any] []T
Slice is just a local wrapper around a slice, providing a similarly expressive interface to the Map and Pair types in the fun package.
func DefaultSlice ¶ added in v0.10.4
DefaultSlice takes a slice value and returns it if it's non-nil. If the slice is nil, it returns a slice of the specified length (and capacity,) as specified.
func MergeSlices ¶ added in v0.10.5
MergeSlices takes a variadic set of arguments which are all slices, and returns a single slice, that contains all items in the input slice.
func NewSlice ¶ added in v0.10.7
NewSlice produces a slice object as a convenience constructor to avoid needing to specify types.
func SlicePtrs ¶ added in v0.10.4
SlicePtrs converts a slice of values to a slice of values. This is a helper for Sliceify(in).Ptrs().
func SliceRefs ¶ added in v0.10.4
SliceRefs converts a slice of pointers to a slice of values, replacing all nil pointers with the zero type for that value.
func SliceSparseRefs ¶ added in v0.10.4
SliceRefs converts a slice of pointers to a slice of objects, dropping nil values. from the output slice.
func (*Slice[T]) AddWhen ¶
AddWhen embeds a conditional check in the Add, and only adds the item to the slice when the condition is true.
func (*Slice[T]) Append ¶
func (s *Slice[T]) Append(in ...T)
Append adds all of the items to the end of the slice.
func (*Slice[T]) AppendWhen ¶
AppendWhen embeds a conditional check in the Append operation, and only adds the items to the slice when the condition is true.
func (*Slice[T]) Empty ¶
func (s *Slice[T]) Empty()
Empty re-slices the slice, to omit all items, but retain the allocation.
func (*Slice[T]) Extend ¶
func (s *Slice[T]) Extend(in []T)
Extend adds the items from the input slice to the root slice.
func (*Slice[T]) ExtendWhen ¶
ExtendWhen embeds a conditional check in the Extend operatio and only adds the items to the slice when the condition is true.
func (Slice[T]) FillTo ¶ added in v0.10.5
FillTo appends zero values to the slice until it reaches the specified length, and returns the resulting slice.
func (*Slice[T]) Filter ¶
Filter returns a new slice, having passed all the items in the input slice. Items that the filter function returns true for are included and others are skipped.
func (*Slice[T]) FilterFuture ¶
FilterFuture returns a future that generates a new slice using the filter to select items from the root slice.
func (*Slice[T]) Grow ¶ added in v0.10.4
Grow adds zero items to the slice until it reaches the desired size.
func (*Slice[T]) GrowCapacity ¶ added in v0.10.5
GrowCapacity extends the capacity of the slice (by adding zero items and the )
func (Slice[T]) Index ¶ added in v0.10.4
Index returns the item at the specified index.
If the provided index is not within the bounds of the slice the operation panics.
func (Slice[T]) Iterator ¶
Iterator returns an iterator to the items of the slice the range keyword also works for these slices.
func (Slice[T]) Last ¶
Last returns the index of the last element in the slice. Empty slices have `-1` last items.
func (*Slice[T]) Populate ¶ added in v0.10.3
Populate constructs an operation that adds all items from the iterator to the slice.
func (*Slice[T]) Prepend ¶ added in v0.10.4
func (s *Slice[T]) Prepend(in ...T)
Prepend adds the items to beginning of the slice.
func (Slice[T]) Process ¶
Process creates a future in the form of a work that, when called iterates through all items in the slice, returning when the processor errors. io.EOF errors are not returned, but do abort iteration early, while fun.ErrIteratorSkip is respected.
func (Slice[T]) Ptrs ¶ added in v0.10.2
func (s Slice[T]) Ptrs() []*T
Ptrs converts a slice in to a slice of pointers to the values in the original slice
func (*Slice[T]) Reset ¶
func (s *Slice[T]) Reset()
Reset constructs a new empty slice releasing the original allocation.
func (*Slice[T]) Reslice ¶
Reslice modifies the slice to set the new start and end indexes.
Slicing operations, can lead to panics if the indexes are out of bounds.
func (*Slice[T]) ResliceBeginning ¶
ResliceBeginning moves the "beginning" of the slice to the specified index.
Slicing operations, can lead to panics if the indexes are out of bounds.
func (*Slice[T]) ResliceEnd ¶
ResliceEnd moves the "end" of the slice to the specified index.
Slicing operations, can lead to panics if the indexes are out of bounds.
func (Slice[T]) Sort ¶
Sort reorders the slice using the provided com parator function, which should return true if a is less than b and, false otherwise. The slice is sorted in "lowest" to "highest" order.
func (Slice[T]) Sparse ¶ added in v0.10.5
Sparse always returns a new slice. It iterates through the elements in the source slice and checks, using ft.IsNil() (which uses reflection), if the value is nil, and only adds the item when it is not-nil.
func (*Slice[T]) Truncate ¶
Truncate removes the last n items from the end of the list.
Slicing operations, can lead to panics if the indexes are out of bounds.
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack provides a generic singly linked list, with an interface that is broadly similar to dt.List.
func NewStackFromIterator ¶
NewListFromIterator builds a stack from the elements in the iterator. In general, any error would be the result of the input iterators's close method.
func (*Stack[T]) Append ¶
func (s *Stack[T]) Append(items ...T)
Append adds a variadic sequence of items to the list.
func (*Stack[T]) Head ¶
Head returns the item at the top of this stack. This is a non destructive operation.
func (*Stack[T]) Iterator ¶
Iterator returns a non-destructive iterator over the Items in a stack. Iterator will not observe new items added to the stack during iteration.
func (*Stack[T]) Len ¶
Len returns the length of the stack. Because stack's track their own size, this is an O(1) operation.
func (*Stack[T]) MarshalJSON ¶
MarshalJSON produces a JSON array representing the items in the stack. By supporting json.Marshaler and json.Unmarshaler, Items and stacks can behave as arrays in larger json objects, and can be as the output/input of json.Marshal and json.Unmarshal.
func (*Stack[T]) Pop ¶
Pop removes the item on the top of the stack, and returns it. If the stack is empty, this will return, but not detach, the root item of the stack, which will report a false Ok() value.
func (*Stack[T]) PopIterator ¶
PopIterator returns a destructive iterator over the Items in a stack. PopIterator will not observe new items added to the stack during iteration.
func (*Stack[T]) Populate ¶ added in v0.10.4
Populate returns a worker that adds items from the iterator to the stack. Any error returned is either a context cancellation error or the result of a panic in the input iterator. The close method on the input iterator is not called.
func (*Stack[T]) ProducerPop ¶
func (*Stack[T]) UnmarshalJSON ¶
UnmarshalJSON reads json input and adds that to values in the stack. If there are items in the stack, they are not removed. By supporting json.Marshaler and json.Unmarshaler, Items and stacks can behave as arrays in larger json objects, and can be as the output/input of json.Marshal and json.Unmarshal.
type Tuple ¶ added in v0.10.5
Tuple represents a key-value tuple. Used by the adt synchronized map implementation and the set package to handle ordered key-value tuples.
func MakeTuple ¶ added in v0.10.5
MakeTuple constructs a tuple object. This is identical to using the literal constructor but may be more ergonomic as the compiler seems to be better at inferring types in function calls over literal constructors.
func (Tuple[K, V]) MarshalJSON ¶ added in v0.10.5
func (*Tuple[K, V]) UnmarshalJSON ¶ added in v0.10.5
type Tuples ¶ added in v0.10.5
Tuples implements a collection of key-value tuples.
func MakeTuples ¶ added in v0.10.5
MakeTuples constructs a Tuples object from a sequence of Tuples. This is identical to using the literal constructor but may be more ergonomic as the compiler seems to be better at inferring types in function calls over literal constructors.
To build Tuples objects from other types, use the Consume methods.
func (*Tuples[K, V]) Add ¶ added in v0.10.5
Add adds a new value to the underlying slice. This may add a duplicate key. The return value is provided to support chaining Add() operations
func (*Tuples[K, V]) Append ¶ added in v0.10.5
Append as a collection of tuples to the collection of key/value tuples.
func (*Tuples[K, V]) Consume ¶ added in v0.10.5
Consume adds items from an iterator of tuples to the current Tuples slice.
func (*Tuples[K, V]) Copy ¶ added in v0.10.5
Copy produces a new Tuples object with the same values.
func (*Tuples[K, V]) Extend ¶ added in v0.10.5
Extend adds the items from a Tuples object (slice of Tuple) without modifying the donating object.
func (*Tuples[K, V]) Iterator ¶ added in v0.10.5
Iterator return an iterator over each key-value tuples.
func (*Tuples[K, V]) MarshalJSON ¶ added in v0.10.5
MarshalJSON produces a JSON encoding for the Pairs object by first converting it to a map and then encoding that map as JSON. The JSON serialization does not necessarily preserve the order of the pairs object.
func (*Tuples[K, V]) Observe ¶ added in v0.10.5
Observe calls the handler function for every tuple in the container.
func (*Tuples[K, V]) Ones ¶ added in v0.10.5
Ones returns an iterator over only the keys in a sequence of iterator items.
func (*Tuples[K, V]) Process ¶ added in v0.10.5
Process returns a worker, that when executed calls the processor function for every tuple in the container.
func (*Tuples[K, V]) Push ¶ added in v0.10.5
Push adds a single tuple to the slice of tuples. This may add a duplicate key.
func (*Tuples[K, V]) SortMerge ¶ added in v0.10.5
SortMerge performs a merge sort on the collected tuples.
func (*Tuples[K, V]) SortQuick ¶ added in v0.10.5
SortQuick does a quick sort using sort.StableSort. Typically faster than SortMerge, but potentially more memory intensive for some types.
func (*Tuples[K, V]) Twos ¶ added in v0.10.5
Twos returns an iterator over only the values in a sequence of iterator tuples.
func (*Tuples[K, V]) UnmarshalJSON ¶ added in v0.10.5
UnmarshalJSON provides consistent JSON decoding for Pairs objects. It reads a JSON document into a map and converts it to pairs, and appends it to the existing Pairs objects without removing or resetting the current object.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cmp provides comparators for sorting linked lists.
|
Package cmp provides comparators for sorting linked lists. |
Package hdrhistogram provides an implementation of Gil Tene's HDR Histogram data structure.
|
Package hdrhistogram provides an implementation of Gil Tene's HDR Histogram data structure. |