slices

package
v0.405.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 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 Filter

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

func FilterVariants added in v0.397.1

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 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

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