Documentation ¶
Overview ¶
Package tsslice provides a collection of generic thread-safe slice utility functions that can be safely used between multiple goroutines.
The provided functions are intended to simplify the process of working with slices in a thread-safe manner.
Index ¶
- func Append[S ~[]E, E any](mux threadsafe.Locker, s *S, v ...E)
- func Filter[S ~[]E, E any](mux threadsafe.RLocker, s S, f func(int, E) bool) S
- func Get[S ~[]E, E any](mux threadsafe.RLocker, s S, k int) E
- func Len[S ~[]E, E any](mux threadsafe.RLocker, s S) int
- func Map[S ~[]E, E any, U any](mux threadsafe.RLocker, s S, f func(int, E) U) []U
- func Reduce[S ~[]E, E any, U any](mux threadsafe.RLocker, s S, init U, f func(int, E, U) U) U
- func Set[S ~[]E, E any](mux threadsafe.Locker, s S, k int, v E)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
func Append[S ~[]E, E any](mux threadsafe.Locker, s *S, v ...E)
Append is a thread-safe version of the Go built-in append function. Appends the value v to the slice s.
func Filter ¶
func Filter[S ~[]E, E any](mux threadsafe.RLocker, s S, f func(int, E) bool) S
Filter is a thread-safe function that returns a new slice containing only the elements in the input slice s for which the specified function f is true.
func Get ¶
func Get[S ~[]E, E any](mux threadsafe.RLocker, s S, k int) E
Get is a thread-safe function to get a value by key k in a slice.
func Len ¶
func Len[S ~[]E, E any](mux threadsafe.RLocker, s S) int
Len is a thread-safe function to get the length of a slice.
func Map ¶
func Map[S ~[]E, E any, U any](mux threadsafe.RLocker, s S, f func(int, E) U) []U
Map is a thread-safe function that returns a new slice that contains each of the elements of the input slice s mutated by the specified function.
func Reduce ¶
func Reduce[S ~[]E, E any, U any](mux threadsafe.RLocker, s S, init U, f func(int, E, U) U) U
Reduce is a thread-safe function that applies the reducing function f to each element of the input slice s, and returns the value of the last call to f. The first parameter of the reducing function f is initialized with init.
Types ¶
This section is empty.