Documentation
¶
Overview ¶
Package sliceutil contains helpers related to slices, usually ones that are generic-related, and are broadly useful, but which the Go core team, in its infinite wisdom, has decided are too much power for the unwashed mashes, and therefore omitted from the utilities in `slices`.
Index ¶
- func FirstNonEmpty[T any](inputs ...[]T) []T
- func GroupBy[T any, U comparable](collection []T, keyFunc func(T) U) map[U][]T
- func KeyBy[T any, K comparable, V any](collection []T, tupleFunc func(item T) (K, V)) map[K]V
- func Map[T any, R any](collection []T, mapFunc func(T) R) []R
- func MapError[T any, R any](collection []T, mapFunc func(T) (R, error)) ([]R, error)
- func Uniq[T comparable](collection []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FirstNonEmpty ¶ added in v0.17.0
func FirstNonEmpty[T any](inputs ...[]T) []T
FirstNonEmpty returns the first non-empty slice from the input, or nil if all input slices are empty.
func GroupBy ¶
func GroupBy[T any, U comparable](collection []T, keyFunc func(T) U) map[U][]T
GroupBy returns an object composed of keys generated from the results of running each element of collection through keyFunc.
func KeyBy ¶
func KeyBy[T any, K comparable, V any](collection []T, tupleFunc func(item T) (K, V)) map[K]V
KeyBy converts a slice into a map using the key/value tuples returned by tupleFunc. If any two pairs would have the same key, the last one wins. Go maps are unordered and the order of the new map isn't guaranteed to the same as the original slice.
func MapError ¶ added in v0.23.0
MapError manipulates a slice and transforms it to a slice of another type, returning the first error that occurred invoking the map function, if there was one.
func Uniq ¶ added in v0.23.0
func Uniq[T comparable](collection []T) []T
Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array.
Types ¶
This section is empty.