sliceutil

package
v0.0.0-...-e9ebb46 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 4 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone[T comparable](t []T) []T

Clone a slice through built-in copy

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 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 IsEmpty

func IsEmpty[V comparable](s []V) bool

IsEmpty checks if the slice has length zero

func Merge

func Merge[V comparable](ss ...[]V) []V

Merge and dedupe multiple items

func MergeItems

func MergeItems[V comparable](items ...V) []V

Merge and dedupe multiple items into a

func PickRandom

func PickRandom[T any](v []T) T

PickRandom item from a slice of elements

func PruneEmptyStrings

func PruneEmptyStrings(v []string) []string

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 ToInt

func ToInt(s []string) ([]int, error)

ToInt converts a slice of strings to a slice of ints

Types

type Items

type Items struct {
	// contains filtered or unexported fields
}

concurrenct safe slice

type SafeSlice

type SafeSlice struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

concurrenct safe slice

func (*SafeSlice) Append

func (ss *SafeSlice) Append(item any)

func (*SafeSlice) Get

func (ss *SafeSlice) Get(index int) any

func (*SafeSlice) Iter

func (ss *SafeSlice) Iter() chan any

func (*SafeSlice) Key

func (ss *SafeSlice) Key(item any) int

func (*SafeSlice) Len

func (ss *SafeSlice) Len() int

func (*SafeSlice) List

func (ss *SafeSlice) List() []any

func (*SafeSlice) Num

func (ss *SafeSlice) Num(item any) int

func (*SafeSlice) ResetNum

func (ss *SafeSlice) ResetNum(item any)

func (*SafeSlice) SetNum

func (ss *SafeSlice) SetNum(item any, num int)

func (*SafeSlice) Update

func (ss *SafeSlice) Update(index int, item any)

func (*SafeSlice) UpdateNum

func (ss *SafeSlice) UpdateNum(item any, num int)

Jump to

Keyboard shortcuts

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