tsslice

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: LGPL-2.1 Imports: 2 Imported by: 0

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

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.

func Set

func Set[S ~[]E, E any](mux threadsafe.Locker, s S, k int, v E)

Set is a thread-safe function to assign a value v to a key k in a slice s.

Types

This section is empty.

Jump to

Keyboard shortcuts

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