slices

package
v0.349.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 2 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 Filter

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

func Find added in v0.184.2

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

func FindVariant added in v0.232.0

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

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

Sort returns a sorted clone of slice.

func Unique added in v0.272.0

func Unique[T comparable](slice []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