dt

package
v0.10.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2024 License: Apache-2.0 Imports: 18 Imported by: 15

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

View Source
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

func ConsumePairs[K comparable, V any](iter *fun.Iterator[Pair[K, V]]) fun.Producer[*Pairs[K, V]]

ConsumePairs creates a *Pairs[K,V] object from an iterator of Pair[K,V] objects.

func ConsumeTuples added in v0.10.5

func ConsumeTuples[K any, V any](iter *fun.Iterator[Tuple[K, V]]) fun.Producer[*Tuples[K, V]]

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

func Transform[T any, O any](in Slice[T], op fun.Transform[T, O]) fun.Producer[Slice[O]]

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.

func Unwind

func Unwind[T any](in T) []T

Unwind uses the Unwrap operation to build a list of the "wrapped" objects.

func Unwrap

func Unwrap[T any](in T) (out T)

Unwrap is a generic equivalent of the `errors.Unwrap()` function for any type that implements an `Unwrap() T` method. useful in combination with Is.

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

func NewElement[T any](val T) *Element[T]

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

func (e *Element[T]) Append(new *Element[T]) *Element[T]

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

func (e *Element[T]) In(l *List[T]) bool

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

func (e *Element[T]) Next() *Element[T]

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

func (e *Element[T]) Ok() bool

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

func (e *Element[T]) Previous() *Element[T]

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

func (e *Element[T]) Remove() bool

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

func (e *Element[T]) Set(v T) bool

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]) String

func (e *Element[T]) String() string

String returns the string form of the value of the element.

func (*Element[T]) Swap

func (e *Element[T]) Swap(with *Element[T]) bool

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

func (e *Element[T]) UnmarshalJSON(in []byte) error

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.

func (*Element[T]) Value

func (e *Element[T]) Value() T

Value accesses the element's value.

type Heap

type Heap[T any] struct {
	LT cmp.LessThan[T]
	// contains filtered or unexported fields
}

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

func (h *Heap[T]) Iterator() *fun.Iterator[T]

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

func (h *Heap[T]) Len() int

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

func (h *Heap[T]) Pop() (T, bool)

Pop removes the element from the underlying list and returns it, with an Ok value, which is true when the value returned is valid.

func (*Heap[T]) Push

func (h *Heap[T]) Push(t T)

Push adds an item to the heap.

type Item

type Item[T any] struct {
	// contains filtered or unexported fields
}

Item is a common wrapper for the elements in a stack.

func NewItem

func NewItem[T any](in T) *Item[T]

NewItem produces a valid Item object for the specified value.

func (*Item[T]) Append

func (it *Item[T]) Append(n *Item[T]) *Item[T]

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

func (it *Item[T]) Attach(stack *Stack[T]) bool

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

func (it *Item[T]) Detach() *Stack[T]

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

func (it *Item[T]) In(s *Stack[T]) bool

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

func (it *Item[T]) MarshalJSON() ([]byte, error)

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]) Next

func (it *Item[T]) Next() *Item[T]

Next returns the following item in the stack.

func (*Item[T]) Ok

func (it *Item[T]) Ok() bool

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

func (it *Item[T]) Remove() bool

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

func (it *Item[T]) Set(v T) bool

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

func (it *Item[T]) String() string

String implements fmt.Stringer, and returns the string value of the item's value.

func (*Item[T]) UnmarshalJSON

func (it *Item[T]) UnmarshalJSON(in []byte) error

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.

func (*Item[T]) Value

func (it *Item[T]) Value() T

Value returns the Item's underlying value. Use the Ok method to check the validity of the zero values.

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

func NewListFromIterator[T any](ctx context.Context, iter *fun.Iterator[T]) (*List[T], error)

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

func (l *List[T]) Back() *Element[T]

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

func (l *List[T]) Copy() *List[T]

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

func (l *List[T]) Extend(input *List[T])

func (*List[T]) Front

func (l *List[T]) Front() *Element[T]

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

func (l *List[T]) IsSorted(lt cmp.LessThan[T]) bool

IsSorted reports if the list is sorted from low to high, according to the LessThan function.

func (*List[T]) Iterator

func (l *List[T]) Iterator() *fun.Iterator[T]

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

func (l *List[T]) Len() int

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

func (l *List[T]) MarshalJSON() ([]byte, error)

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

func (l *List[T]) PopBack() *Element[T]

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

func (l *List[T]) PopFront() *Element[T]

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

func (l *List[T]) PopIterator() *fun.Iterator[T]

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

func (l *List[T]) PopReverse() *fun.Iterator[T]

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

func (l *List[T]) Populate(iter *fun.Iterator[T]) fun.Worker

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

