Documentation ¶
Index ¶
- func AppendOrReplace[T any](slice []T, value T, fn func(T) bool) []T
- func Contains[T comparable](slice []T, value T) bool
- func Filter[T any](slice []T, fn func(T) bool) []T
- func FilterVariants[T any, U any](slice []U) iter.Seq[T]
- func Find[T any](slice []T, fn func(T) bool) (T, bool)
- func FindVariant[T any, U any](slice []U) (T, bool)
- func FlatMap[T, U any](slice []T, fn func(T) []U) []U
- func GroupBy[T any, K comparable](slice []T, fn func(T) K) map[K][]T
- func Map[T, U any](slice []T, fn func(T) U) []U
- func MapErr[T, U any](slice []T, fn func(T) (U, error)) ([]U, error)
- func Reduce[T, U any](slice []T, initial U, fn func(U, T) U) U
- func Reverse[T any](slice []T)
- func Sort[T cmp.Ordered](slice []T) []T
- func Unique[T comparable](slice []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendOrReplace ¶
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 FilterVariants ¶
FilterVariants finds all elements in a slice that can be cast to the given type.
func FindVariant ¶
FindVariant finds the first element in a slice that can be cast to the given type.
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 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.
Click to show internal directories.
Click to hide internal directories.