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.)
Index ¶
- Constants
- func ConsumePairs[K comparable, V any](iter *fun.Stream[Pair[K, V]]) fun.Generator[*Pairs[K, V]]
- func ConsumeTuples[K any, V any](iter *fun.Stream[Tuple[K, V]]) fun.Generator[*Tuples[K, V]]
- func DefaultMap[K comparable, V any](input map[K]V, args ...int) map[K]V
- func Transform[T any, O any](in Slice[T], op fun.Converter[T, O]) fun.Generator[Slice[O]]
- func Unwind[T any](in T) []T
- func Unwrap[T any](in T) (out T)
- type Element
- func (e *Element[T]) Append(val *Element[T]) *Element[T]
- func (e *Element[T]) Drop()
- func (e *Element[T]) In(l *List[T]) bool
- func (e *Element[T]) MarshalJSON() ([]byte, error)
- func (e *Element[T]) Next() *Element[T]
- func (e *Element[T]) Ok() bool
- func (e *Element[T]) Previous() *Element[T]
- func (e *Element[T]) Push(v T) *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]) GeneratorBack() fun.Generator[T]
- func (l *List[T]) GeneratorFront() fun.Generator[T]
- func (l *List[T]) GeneratorPopBack() fun.Generator[T]
- func (l *List[T]) GeneratorPopFront() fun.Generator[T]
- func (l *List[T]) IsSorted(lt cmp.LessThan[T]) bool
- func (l *List[T]) Iterator() iter.Seq[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]) Populate(iter *fun.Stream[T]) fun.Worker
- func (l *List[T]) PushBack(it T)
- func (l *List[T]) PushFront(it 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]) StreamBack() *fun.Stream[T]
- func (l *List[T]) StreamFront() *fun.Stream[T]
- func (l *List[T]) StreamPopBack() *fun.Stream[T]
- func (l *List[T]) StreamPopFront() *fun.Stream[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]) Delete(k K)
- func (m Map[K, V]) Extend(pairs *Pairs[K, V])
- func (m Map[K, V]) ExtendWithPairs(pairs *Pairs[K, V])
- func (m Map[K, V]) ExtendWithStream(it *fun.Stream[Pair[K, V]]) fun.Worker
- func (m Map[K, V]) ExtendWithTuples(tuples *Tuples[K, V])
- func (m Map[K, V]) Generator() fun.Generator[Pair[K, V]]
- func (m Map[K, V]) GeneratorKeys() fun.Generator[K]
- func (m Map[K, V]) GeneratorValues() fun.Generator[V]
- func (m Map[K, V]) Get(key K) V
- func (m Map[K, V]) Keys() *fun.Stream[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]) SetDefault(key K)
- func (m Map[K, V]) Store(k K, v V)
- func (m Map[K, V]) Stream() *fun.Stream[Pair[K, V]]
- func (m Map[K, V]) Tuples() *Tuples[K, V]
- func (m Map[K, V]) Values() *fun.Stream[V]
- type Optional
- func (o *Optional[T]) Default(in T)
- func (o *Optional[T]) Future() fn.Future[T]
- func (o *Optional[T]) Get() (T, bool)
- func (o *Optional[T]) Handler() fn.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]) 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(vals ...Pair[K, V])
- func (p *Pairs[K, V]) Consume(iter *fun.Stream[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.Stream[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() iter.Seq[Pair[K, V]]
- func (p *Pairs[K, V]) Iterator2() iter.Seq2[K, V]
- func (p *Pairs[K, V]) Keys() *fun.Stream[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]) Push(pair Pair[K, V])
- func (p *Pairs[K, V]) ReadAll(pf fun.Handler[Pair[K, V]]) fun.Worker
- 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]) Stream() *fun.Stream[Pair[K, V]]
- func (p *Pairs[K, V]) UnmarshalJSON(in []byte) error
- func (p *Pairs[K, V]) Values() *fun.Stream[V]
- type Ring
- func (r *Ring[T]) Cap() int
- func (r *Ring[T]) FIFO() *fun.Stream[T]
- func (r *Ring[T]) Head() T
- func (r *Ring[T]) LIFO() *fun.Stream[T]
- func (r *Ring[T]) Len() int
- func (r *Ring[T]) Pop() *T
- func (r *Ring[T]) PopFIFO() *fun.Stream[T]
- func (r *Ring[T]) Push(val T)
- func (r *Ring[T]) Setup(size int)
- func (r *Ring[T]) Tail() T
- func (r *Ring[T]) Total() uint64
- type Set
- func (s *Set[T]) Add(in T)
- func (s *Set[T]) AddCheck(in T) (ok bool)
- func (s *Set[T]) AppendSet(extra *Set[T])
- func (s *Set[T]) AppendStream(iter *fun.Stream[T])
- 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]) Generator() (out fun.Generator[T])
- func (s *Set[T]) Iterator() iter.Seq[T]
- func (s *Set[T]) Len() int
- func (s *Set[T]) MarshalJSON() ([]byte, error)
- func (s *Set[T]) Order()
- func (s *Set[T]) SortMerge(lt cmp.LessThan[T])
- func (s *Set[T]) SortQuick(lt cmp.LessThan[T])
- func (s *Set[T]) Stream() *fun.Stream[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 Variadic[T any](in ...T) Slice[T]
- func (s *Slice[T]) Add(in T)
- func (s *Slice[T]) Append(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]) 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) fn.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]) Last() int
- func (s Slice[T]) Len() int
- func (s *Slice[T]) Populate(iter *fun.Stream[T]) fun.Worker
- func (s *Slice[T]) Prepend(in ...T)
- func (s Slice[T]) Ptr(index int) *T
- func (s Slice[T]) Ptrs() []*T
- func (s Slice[T]) ReadAll(of fn.Handler[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]) Stream() *fun.Stream[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]) Generator() fun.Generator[T]
- func (s *Stack[T]) GeneratorPop() fun.Generator[T]
- func (s *Stack[T]) Head() *Item[T]
- func (s *Stack[T]) Iterator() iter.Seq[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]) Populate(iter *fun.Stream[T]) fun.Worker
- func (s *Stack[T]) Push(it T)
- func (s *Stack[T]) Stream() *fun.Stream[T]
- func (s *Stack[T]) StreamPop() *fun.Stream[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(vals ...Tuple[K, V])
- func (p *Tuples[K, V]) Consume(iter *fun.Stream[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() iter.Seq[Tuple[K, V]]
- func (p *Tuples[K, V]) Iterator2() iter.Seq2[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]) Ones() *fun.Stream[K]
- func (p *Tuples[K, V]) Push(tuple Tuple[K, V])
- func (p *Tuples[K, V]) ReadAll(pf fun.Handler[Tuple[K, V]]) fun.Worker
- 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]) Stream() *fun.Stream[Tuple[K, V]]
- func (p *Tuples[K, V]) Twos() *fun.Stream[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 a stream of Pair[K,V] objects.
func ConsumeTuples ¶ added in v0.10.5
ConsumeTuples creates a *Tuples[K,V] object from a stream 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 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.ErrStreamContinue. 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 streams, 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]) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaler interface. Nil and unset Element values are marshaled as 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]) Push ¶ added in v0.12.0
Push adds a value to the list, and returns the resulting element.
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 (*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.
func (*Heap[T]) Pop ¶
Pop removes the element from the underlying list and returns it, with an Ok value, which is true when the value returned is valid.
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 (*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]) Extend ¶
Extend removes items from the front of the input list, and appends them to the end (back) of the current list.
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]) GeneratorBack ¶ added in v0.12.0
GeneratorBack provides the same semantics and operation as the Generator operation, but starts at the end/tail of the list and works forward.
func (*List[T]) GeneratorFront ¶ added in v0.12.0
GeneratorFront provides a generator function that iterates through the contents of the list, front-to-back. When the generator has fully iterated through the list, or iterates to an item that has been removed (likely due to concurrent access,) the generator returns io.EOF.
The GeneratorFront starts at the front of the list and iterates in order.
func (*List[T]) GeneratorPopBack ¶ added in v0.12.0
GeneratorPopBack provides the same semantics and operation as the GeneratorPopBack operation, but starts at the end/tail of the list and works forward.
func (*List[T]) GeneratorPopFront ¶ added in v0.12.0
GeneratorPopFront provides a generator function that iterates through the contents of the list, removing each item from the list as it encounters it. When the generator reaches has fully iterated through the list, or iterates to an item that has been removed (likely due to concurrent access,) the generator returns io.EOF.
In most cases, for destructive iteration, use the pubsub.Queue, pubsub.Deque, or one of the pubsub.Distributor implementations.
The generator starts at the front of the list and iterates in order.
func (*List[T]) IsSorted ¶
IsSorted reports if the list is sorted from low to high, according to the LessThan function.
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 stream 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 stream over the list, that removes items during the iteration:
for e := list.PopFront(); e.Ok(); e = input.PopFront() { // do work }
func (*List[T]) Populate ¶ added in v0.10.4
Populate returns a worker that adds items from the stream to the list. Any error returned is either a context cancellation error or the result of a panic in the input stream. The close method on the input stream is not called.
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]) 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]) StreamBack ¶ added in v0.12.0
StreamBack returns a stream that produces elements from the list, from the back to the front. The stream 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 stream is, these values will not be present in the stream; however, values added ahead of the stream, will be visible.
func (*List[T]) StreamFront ¶ added in v0.12.0
StreamFront returns a stream over the values in the list in front-to-back order. The Stream 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 stream is, these values will not be present in the stream; however, values added ahead of the stream, will be visible.
func (*List[T]) StreamPopBack ¶ added in v0.12.0
StreamPopBack produces a stream that consumes elements from the list as it iterates, moving back-to-front.
If you add values to the list during iteration *behind* where the stream is, these values will not be present in the stream; however, values added ahead of the stream, will be visible.
func (*List[T]) StreamPopFront ¶ added in v0.12.0
PopStream produces a stream 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 stream is, these values will not be present in the stream; however, values added ahead of the stream, will be visible.
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 Streams.
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 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]) 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]) ExtendWithPairs ¶ added in v0.12.0
ExtendWithPairs adds items to the map from a Pairs object. Existing values for K are always overwritten.
func (Map[K, V]) ExtendWithStream ¶ added in v0.12.0
ExtendWithStream adds items to the map. If a key already exists in the map, it will be overwritten for subsequent appearances of that key.
This operation is lazy, and returns a Worker (future) function that must be excuted to process the stream.
func (Map[K, V]) ExtendWithTuples ¶ added in v0.12.0
ExtendWithTuples adds items to the map from a Tuples object. Existing values for K are always overwritten.
func (Map[K, V]) Generator ¶ added in v0.12.0
Generator constructs a fun.Generator function for the pairs in the map. The operation starts a goroutine on the first iteration that tracks the state of the stream. Iteration order is randomized.
func (Map[K, V]) GeneratorKeys ¶ added in v0.12.0
GeneratorKeys 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]) GeneratorValues ¶ added in v0.12.0
GeneratorValues 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]) 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]) 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]) 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.
func (Map[K, V]) Store ¶ added in v0.12.0
func (m Map[K, V]) Store(k K, v V)
Store adds a key value pair directly to the map.
func (Map[K, V]) Stream ¶ added in v0.12.0
Stream converts a map into a stream of dt.Pair objects. The stream is panic-safe, and uses one go routine to track the progress through the map. As a result you should always, either exhaust the stream, cancel the context that you pass to the stream OR call stream.Close().
To use this stream the items in the map are not copied, and the iteration order is randomized following the convention in go.
Use in combination with other stream processing tools (generators, observers, transformers, etc.) to limit the number of times a collection of data must be coppied.
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]) 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 fn.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]) 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.
func (Pair[K, V]) Get ¶ added in v0.11.0
func (p Pair[K, V]) Get() (K, V)
Get returns only the key and value of a Pair. Provided for symmetry.
func (Pair[K, V]) GetKey ¶ added in v0.11.0
func (p Pair[K, V]) GetKey() K
GetValue returns only the key of a Pair. Provided for symmetry.
func (Pair[K, V]) GetValue ¶ added in v0.11.0
func (p Pair[K, V]) GetValue() V
GetValue returns only the value of a Pair. Provided for symmetry.
func (*Pair[K, V]) Set ¶ added in v0.11.0
Set is a helper to modify the both values of a pair. This method can be chained.
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]) 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 from 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 from the input stream, 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]) Iterator2 ¶ added in v0.12.0
Iterator2 returns a native go iterator function for the items in a pairs sequence.
func (*Pairs[K, V]) Keys ¶
Keys returns a stream over only the keys in a sequence of iterator items.
func (*Pairs[K, V]) Map ¶
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]) 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]) ReadAll ¶ added in v0.12.0
ReadAll returns a worker, that when executed calls the processor function for every pair in the container.
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 Ring ¶ added in v0.12.0
type Ring[T any] struct { // contains filtered or unexported fields }
Ring is a simple generic ring-buffer implemented on top of a slice/array with a few conveniences: there are forward and backward streams; you can pop items from the "end" (oldest) in the buffer. The Total() method maintains a count of the total number of items added to the buffer.
Operations on the Ring are NOT safe for concurrent use from multiple go routines.
func (*Ring[T]) Cap ¶ added in v0.12.0
Returns the capacity of the ring buffer. This is either the size passed to Setup() or the default 1024.
func (*Ring[T]) FIFO ¶ added in v0.12.0
FIFO returns a stream that begins at the first (oldest; Head) element and streams forward to the current or most recently added element in the buffer.
func (*Ring[T]) Head ¶ added in v0.12.0
func (r *Ring[T]) Head() T
Head returns the oldest element in the buffer.
func (*Ring[T]) LIFO ¶ added in v0.12.0
LIFO returns the element that was most recently added to buffer and iterates backwords to the oldest element in the buffer.
func (*Ring[T]) Len ¶ added in v0.12.0
Len returns the number of elements in the buffer. This is, some number between the capacity and 0. It is decremented when items are popped from the buffer, but only incremented when a previously empty position is filled.
func (*Ring[T]) Pop ¶ added in v0.12.0
func (r *Ring[T]) Pop() *T
Pop returns the oldest element in the buffer to the caller. If the buffer is empty, then Pop() returns nil.
The returned value is (effectively) owned by the caller of Pop() and is independent of the value stored in the ring.
func (*Ring[T]) PopFIFO ¶ added in v0.12.0
PopFIFO returns a FIFO stream that consumes elements in the buffer, starting with the oldest element in the buffer and moving through all elements. The stream is exhusted when the buffer is empty.
func (*Ring[T]) Push ¶ added in v0.12.0
func (r *Ring[T]) Push(val T)
Push adds an element to the buffer in the next position, potentially overwriting the oldest element in the buffer once the buffer is full.
Elements are always pushed to the "next" position in the buffer, even if elements are removed using Pop().
func (*Ring[T]) Setup ¶ added in v0.12.0
Setup sets the size of the ring buffer and initializes the buffer, if the buffer hasn't been used. Using the buffer initializes it with a size of 1024.
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]) AppendStream ¶ added in v0.12.0
AppendStream adds all items encountered in the stream to 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 sets are ordered, order is considered.
func (*Set[T]) Generator ¶ added in v0.12.0
Generator will produce each item from set on successive calls. If the Set is ordered, then the generator produces items in the set's order. If the Set is synchronize, then the Generator always holds the Set's lock when called.
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]) 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]) Stream ¶ added in v0.12.0
Stream provides a way to iterate over the items in the set. Provides items in iteration order if the set is ordered.
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 NewSlice(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
SliceSparseRefs converts a slice of pointers to a slice of objects, dropping nil values. from the output slice.
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]) 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]) 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]) 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 stream 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]) 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]) ReadAll ¶ added in v0.12.0
ReadAll calls the observer function on every item in the 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]) Stream ¶ added in v0.12.0
Stream returns a stream to the items of the slice the range keyword also works for these slices.
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 (*Stack[T]) Append ¶
func (s *Stack[T]) Append(items ...T)
Append adds a variadic sequence of items to the list.
func (*Stack[T]) GeneratorPop ¶ added in v0.12.0
func (*Stack[T]) Head ¶
Head returns the item at the top of this stack. This is a non destructive operation.
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]) Populate ¶ added in v0.10.4
Populate returns a worker that adds items from the stream to the stack. Any error returned is either a context cancellation error or the result of a panic in the input stream. The close method on the input stream is not called.
func (*Stack[T]) Stream ¶ added in v0.12.0
Stream returns a non-destructive stream over the Items in a stack. Stream will not observe new items added to the stack during iteration.
func (*Stack[T]) StreamPop ¶ added in v0.12.0
StreamPop returns a destructive stream over the Items in a stack. StreamPop will not observe new items added to the stack during iteration.
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 a stream 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 returns a native go iterator function for tuples.
func (*Tuples[K, V]) Iterator2 ¶ added in v0.12.0
Iterator2 returns a native go iterator over the items in a collections of 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]) Ones ¶ added in v0.10.5
Ones returns a stream over only the first item from a sequence of tuples.
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]) ReadAll ¶ added in v0.12.0
ReadAll returns a worker, that when executed calls the processor function for every tuple in the container.
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 a stream over only the second item from a sequence of 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 hdrhist provides an implementation of Gil Tene's HDR Histogram data structure.
|
Package hdrhist provides an implementation of Gil Tene's HDR Histogram data structure. |