sliceutil

package
v0.57.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: AGPL-3.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendUnique

func AppendUnique[T comparable](s []T, ee ...T) []T

AppendUnique appends e to s if e is not already present in s.

func AppendUniqueSort

func AppendUniqueSort[T cmp.Ordered](s []T, vs ...T) []T

AppendUniqueSort appends e to s if e is not already present in s and sorts the slice.

Note, that s slice must be sorted before calling this function.

func AppendUniqueSortFunc

func AppendUniqueSortFunc[T any](s []T, cmp func(T, T) int, vs ...T) []T

AppendUniqueSortFunc appends e to s if e is not already present in s and sorts the slice.

Note, that s slice must be sorted before calling this function.

func Contains

func Contains[T comparable](s []T, e T) bool

Contains returns true if s slice contains e element.

func ContainsAll

func ContainsAll[T comparable](s []T, e []T) bool

ContainsAll returns true if s slice contains all elements in e slice.

func Copy

func Copy[T any](s []T) []T

Copy returns a copy of the slice.

func Filter

func Filter[T any](s []T, f func(T) bool) []T

Filter returns a new slice with the elements of the original slice that satisfy the predicate f.

func IndexOf

func IndexOf[T comparable](s []T, e T) int

IndexOf returns the index of the first occurrence of e in s, or -1 if e is not present in s.

func Intersect

func Intersect[T comparable](slices ...[]T) []T

Intersect returns a new slice with the elements that are present in all slices.

func IsUnique

func IsUnique[T comparable](s []T) bool

IsUnique returns true if all elements in the slice are unique.

func Map

func Map[T, U any](s []T, f func(T) U) []U

Map returns a new slice with the results of applying the function f to each element of the original slice.

func MapErr

func MapErr[T, U any](s []T, f func(T) (U, error)) (r []U, err error)

MapErr returns a new slice with the results of applying the function f to each element of the original slice and fails when applying the function to eny of the elements fails.

func Once

func Once[T comparable](slices ...[]T) []T

Once returns a new slice with the elements that are present only once in all slices.

func Unique

func Unique[T comparable](slices ...[]T) []T

Unique returns a new slice with the unique elements of all slices. The order of the elements is preserved.

Types

This section is empty.

Jump to

Keyboard shortcuts

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