func (l *List[T]) Producer() fun.Producer[T]

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

func (l *List[T]) ProducerPop() fun.Producer[T]

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

func (l *List[T]) ProducerReverse() fun.Producer[T]

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

func (l *List[T]) ProducerReversePop() fun.Producer[T]

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

func (l *List[T]) Reverse() *fun.Iterator[T]

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]) Slice added in v0.10.3

func (l *List[T]) Slice() Slice[T]

Slice exports the contents of the list to a slice.

func (*List[T]) SortMerge

func (l *List[T]) SortMerge(lt cmp.LessThan[T])

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

func (l *List[T]) SortQuick(lt cmp.LessThan[T])

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

func (l *List[T]) UnmarshalJSON(in []byte) error

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]) AddPair

func (m Map[K, V]) AddPair(p Pair[K, V])

AddPair adds a Pair holding K and V objects to the map.

func (Map[K, V]) AddTuple added in v0.10.5

func (m Map[K, V]) AddTuple(p Tuple[K, V])

AddTuple adds a Tuple of K and V objects to the map.

func (Map[K, V]) Append

func (m Map[K, V]) Append(pairs ...Pair[K, V])

Append adds a sequence of Pair objects to the map.

func (Map[K, V]) Check

func (m Map[K, V]) Check(key K) bool

Check returns true if the value K is in the map.

func (Map[K, V]) ConsumeMap

func (m Map[K, V]) ConsumeMap(in Map[K, V])

ConsumeMap adds all the keys from the input map the map.

func (Map[K, V]) ConsumePairs added in v0.10.5

func (m Map[K, V]) ConsumePairs(pairs *Pairs[K, V])

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

func (m Map[K, V]) ConsumeTuples(tuples *Tuples[K, V])

ConsumeTuples adds items to the map from a Tuples object. Existing values for K are always overwritten.

func (Map[K, V]) ConsumeValues

func (m Map[K, V]) ConsumeValues(iter *fun.Iterator[V], keyf func(V) K) fun.Worker

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]) Extend

func (m Map[K, V]) Extend(pairs *Pairs[K, V])

Extend adds a sequence of Pairs to 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

func (m Map[K, V]) Iterator() *fun.Iterator[Pair[K, V]]

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]) Keys

func (m Map[K, V]) Keys() *fun.Iterator[K]

Keys provides an iterator over just the keys in the map.

func (Map[K, V]) Len

func (m Map[K, V]) Len() int

Len returns the length. It is equivalent to len(Map), but is provided for consistency.

func (Map[K, V]) Load

func (m Map[K, V]) Load(key K) (V, bool)

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]) Pairs

func (m Map[K, V]) Pairs() *Pairs[K, V]

Pairs exports a Pairs object, containing the contents of the map.

func (Map[K, V]) Producer

func (m Map[K, V]) Producer() fun.Producer[Pair[K, V]]

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

func (m Map[K, V]) ProducerKeys() fun.Producer[K]

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

func (m Map[K, V]) ProducerValues() fun.Producer[V]

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.

func (Map[K, V]) Tuples added in v0.10.5

func (m Map[K, V]) Tuples() *Tuples[K, V]

Tupes exports a map a Pairs object, containing the contents of the map.

func (Map[K, V]) Values

func (m Map[K, V]) Values() *fun.Iterator[V]

Values provides an iterator over just the values in the map.

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

func NewOptional[T any](in T) Optional[T]

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

func (o *Optional[T]) DefaultFuture(in fun.Future[T])

DefaultFuture resolves the future if the optional has not yet been set.

func (*Optional[T]) Future added in v0.10.5

func (o *Optional[T]) Future() fun.Future[T]

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

func (o *Optional[T]) Get() (T, bool)

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

func (o *Optional[T]) Handler() fun.Handler[T]

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

func (o Optional[T]) MarshalBinary() ([]byte, error)

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

func (o Optional[T]) MarshalText() ([]byte, error)

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]) Ok added in v0.10.9

func (o Optional[T]) Ok() bool

Ok returns true when the optional

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

func (o *Optional[T]) Scan(src any) (err error)

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

func (o *Optional[T]) SetWhen(cond bool, v T)

Set changes the value of the, only when the boolean cond value is positive.

func (*Optional[T]) SetWhenFuture added in v0.10.5

func (o *Optional[T]) SetWhenFuture(cond bool, v fun.Future[T])

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

func (o *Optional[T]) UnmarshalBinary(in []byte) (err error)

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

func (o *Optional[T]) UnmarshalText(in []byte) (err error)

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.

func (Optional[T]) Value added in v0.10.5

