util

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InverseMap

func InverseMap[K, V comparable](d map[K]V) (map[V]K, error)

func MustInverseMap

func MustInverseMap[K, V comparable](d map[K]V) map[V]K

func OpenAndParse

func OpenAndParse[T any](file string, f func([]byte) (T, error)) (T, error)

func ParseUint

func ParseUint(s string) (uint, error)

func Ptr

func Ptr[T any](t T) *T

func ReadAndParse

func ReadAndParse[T any](r io.ReadCloser, f func([]byte) (T, error)) (T, error)

Types

type Opt

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

func NewOpt

func NewOpt[T any](v T) *Opt[T]

func (Opt[T]) Unwrap

func (p Opt[T]) Unwrap() T

func (*Opt[T]) Update

func (p *Opt[T]) Update(v T)

func (*Opt[T]) WhenUpdated

func (p *Opt[T]) WhenUpdated(f func(v T))

WhenUpdated calls f the first time this is called after being Update() or NewOpt().

type Rat

type Rat struct {
	Num   uint
	Denom uint
}

func NewRat

func NewRat(num, denom uint) Rat

func ParseRat

func ParseRat(s string) (Rat, error)

func (Rat) Float

func (r Rat) Float() float64

func (Rat) MarshalYAML

func (r Rat) MarshalYAML() (any, error)

func (Rat) String

func (r Rat) String() string

func (*Rat) UnmarshalYAML

func (r *Rat) UnmarshalYAML(value *yaml.Node) error

type Ring

type Ring[T any] []T

func MustNewRing

func MustNewRing[T any](v ...T) Ring[T]

func NewRing

func NewRing[T any](v ...T) (Ring[T], error)

NewRing returns a new ring buffer.

func (Ring[T]) All

func (r Ring[T]) All() iter.Seq[T]

func (Ring[T]) At

func (r Ring[T]) At(i int) T

func (Ring[T]) Len

func (r Ring[T]) Len() int

type Set

type Set[T comparable] map[T]bool

func NewSet

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

func (Set[T]) All

func (s Set[T]) All() iter.Seq[T]

func (Set[T]) In

func (s Set[T]) In(v T) bool

func (Set[T]) Len

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

Jump to

Keyboard shortcuts

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