sliceutils

package
v0.0.0-...-525d511 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 3 Imported by: 27

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendUnique

func AppendUnique[S ~[]E, E comparable](in S, add ...E) S

AppendUnique appends elements to a slice, if they are not net contained.

func AppendUniqueFunc

func AppendUniqueFunc[S ~[]E, E comparable](in S, cmp func(E, E) int, add ...E) S

AppendUniqueFunc returns appends additional elements, if they are considered by the given function not to be yet present.

func AsAny

func AsAny[S ~[]T, T any](s S) []any

AsAny converts any slice to an interface slice.

func Convert

func Convert[T, S any](a []S) []T

Convert converts a slice to a slice with a more general element type.

func ConvertPointer

func ConvertPointer[T any, S ~[]P, E any, P generics.PointerType[E]](s S) []T

ConvertPointer converts a slice of pointers to an interface slice avoiding typed nil interfaces.

func ConvertWith

func ConvertWith[S, T, I any](in []S, c func(I) T) []T

ConvertWith converts the element type of a slice using a converter function. Unfortunately this cannot be expressed in a type-safe way in Go. I MUST follow the type constraint I super S, which cannot be expressed in Go. If I == S the Transform function should be used, instead.

func CopyAppend

func CopyAppend[E any](slice []E, elems ...E) []E

CopyAppend returns a new slice containing the additional elements appended to to the original slice.

func CopyAppendUnique

func CopyAppendUnique[S ~[]E, E comparable](in S, add ...E) S

CopyAppendUnique returns a new slice with additional elements appended, if they are not net contained.

func CopyAppendUniqueFunc

func CopyAppendUniqueFunc[S ~[]E, E any](in S, eq func(E, E) bool, add ...E) S

CopyAppendUniqueFunc returns a new slice with additional elements appended, if they are considered by the given function not to be yet present.

func Filter

func Filter[S ~[]E, E any](in S, f matcher.Matcher[E]) S

Filter filters a slice by a matcher.Matcher.

func Transform

func Transform[S ~[]E, E any, T any](in S, m func(E) T) []T

Types

This section is empty.

Jump to

Keyboard shortcuts

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