func (o Optional[T]) Value() (driver.Value, error)

Value implements the SQL driver.Valuer interface. Scan implements the sql Scanner interface. This is invalid if the type of the optional value is not a primitive value type.

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

func (p *Pairs[K, V]) Add(k K, v V) *Pairs[K, V]

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]) Append

func (p *Pairs[K, V]) Append(new ...Pair[K, V])

Append as a collection of pairs to the collection of key/value pairs.

func (*Pairs[K, V]) Consume

func (p *Pairs[K, V]) Consume(iter *fun.Iterator[Pair[K, V]]) fun.Worker

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

func (p *Pairs[K, V]) ConsumeValues(iter *fun.Iterator[V], keyf func(V) K) fun.Worker

ConsumeValues adds all of the values in the input iterator, generating the keys using the function provided.

func (*Pairs[K, V]) Copy added in v0.10.3

func (p *Pairs[K, V]) Copy() *Pairs[K, V]

Copy produces a new Pairs object with the same values.

func (*Pairs[K, V]) Extend

func (p *Pairs[K, V]) Extend(toAdd *Pairs[K, V])

Extend adds the items from a Pairs object (slice of Pair) without modifying the donating object.

func (*Pairs[K, V]) Iterator

func (p *Pairs[K, V]) Iterator() *fun.Iterator[Pair[K, V]]

Iterator return an iterator over each key-value pairs.

func (*Pairs[K, V]) Keys

func (p *Pairs[K, V]) Keys() *fun.Iterator[K]

Keys returns an iterator over only the keys in a sequence of iterator items.

func (*Pairs[K, V]) Len

func (p *Pairs[K, V]) Len() int

Len returns the number of items in the pairs object.

func (*Pairs[K, V]) List added in v0.10.2

func (p *Pairs[K, V]) List() *List[Pair[K, V]]

List returns the sequence of pairs as a list.

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

func (p *Pairs[K, V]) MarshalJSON() ([]byte, error)

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

func (p *Pairs[K, V]) Observe(hf fun.Handler[Pair[K, V]])

Observe calls the handler function for every pair in the container.

func (*Pairs[K, V]) Process added in v0.10.3

func (p *Pairs[K, V]) Process(pf fun.Processor[Pair[K, V]]) fun.Worker

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

func (p *Pairs[K, V]) Push(pair Pair[K, V])

Push adds a single pair to the slice of pairs. This may add a duplicate key.

func (*Pairs[K, V]) Slice

func (p *Pairs[K, V]) Slice() []Pair[K, V]

Slice creates a new slice of all the Pair objects.

func (*Pairs[K, V]) SortMerge added in v0.10.2

func (p *Pairs[K, V]) SortMerge(c cmp.LessThan[Pair[K, V]])

SortMerge performs a merge sort on the collected pairs.

func (*Pairs[K, V]) SortQuick added in v0.10.2

func (p *Pairs[K, V]) SortQuick(c cmp.LessThan[Pair[K, V]])

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

func (p *Pairs[K, V]) UnmarshalJSON(in []byte) error

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.

func (*Pairs[K, V]) Values

func (p *Pairs[K, V]) Values() *fun.Iterator[V]

Values returns an iterator over only the values in a sequence of iterator pairs.

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

func (s *Set[T]) AddCheck(in T) (ok bool)

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]) Check

func (s *Set[T]) Check(in T) bool

Check returns true if the item is in 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

func (s *Set[T]) DeleteCheck(in T) bool

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

func (s *Set[T]) Equal(other *Set[T]) bool

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]) Extend added in v0.10.3

func (s *Set[T]) Extend(extra *Set[T])

Extend adds the items of one set to this set.

func (*Set[T]) Iterator

func (s *Set[T]) Iterator() *fun.Iterator[T]

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]) Len

func (s *Set[T]) Len() int

Len returns the number of items tracked in the set.

func (*Set[T]) MarshalJSON

func (s *Set[T]) MarshalJSON() ([]byte, error)

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]) Populate

func (s *Set[T]) Populate(iter *fun.Iterator[T])

Populate adds all items encountered in the iterator to the set.

func (*Set[T]) Producer

func (s *Set[T]) Producer() (out fun.Producer[T])

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

func (s *Set[T]) SortMerge(lt cmp.LessThan[T])

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

func (s *Set[T]) SortQuick(lt cmp.LessThan[T])

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

func (s *Set[T]) UnmarshalJSON(in []byte) error

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.

func (*Set[T]) WithLock

func (s *Set[T]) WithLock(mtx *sync.Mutex)

