nimble

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 5 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 comparable](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 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 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 (*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