nimble

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 9 Imported by: 3

README

nimble

Data structures and functional programming tools using generics, along with a few extra useful helpers.

See unit tests for usage patterns

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[T any](f func(index int, v T) bool, values ...T) []T

Filter returns the filtered items from the input set, using the filter function

func Map

func Map[T any, U any](f func(index int, v T) U, values ...T) []U

Map returns the original slice passed through the mapping function

func Or added in v0.1.4

func Or[T comparable](value T, orValue T) T

Or returns the orValue when value is the zero value for a given type

func Retry added in v0.2.0

func Retry(config *RetryConfig, executor func() error) error

Retry will execute the provided executor function multiple times with an interim delay, reporting the final error status in the event of a terminal failure

func SigFigDur added in v0.1.2

func SigFigDur(t time.Duration, sigFigs int) string

SigFigDur renders duration to a fixed number of significant figures, independent of the unit of measure.

func Unique

func Unique[T comparable](values ...T) []T

Unique returns a slice from the original containing only unique elements

Types

type IndexedDequeIterator added in v0.6.1

type IndexedDequeIterator struct {
	// contains filtered or unexported fields
}

func (*IndexedDequeIterator) Next added in v0.6.1

func (iqi *IndexedDequeIterator) Next() bool

func (*IndexedDequeIterator) ReverseNext added in v0.6.1

func (iqi *IndexedDequeIterator) ReverseNext() bool

func (*IndexedDequeIterator) Value added in v0.6.1

func (iqi *IndexedDequeIterator) Value() string

type IndexedDequeue added in v0.6.0

type IndexedDequeue struct {
	// contains filtered or unexported fields
}

func NewIndexedDequeue added in v0.6.0

func NewIndexedDequeue(items ...string) *IndexedDequeue

NewIndexedDequeue creates an indexed deque, whereby items can be accessed in constant time from the head or tail, and arbitrary items can be accessed in near constant time using a string lookup, where lookup time varies slightly by the number of matching candidates. pop => prev(nil) <-- tail <-- prev next --> head --> next(nil) <= push

func (*IndexedDequeue) Find added in v0.6.0

func (iq *IndexedDequeue) Find(pattern string) []*IndexedDequeueLink

func (*IndexedDequeue) GetIter added in v0.6.1

func (iq *IndexedDequeue) GetIter() *IndexedDequeIterator

GetIter returns an iterator

func (*IndexedDequeue) Pop added in v0.6.0

func (iq *IndexedDequeue) Pop() string

func (*IndexedDequeue) Push added in v0.6.0

func (iq *IndexedDequeue) Push(value string)

func (*IndexedDequeue) RemoveItem added in v0.6.0

func (iq *IndexedDequeue) RemoveItem(links ...*IndexedDequeueLink)

func (*IndexedDequeue) Size added in v0.6.0

func (iq *IndexedDequeue) Size() int
type IndexedDequeueLink struct {
	CreatedAt time.Time
	Value     string
	// contains filtered or unexported fields
}
type Link[K comparable, V any] struct {
	Key   K
	Value V
	Next  *Link[K, V]
	Prev  *Link[K, V]
}

type OrderedMap added in v0.4.0

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

func NewOrderedMap added in v0.4.0

func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]

func (*OrderedMap[K, V]) Delete added in v0.4.0

func (om *OrderedMap[K, V]) Delete(key K)

func (*OrderedMap[K, V]) Get added in v0.4.0

func (om *OrderedMap[K, V]) Get(key K) (V, bool)

func (*OrderedMap[K, V]) GetIter added in v0.4.0

func (om *OrderedMap[K, V]) GetIter() *OrderedMapIter[K, V]

GetIter returns an iterator which allows for forward or reverse iteration through the key/value pairs as they were added to the collection

func (*OrderedMap[K, V]) Length added in v0.4.0

func (om *OrderedMap[K, V]) Length() int

func (*OrderedMap[K, V]) Put added in v0.4.0

