Documentation
¶
Index ¶
- func Clone[T comparable](t []T) []T
- func Contains[T comparable](inputSlice []T, element T) bool
- func ContainsItems[T comparable](s1 []T, s2 []T) bool
- func Dedupe[T comparable](inputSlice []T) (result []T)
- func DedupeFunc[T any](inputSlice []T, keyFunc func(T) any) (result []T)
- func Diff[V comparable](s1, s2 []V) (extraS1, extraS2 []V)
- func ElementsMatch[V comparable](s1, s2 []V) bool
- func Equal[T comparable](s1, s2 []T) bool
- func FirstNonZero[T comparable](inputs []T) (T, bool)
- func IsEmpty[V comparable](s []V) bool
- func Merge[V comparable](ss ...[]V) []V
- func MergeItems[V comparable](items ...V) []V
- func PickRandom[T any](v []T) T
- func PruneEmptyStrings(v []string) []string
- func PruneEqual[T comparable](inputSlice []T, equalTo T) (r []T)
- func ToInt(s []string) ([]int, error)
- func VisitRandom[T comparable](t []T, visit VisitFunc[T])
- func VisitRandomZero[T comparable](t []T, visit VisitFunc[T])
- func VisitSequential[T comparable](t []T, visit VisitFunc[T])
- type SyncSlice
- type VisitFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](inputSlice []T, element T) bool
Contains if a slice contains an element
func ContainsItems ¶
func ContainsItems[T comparable](s1 []T, s2 []T) bool
ContainsItems checks if s1 contains s2
func Dedupe ¶
func Dedupe[T comparable](inputSlice []T) (result []T)
Dedupe removes duplicates from a slice of elements preserving the order
func DedupeFunc ¶
DedupeFunc removes duplicates from a slice of elements using a key function The key function is used to return a key for each element in the slice and then the key is used to check for duplicates If the key function is nil, we return the original input slice
func Diff ¶
func Diff[V comparable](s1, s2 []V) (extraS1, extraS2 []V)
Diff calculates the extra elements between two sequences
func ElementsMatch ¶
func ElementsMatch[V comparable](s1, s2 []V) bool
ElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.
func Equal ¶
func Equal[T comparable](s1, s2 []T) bool
Equal checks if the items of two slices are equal respecting the order
func FirstNonZero ¶
func FirstNonZero[T comparable](inputs []T) (T, bool)
FirstNonZero function takes a slice of comparable type inputs, and returns the first non-zero element in the slice along with a boolean value indicating if a non-zero element was found or not.
func MergeItems ¶
func MergeItems[V comparable](items ...V) []V
Merge and dedupe multiple items into a
func PruneEmptyStrings ¶
PruneEmptyStrings from the slice
func PruneEqual ¶
func PruneEqual[T comparable](inputSlice []T, equalTo T) (r []T)
PruneEqual removes items from the slice equal to the specified value
func VisitRandom ¶
func VisitRandom[T comparable](t []T, visit VisitFunc[T])
VisitRandom visits all items in the slice in random order and calls the specified function for each item
func VisitRandomZero ¶
func VisitRandomZero[T comparable](t []T, visit VisitFunc[T])
VisitRandomZero visits all items in the slice in random order without allocations and calls the specified function for each item
func VisitSequential ¶
func VisitSequential[T comparable](t []T, visit VisitFunc[T])
VisitSequential visits all items in the slice in sequential order and calls the specified function for each item
Types ¶
type SyncSlice ¶
type SyncSlice[K comparable] struct { Slice []K // contains filtered or unexported fields }
SyncSlice provides a thread-safe slice for elements of any comparable type.
func NewSyncSlice ¶
func NewSyncSlice[K comparable]() *SyncSlice[K]
NewSyncSlice initializes a new instance of SyncSlice.
func (*SyncSlice[K]) Append ¶
func (ss *SyncSlice[K]) Append(items ...K)
Append adds elements to the end of the slice in a thread-safe manner.
func (*SyncSlice[K]) Each ¶
Each iterates over all elements in the slice and applies the function f to each element. Iteration is done in a read-locked context to prevent data race.
func (*SyncSlice[K]) Empty ¶
func (ss *SyncSlice[K]) Empty()
Empty clears the slice by reinitializing it in a thread-safe manner.
func (*SyncSlice[K]) Get ¶
Get retrieves an element by index from the slice safely. Returns the element and true if index is within bounds, otherwise returns zero value and false.
type VisitFunc ¶
type VisitFunc[T comparable] func(index int, item T) error