go_tools

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransformArray

func TransformArray[T, U any](arr []T, f func(T) U) []U

func TransformMaybeArray

func TransformMaybeArray[T, U any](arr []T, f func(T) (U, bool)) []U

Types

type Cache

type Cache[T any] interface {
	// Get returns the object stored in the cache with the given key.
	// If the object has expired, it will be removed from the cache and nil will be returned.
	Get(key string) CacheObject[T]
	Set(key string, obj T)
	Clear()
}

func NewCache

func NewCache[T any](expiry ...time.Duration) Cache[T]

type CacheObject

type CacheObject[T any] interface {
	Get() T
	Expired() bool
	Insert() time.Time
}

type MutablePair

type MutablePair[L, R any] interface {
	Pair[L, R]
	SetLeft(L)
	SetRight(R)
}

func NewMutablePair

func NewMutablePair[L, R any](left L, right R) MutablePair[L, R]

type Pair

type Pair[L, R any] interface {
	Left() L
	Right() R
}

func NewPair

func NewPair[L, R any](left L, right R) Pair[L, R]

type Queue

type Queue[T comparable] interface {
	Enqueue(item T)
	Dequeue() (*T, error)
	IsEmpty() bool
	Size() int
	Items() []T
	RemoveFunc(func(T) bool) bool
}

func NewQueue

func NewQueue[T comparable]() Queue[T]

type SafeDoubleMap

type SafeDoubleMap[K, V comparable] interface {
	SafeMap[K, V]
	RemoveByValue(V)
}

func NewSafeDoubleMap

func NewSafeDoubleMap[K, V comparable](m ...map[K]V) SafeDoubleMap[K, V]

type SafeMap

type SafeMap[K comparable, V any] interface {
	Get(K) (V, bool)
	Put(K, V)
	Remove(K)

	Contains(K) bool
	Keys() []K
	Values() []V
	Size() int
	Copy() map[K]V

	// ForEach iterates over the map and calls the given function for each key-value pair.
	// The order of iteration is not guaranteed. If the function returns false, the iteration stops.
	//
	// As the map is read-locked during the iteration, the function should not call any method that modifies the map.
	ForEach(func(K, V) bool)
}

func NewSafeMap

func NewSafeMap[K comparable, V any](m ...map[K]V) SafeMap[K, V]

Jump to

Keyboard shortcuts

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