func (om *OrderedMap[K, V]) Put(key K, value V)

type OrderedMapIter added in v0.5.0

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

func (*OrderedMapIter[K, V]) Key added in v0.5.0

func (i *OrderedMapIter[K, V]) Key() K

func (*OrderedMapIter[K, V]) Next added in v0.5.0

func (i *OrderedMapIter[K, V]) Next() bool

Next advances to the next position in the iterator. This must be called before the iterator's Key() or Value() functions can be consumed. This lends well to using Next() in a for loop

func (*OrderedMapIter[K, V]) ReverseNext added in v0.5.0

func (i *OrderedMapIter[K, V]) ReverseNext() bool

ReverseNext advances to the next position in the iterator, starting from the end going to the beginning. This must be called before the iterator's Key() or Value() functions can be consumed. This lends well to using ReverseNext() in a for loop

func (*OrderedMapIter[K, V]) Value added in v0.5.0

func (i *OrderedMapIter[K, V]) Value() V

type RetryConfig added in v0.2.0

type RetryConfig struct {
	NumAttempts         int
	DelayBetweenRetries time.Duration
	LogEnabled          bool
	LogOperationName    string
}

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func Intersect added in v0.3.1

func Intersect[T comparable](set ...*Set[T]) *Set[T]

Intersect returns the intersection of all provided sets

func NewSet

func NewSet[T comparable](values ...T) *Set[T]

NewSet creates a new set, initialized with values

func NewSetFromMap added in v0.2.0

func NewSetFromMap[T comparable, X any](values map[T]X) *Set[T]

func Union added in v0.3.1

func Union[T comparable](set ...*Set[T]) *Set[T]

Union returns a new set that is a union of the members of the provided sets

func (*Set[T]) Add

func (s *Set[T]) Add(values ...T)

Add adds a single value to the set

func (*Set[T]) Copy added in v0.3.3

func (s *Set[T]) Copy() *Set[T]

Copy makes a shallow copy of the current set and returns it

func (*Set[T]) Difference added in v0.3.1

func (s *Set[T]) Difference(set ...*Set[T]) *Set[T]

func (*Set[T]) Has

func (s *Set[T]) Has(value T) bool

Has returns true if the set already contains the provided value

func (*Set[T]) Intersect added in v0.3.1

func (s *Set[T]) Intersect(set *Set[T]) *Set[T]

func (*Set[T]) Items added in v0.1.1

func (s *Set[T]) Items() []T

Items returns a slice of the items in the set

func (*Set[T]) Pop added in v0.3.2

func (s *Set[T]) Pop() any

Pop removes and returns an arbitrary item from the set

func (*Set[T]) Remove

func (s *Set[T]) Remove(value T)

Remove removes the specified item from the set

func (*Set[T]) Size

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

Size returns the size of the set

type SortedList added in v0.5.0

type SortedList[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

func NewSortedList added in v0.5.0

func NewSortedList[T cmp.Ordered](items ...T) *SortedList[T]

NewSortedList constructs a sorted list. A sorted list maintains order upon every added item, making it ideal for accesing the smallest and largest items at any given time.

func (*SortedList[T]) Extend added in v0.5.0

func (l *SortedList[T]) Extend(items ...T)

func (*SortedList[T]) Get added in v0.5.0

func (l *SortedList[T]) Get(index int) T

func (*SortedList[T]) Largest added in v0.5.0

func (l *SortedList[T]) Largest() T

func (*SortedList[T]) Length added in v0.5.0

func (l *SortedList[T]) Length() int

func (*SortedList[T]) PopLargest added in v0.5.0

func (l *SortedList[T]) PopLargest() T

func (*SortedList[T]) PopSmallest added in v0.5.0

func (l *SortedList[T]) PopSmallest() T

func (*SortedList[T]) Smallest added in v0.5.0

func (l *SortedList[T]) Smallest() T

Jump to

Keyboard shortcuts

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