nimble

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 6 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(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(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 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 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 (*Set[T]) Add

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

Add adds a single value to the set

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

Jump to

Keyboard shortcuts

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