common

package
v0.0.0-...-bcd5820 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddKeysToMap

func AddKeysToMap[T comparable](m map[T]any, items ...T)

func Apply

func Apply[T any, K any](items []T, f func(in T) K) []K

func ChainErr

func ChainErr(err1 error, err2 error) error

TODO - there should be some build in mechanism for this. E.g. there is errros.Unwrap. Can we use that without this method?

func Filter

func Filter[T any](records []T, predicate func(item T) bool) (ret []T)

func Keys

func Keys[K comparable, V any](m map[K]V) []K

func MaxInt

func MaxInt(a, b int) int

func MaxUInt32

func MaxUInt32(a, b uint32) uint32

func MergeInto

func MergeInto[T comparable, V any](m1 map[T]V, m2 map[T]V)

func MinInt

func MinInt(a, b int) int

func MinUInt32

func MinUInt32(a, b uint32) uint32

func Must

func Must[T any](obj T, err error) T

func ReadCsvFile

func ReadCsvFile(filePath string) ([][]string, error)

func SplitNoEmpty

func SplitNoEmpty(s string, sep string) []string

func ToMap

func ToMap[T comparable](items ...T) map[T]any

func Values

func Values[K comparable, V any](m map[K]V) []V

Types

type CompSet

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

func NewCompSet

func NewCompSet[T comparable](items ...T) CompSet[T]

NewCompSet initializes a new set

func (CompSet[T]) Add

func (set CompSet[T]) Add(items ...T)

Add adds the items one or more to the set.

func (CompSet[T]) Any

func (set CompSet[T]) Any() bool

Any returns true if this set contains any item.

func (CompSet[T]) Contains

func (set CompSet[T]) Contains(item T) bool

Contains returns true if the item is contained in the set. Equality is determined using the hashCode() and equals() functions.

func (CompSet[T]) Items

func (set CompSet[T]) Items() (res []T)

Items returns the all items in the set in a slice

func (CompSet[T]) Len

func (set CompSet[T]) Len() int

Len returns the number of items in the set.

func (CompSet[T]) MarshalJSON

func (set CompSet[T]) MarshalJSON() ([]byte, error)

MarshalJSON converts the set to an array-like json representation

func (*CompSet[T]) UnmarshalJSON

func (set *CompSet[T]) UnmarshalJSON(bytes []byte) error

UnmarshalJSON initializes a set from an array-like json representation

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func Background

func Background() Context

func WithCancel

func WithCancel(parent Context) (Context, context.CancelFunc)

func WithTimeout

func WithTimeout(parent Context, timeout time.Duration) (Context, context.CancelFunc)

func Wrap

func Wrap(ctx context.Context) Context

func (Context) Errgroup

func (c Context) Errgroup() (Group, Context)

func (Context) Go

func (c Context) Go(f func())

func (Context) OnDone

func (c Context) OnDone(f func())

func (Context) WithDefer

func (c Context) WithDefer(d func()) Context

type Group

type Group struct {
	*errgroup.Group
	// contains filtered or unexported fields
}

func (Group) Go

func (g Group) Go(f func() error)

Jump to

Keyboard shortcuts

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