sliceutil

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 3 Imported by: 263

README

sliceutil

The package contains various helpers to interact with slices

Documentation

Index

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 Diff added in v0.0.4

func Diff[V comparable](s1, s2 []V) (extraS1, extraS2 []V)

Diff calculates the extra elements between two sequences

func ElementsMatch added in v0.0.4

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 added in v0.0.4

func Equal[T comparable](s1, s2 []T) bool

Equal checks if the items of two slices are equal respecting the order

func IsEmpty added in v0.0.4

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

IsEmpty checks if the slice has length zero

func Merge added in v0.0.4

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

Merge and dedupe multiple items

func MergeItems added in v0.0.4

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

This section is empty.

Jump to

Keyboard shortcuts

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