Documentation ¶
Overview ¶
Utils to complement the standard library.
Index ¶
- func AppendSliceCopy[T any](immutable []T, suffix ...T) []T
- func AtomicExtrema[Base any](ptr Atomic[Base], other Base, rightIsBetter func(Base, Base) bool) (_stored bool)
- func AtomicMax[Base constraints.Ordered](ptr Atomic[Base], other Base) (_stored bool)
- func AtomicMin[Base constraints.Ordered](ptr Atomic[Base], other Base) (_stored bool)
- func ClearSlice[T any](slice *[]T)
- func ClosedChan[T any]() <-chan T
- func ContextWithStopCh(ctx context.Context, ch <-chan Empty) context.Context
- func CountSlice[T any](input []T, predicate func(T) bool) int
- func DrainSliceOrdered[T any](slice *[]T, predicate func(T) bool)
- func DrainSliceUnordered[T any](slice *[]T, predicate func(T) bool)
- func FindInSlice[T comparable](input []T, needle T) int
- func FindInSliceWith[T any](input []T, predicate func(T) bool) int
- func ForEachRef[T any](slice []T, eachFn func(*T))
- func GetArbitraryMapEntry[K comparable, V any](map_ map[K]V) (K, V, bool)
- func GetOrAppend[T any](slice *[]T, predicate func(*T) bool) *T
- func GetOrAppendSliceWith[T any](slice *[]T, predicate func(*T) bool, ctor func() T) *T
- func Identity[T any](t T) T
- func IsZero[T comparable](value T) bool
- func MapSlice[T any, U any](input []T, fn func(T) U) []U
- func NewLateInit[T any]() (_reader LateInitReader[T], _writer LateInitWriter[T])
- func NoOp()
- func NotifyOnBlock[T any](blockNotifier BlockNotifier, ch <-chan T) (T, bool)
- func RoundedIntDiv[T constraints.Integer](numerator, divisor T) T
- func SelectOrNotifyRR[T1, T2 any, R any](blockNotifier BlockNotifier, ch1 <-chan T1, then1 func(T1, bool) R, ...) R
- func SelectOrNotifyRRR[T1, T2, T3 any, R any](blockNotifier BlockNotifier, ch1 <-chan T1, then1 func(T1, bool) R, ...) R
- func SliceContains[T comparable](input []T, needle T) bool
- func SliceToMap[K comparable, V any](input []V, keyFn func(V) K) map[K]V
- func SwapRemove[T any](input *[]T, i int)
- func Type[T any]() reflect.Type
- func TypeName[T any]() string
- func Zero[T any]() T
- type Atomic
- type BlockNotifier
- type Empty
- type LateInitReader
- type LateInitWriter
- type TryRecvResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendSliceCopy ¶
func AppendSliceCopy[T any](immutable []T, suffix ...T) []T
Similar to append(), but always reallocates exactly one new slice, and never mutates the buffer behind `immutable` even if there is remaining capacity.
func AtomicExtrema ¶
func AtomicMax ¶
func AtomicMax[Base constraints.Ordered](ptr Atomic[Base], other Base) (_stored bool)
func AtomicMin ¶
func AtomicMin[Base constraints.Ordered](ptr Atomic[Base], other Base) (_stored bool)
func ClearSlice ¶
func ClearSlice[T any](slice *[]T)
Clears the slice without deallocating its capacity, freeing any possible underlying pointers for GC.
func ClosedChan ¶
func ClosedChan[T any]() <-chan T
func ContextWithStopCh ¶
func CountSlice ¶
func DrainSliceOrdered ¶
Removes items in the slice that do not match the predicate, preserving order of other items.
func DrainSliceUnordered ¶
Swap-removes items in the slice that do not match the predicate.
func FindInSlice ¶
func FindInSlice[T comparable](input []T, needle T) int
Returns the first occurrence of needle in input, or -1 if not found.
func FindInSliceWith ¶
Returns the first occurrence in input where predicate returns true, or -1 if not found.
func ForEachRef ¶
func ForEachRef[T any](slice []T, eachFn func(*T))
Execute `eachFn` on each item of `slice` by reference.
func GetArbitraryMapEntry ¶
func GetArbitraryMapEntry[K comparable, V any](map_ map[K]V) (K, V, bool)
Returns an arbitrary map entry and true, or zero KV and false if the map is empty.
func GetOrAppend ¶
Returns a pointer to a slice entry satisfying the condition, appending a new zero entry if none satisfies.
func GetOrAppendSliceWith ¶
Similar to GetOrAppend, but appends an entry from the ctor function.
func IsZero ¶
func IsZero[T comparable](value T) bool
func NewLateInit ¶
func NewLateInit[T any]() (_reader LateInitReader[T], _writer LateInitWriter[T])
func NotifyOnBlock ¶
func NotifyOnBlock[T any](blockNotifier BlockNotifier, ch <-chan T) (T, bool)
Receives a value from `ch`. If this was a blocking operation, also calls the OnBlock/OnUnblock hooks on `blockNotifier`.
func RoundedIntDiv ¶
func RoundedIntDiv[T constraints.Integer](numerator, divisor T) T
Returns the nearest integer to {numerator / divisor} with half-positive rounding.
func SelectOrNotifyRR ¶
func SelectOrNotifyRR[T1, T2 any, R any]( blockNotifier BlockNotifier, ch1 <-chan T1, then1 func(T1, bool) R, ch2 <-chan T2, then2 func(T2, bool) R, ) R
Select-recvs from one of the channels, and call the specified function if it blocks (all channels have no data).
func SelectOrNotifyRRR ¶
func SelectOrNotifyRRR[T1, T2, T3 any, R any]( blockNotifier BlockNotifier, ch1 <-chan T1, then1 func(T1, bool) R, ch2 <-chan T2, then2 func(T2, bool) R, ch3 <-chan T3, then3 func(T3, bool) R, ) R
Select-recvs from one of the channels, and call the specified function if it blocks (all channels have no data).
func SliceContains ¶
func SliceContains[T comparable](input []T, needle T) bool
func SliceToMap ¶
func SliceToMap[K comparable, V any](input []V, keyFn func(V) K) map[K]V
func SwapRemove ¶
Removes the item at index i from input, moving the last item to its original position.
Types ¶
type BlockNotifier ¶
type BlockNotifier interface { OnBlock() OnUnblock() }
type LateInitReader ¶
type LateInitReader[T any] struct { // contains filtered or unexported fields }
func (LateInitReader[T]) Get ¶
func (reader LateInitReader[T]) Get() T
type LateInitWriter ¶
type LateInitWriter[T any] func(T)
type TryRecvResult ¶
func TryRecv ¶
func TryRecv[T any](ch <-chan T) TryRecvResult[T]