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 ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultIfEmpty ¶ added in v0.12.0
func DefaultIfEmpty[T any](input []T, defaultSlice []T) []T
DefaultIfEmpty returns the default slice if the input slice is nil or empty, otherwise it returns the input slice.
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.
Types ¶
This section is empty.