WithLock configures the Set to synchronize operations with this mutex. If the mutex is nil, or the Set is already synchronized with a different mutex, WithLock panics with an invariant violation.

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

func DefaultSlice[T any](input []T, args ...int) Slice[T]

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

func MergeSlices[T any](sls ...[]T) Slice[T]

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

func NewSlice[T any](in []T) Slice[T]

NewSlice produces a slice object as a convenience constructor to avoid needing to specify types.

func SlicePtrs added in v0.10.4

func SlicePtrs[T any](in []T) Slice[*T]

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

func SliceRefs[T any](in []*T) Slice[T]

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

func SliceSparseRefs[T any](in []*T) Slice[T]

SliceRefs converts a slice of pointers to a slice of objects, dropping nil values. from the output slice.

func Sliceify deprecated

func Sliceify[T any](in []T) Slice[T]

Sliceify produces a slice object as a convenience constructor to avoid needing to specify types.

Deprecated: use NewSlice for this case.

func Variadic

func Variadic[T any](in ...T) Slice[T]

Variadic constructs a slice of type T from a sequence of variadic options.

func (*Slice[T]) Add

func (s *Slice[T]) Add(in T)

Add adds a single item to the end of the slice.

func (*Slice[T]) AddWhen

func (s *Slice[T]) AddWhen(cond bool, in T)

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

func (s *Slice[T]) AppendWhen(cond bool, in ...T)

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]) Cap

func (s Slice[T]) Cap() int

Cap returns the capacity of the slice.

func (Slice[T]) Copy

func (s Slice[T]) Copy() Slice[T]

Copy performs a shallow copy 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]) ExtendWhen

func (s *Slice[T]) ExtendWhen(cond bool, in []T)

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

func (s Slice[T]) FillTo(length int) Slice[T]

FillTo appends zero values to the slice until it reaches the specified length, and returns the resulting slice.

func (*Slice[T]) Filter

func (s *Slice[T]) Filter(p func(T) bool) (o Slice[T])

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

func (s *Slice[T]) FilterFuture(p func(T) bool) fun.Future[Slice[T]]

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

func (s *Slice[T]) Grow(size int)

Grow adds zero items to the slice until it reaches the desired size.

func (*Slice[T]) GrowCapacity added in v0.10.5

func (s *Slice[T]) GrowCapacity(size int)

GrowCapacity extends the capacity of the slice (by adding zero items and the )

func (Slice[T]) Index added in v0.10.4

func (s Slice[T]) Index(index int) T

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]) IsEmpty

func (s Slice[T]) IsEmpty() bool

IsEmpty returns true when there are no items in the slice (or it is nil.

func (Slice[T]) Iterator

func (s Slice[T]) Iterator() *fun.Iterator[T]

Iterator returns an iterator to the items of the slice the range keyword also works for these slices.

func (Slice[T]) Last

func (s Slice[T]) Last() int

Last returns the index of the last element in the slice. Empty slices have `-1` last items.

func (Slice[T]) Len

func (s Slice[T]) Len() int

Len returns the length of the slice.

func (Slice[T]) Observe

func (s Slice[T]) Observe(of fun.Handler[T])

Observe calls the observer function on every item in the slice.

func (*Slice[T]) Populate added in v0.10.3

func (s *Slice[T]) Populate(iter *fun.Iterator[T]) fun.Worker

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

func (s Slice[T]) Process(pf fun.Processor[T]) fun.Worker

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]) Ptr added in v0.10.2

func (s Slice[T]) Ptr(index int) *T

Ptr provides a pointer to the item at the provided index.

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

func (s *Slice[T]) Reslice(start, end int)

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

func (s *Slice[T]) ResliceBeginning(start int)

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

func (s *Slice[T]) ResliceEnd(end int)

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

func (s Slice[T]) Sort(cp func(a, b T) bool)

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

func (s Slice[T]) Sparse() Slice[T]

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

func (s *Slice[T]) Truncate(n int)

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.

func (Slice[T]) Zero added in v0.10.5

func (s Slice[T]) Zero()

Zero replaces all items in the slice with the zero value for the type T.

func (Slice[T]) ZeroRange added in v0.10.5

func (s Slice[T]) ZeroRange(start, end int)

ZeroRange replaces values between the specified indexes (inclusive) with the zero value of the type. If the indexes provided are outside of the bounds of the slice, an invariant violation panic is raised.

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

func NewStackFromIterator[T any](ctx context.Context, iter *fun.Iterator[T]) (*Stack[T], error)

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

func (s *Stack[T]) Head() *Item[T]

Head returns the item at the top of this stack. This is a non destructive operation.

func (*Stack[T]) Iterator

