slices

package
v0.412.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendOrReplace

func AppendOrReplace[T any](slice []T, value T, fn func(T) bool) []T

AppendOrReplace appends a value to a slice if the slice does not contain a value for which the given function returns true. If the slice does contain such a value, it is replaced.

func Contains

func Contains[T comparable](slice []T, value T) bool

func Filter

func Filter[T any](slice []T, fn func(T) bool) []T

func FilterVariants

func FilterVariants[T any, U any](slice []U) iter.Seq[T]

FilterVariants finds all elements in a slice that can be cast to the given type.

func Find

func Find[T any](slice []T, fn func(T) bool) (T, bool)

func FindVariant

func FindVariant[T any, U any](slice []U) (T, bool)

FindVariant finds the first element in a slice that can be cast to the given type.

func FlatMap

func FlatMap[T, U any](slice []T, fn func(T) []U) []U

func GroupBy

func GroupBy[T any, K comparable](slice []T, fn func(T) K) map[K][]T

GroupBy groups the elements of a slice by the result of a function.

func Map

func Map[T, U any](slice []T, fn func(T) U) []U

func MapErr

func MapErr[T, U any](slice []T, fn func(T) (U, error)) ([]U, error)

func Reduce

func Reduce[T, U any](slice []T, initial U, fn func(U, T) U) U

func Reverse

func Reverse[T any](slice []T)

Reverse reverses a slice of any type in place.

func Sort

func Sort[T cmp.Ordered](slice []T) []T

Sort returns a sorted clone of slice.

func Unique

func Unique[T comparable](slice []T) []T

Unique returns a new slice containing only the unique elements of the input, with the order preserved.

Types

This section is empty.

Jump to

Keyboard shortcuts

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