utils

package
v0.1.16-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyMap

func CopyMap[K comparable, T any](orig map[K]T, usePointerCopier ...bool) map[K]T

func CopyPointer

func CopyPointer[T any](orig *T, usePointerCopier ...bool) *T

func CopySlice

func CopySlice[T any](orig []T, usePointerCopier ...bool) []T

func RunParallel

func RunParallel(tasks ...func())

func SliceOf

func SliceOf[A any, B any](orig []A) (dst []B)

Types

type CustomMutex

type CustomMutex interface {
	Lock(ctx context.Context) error
	Unlock()
	TryLock(ctx context.Context) bool
	TryUnlock() bool
}

func NewMutex

func NewMutex() CustomMutex

type DeepCopier

type DeepCopier[T any] interface {
	Copy() *T
}

type LimitedSafeMap

type LimitedSafeMap[K comparable, T any] interface {
	SafeMap[K, T]

	Sorted() []T
}

func NewLimitedSafeMap

func NewLimitedSafeMap[K comparable, T any](limit int, sortBy LimitedSafeMapOrderBy[T]) LimitedSafeMap[K, T]

type LimitedSafeMapOrderBy

type LimitedSafeMapOrderBy[T any] func(a, b T) bool

type Nullable

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

func (*Nullable[T]) Clear

func (n *Nullable[T]) Clear()

func (Nullable[T]) Get

func (n Nullable[T]) Get() (v T)

func (Nullable[T]) MarshalJSON

func (n Nullable[T]) MarshalJSON() ([]byte, error)

func (*Nullable[T]) Set

func (n *Nullable[T]) Set(v T)

func (*Nullable[T]) UnmarshalJSON

func (n *Nullable[T]) UnmarshalJSON(data []byte) error

func (Nullable[T]) Valid

func (n Nullable[T]) Valid() bool

type RWLocker

type RWLocker interface {
	sync.Locker
	RLock()
	RUnlock()
}

type SafeMap

type SafeMap[K comparable, T any] interface {
	Get(key K) (T, bool)
	Delete(key K) bool
	Has(key K) bool
	Set(key K, value T)
	Size() int

	Find(fn SafeMapLambda[T]) (T, bool)
	Search(fn SafeMapLambda[T]) (values []T)
	Each(fn SafeMapLambda[T])
}

func NewSafeMap

func NewSafeMap[K comparable, T any]() SafeMap[K, T]

type SafeMapEmbedded

type SafeMapEmbedded[K comparable, T any] interface {
	Get(key K) T
	Delete(key K) (ok bool)
	Each(fn SafeMapLambda[T])
	Size() int
}

func NewSafeMapEmbedded

func NewSafeMapEmbedded[K comparable, T any](gen SafeMapGenerator[T]) SafeMapEmbedded[K, T]

type SafeMapGenerator

type SafeMapGenerator[T any] func() T

type SafeMapLambda

type SafeMapLambda[T any] func(obj T) bool

type SafeSlice

type SafeSlice[T any] interface {
	json.Marshaler
	json.Unmarshaler

	Read() []T
	Remove(i int)
	Size() int
	Get(i int) T
	Set(i int, v T)
	Add(T)
	Index(fn SafeSliceIndex[T]) int
	Lock() (unlock SafeSliceUnlock)
	Replace([]T)
}

func NewSafeSlice

func NewSafeSlice[T any]() SafeSlice[T]

type SafeSliceIndex

type SafeSliceIndex[T any] func(v T) bool

type SafeSliceUnlock

type SafeSliceUnlock func()

type SimpleMap

type SimpleMap[K comparable, T any] interface {
	Set(key K, value T)
	Delete(key K) (ok bool)
	Get(key K) (value T, ok bool)
	Size() int
	Each(fn func(key K, value T))
}

func NewSimpleMap

func NewSimpleMap[K comparable, T any]() SimpleMap[K, T]

Jump to

Keyboard shortcuts

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