slices

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk added in v2.1.0

func Chunk[T any](slice []T, chunkSize int) [][]T

Chunk helps chunk a slice into equal size

Types

type Item

type Item[T any] struct {
	Index int
	Value T
}

Item represents the slice item

type Safe added in v2.4.0

type Safe[T any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Safe type that can be safely shared between goroutines.

func NewSafe added in v2.4.0

func NewSafe[T any]() *Safe[T]

NewSafe creates a new synchronized slice.

func (*Safe[T]) Append added in v2.4.0

func (cs *Safe[T]) Append(item T)

Append adds an item to the concurrent slice.

func (*Safe[T]) Delete added in v2.4.0

func (cs *Safe[T]) Delete(index int)

Delete an item from the slice

func (*Safe[T]) Get added in v2.4.0

func (cs *Safe[T]) Get(index int) (item any)

Get returns the slice item at the given index

func (*Safe[T]) Iter added in v2.4.0

func (cs *Safe[T]) Iter() <-chan Item[T]

Iter iterates the items in the concurrent slice. Each item is sent over a channel, so that we can iterate over the slice using the builtin range keyword.

func (*Safe[T]) Len added in v2.4.0

func (cs *Safe[T]) Len() int

Len returns the number of items

Jump to

Keyboard shortcuts

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