func (s *Stack[T]) Iterator() *fun.Iterator[T]

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

func (s *Stack[T]) Len() int

Len returns the length of the stack. Because stack's track their own size, this is an O(1) operation.

func (*Stack[T]) MarshalJSON

func (s *Stack[T]) MarshalJSON() ([]byte, error)

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

func (s *Stack[T]) Pop() *Item[T]

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

func (s *Stack[T]) PopIterator() *fun.Iterator[T]

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

func (s *Stack[T]) Populate(iter *fun.Iterator[T]) fun.Worker

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]) Producer

func (s *Stack[T]) Producer() fun.Producer[T]

func (*Stack[T]) ProducerPop

func (s *Stack[T]) ProducerPop() fun.Producer[T]

func (*Stack[T]) Push

func (s *Stack[T]) Push(it T)

Push appends an item to the stack.

func (*Stack[T]) UnmarshalJSON

func (s *Stack[T]) UnmarshalJSON(in []byte) error

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

type Tuple[K any, V any] struct {
	One K
	Two V
}

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

func MakeTuple[K any, V any](k K, v V) Tuple[K, V]

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 (t Tuple[K, V]) MarshalJSON() ([]byte, error)

func (*Tuple[K, V]) UnmarshalJSON added in v0.10.5

func (t *Tuple[K, V]) UnmarshalJSON(in []byte) error

type Tuples added in v0.10.5

type Tuples[K any, V any] struct {
	// contains filtered or unexported fields
}

Tuples implements a collection of key-value tuples.

func MakeTuples added in v0.10.5

func MakeTuples[K any, V any](in ...Tuple[K, V]) *Tuples[K, V]

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

func (p *Tuples[K, V]) Add(k K, v V) *Tuples[K, V]

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

func (p *Tuples[K, V]) Append(new ...Tuple[K, V])

Append as a collection of tuples to the collection of key/value tuples.

func (*Tuples[K, V]) Consume added in v0.10.5

func (p *Tuples[K, V]) Consume(iter *fun.Iterator[Tuple[K, V]]) fun.Worker

Consume adds items from an iterator of tuples to the current Tuples slice.

func (*Tuples[K, V]) Copy added in v0.10.5

func (p *Tuples[K, V]) Copy() *Tuples[K, V]

Copy produces a new Tuples object with the same values.

func (*Tuples[K, V]) Extend added in v0.10.5

func (p *Tuples[K, V]) Extend(toAdd *Tuples[K, V])

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

func (p *Tuples[K, V]) Iterator() *fun.Iterator[Tuple[K, V]]

Iterator return an iterator over each key-value tuples.

func (*Tuples[K, V]) Len added in v0.10.5

func (p *Tuples[K, V]) Len() int

Len returns the number of items in the tuples object.

func (*Tuples[K, V]) List added in v0.10.5

func (p *Tuples[K, V]) List() *List[Tuple[K, V]]

List returns the sequence of tuples as a list.

func (*Tuples[K, V]) MarshalJSON added in v0.10.5

func (p *Tuples[K, V]) MarshalJSON() ([]byte, error)

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

func (p *Tuples[K, V]) Observe(hf fun.Handler[Tuple[K, V]])

Observe calls the handler function for every tuple in the container.

func (*Tuples[K, V]) Ones added in v0.10.5

func (p *Tuples[K, V]) Ones() *fun.Iterator[K]

Ones returns an iterator over only the keys in a sequence of iterator items.

func (*Tuples[K, V]) Process added in v0.10.5

func (p *Tuples[K, V]) Process(pf fun.Processor[Tuple[K, V]]) fun.Worker

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

func (p *Tuples[K, V]) Push(tuple Tuple[K, V])

Push adds a single tuple to the slice of tuples. This may add a duplicate key.

func (*Tuples[K, V]) Slice added in v0.10.5

func (p *Tuples[K, V]) Slice() []Tuple[K, V]

Slice creates a new slice of all the Tuple objects.

func (*Tuples[K, V]) SortMerge added in v0.10.5

func (p *Tuples[K, V]) SortMerge(c cmp.LessThan[Tuple[K, V]])

SortMerge performs a merge sort on the collected tuples.

func (*Tuples[K, V]) SortQuick added in v0.10.5

func (p *Tuples[K, V]) SortQuick(c cmp.LessThan[Tuple[K, V]])

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

func (p *Tuples[K, V]) Twos() *fun.Iterator[V]

Twos returns an iterator over only the values in a sequence of iterator tuples.

func (*Tuples[K, V]) UnmarshalJSON added in v0.10.5

func (p *Tuples[K, V]) UnmarshalJSON(in []byte) error

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL