Documentation
¶
Index ¶
- func AppendJust[T any](in []T, extra ...T) []T
- func Collate[T any, K comparable](in []T, get func(T) K) []K
- func Deduplicate[T comparable](in []T) []T
- func DeduplicateFunc[T any, C comparable](in []T, key func(v T) C) []T
- func Gather[T, V any](out []V, in []T, get func(T) V) []V
- func GatherIf[T, V any](out []V, in []T, get func(T) (V, bool)) []V
- func GrowJust[T any](in []T, size int) []T
- func OrderBy[T any, K comparable](in []T, keys []K, key func(T) K)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendJust ¶
func AppendJust[T any](in []T, extra ...T) []T
AppendJust appends extra elements to slice, ONLY allocating at most len(extra) elements. This is different to the typical append behaviour which will append extra, in a manner to reduce the need for new allocations on every call to append.
func Collate ¶
func Collate[T any, K comparable](in []T, get func(T) K) []K
Collate will collect the values of type K from input type []T, passing each item to 'get' and deduplicating the end result. This is equivalent to calling Gather() followed by Deduplicate().
func Deduplicate ¶
func Deduplicate[T comparable](in []T) []T
Deduplicate deduplicates entries in the given slice.
func DeduplicateFunc ¶
func DeduplicateFunc[T any, C comparable](in []T, key func(v T) C) []T
DeduplicateFunc deduplicates entries in the given slice, using the result of key() to gauge uniqueness.
func Gather ¶
func Gather[T, V any](out []V, in []T, get func(T) V) []V
Gather will collect the values of type V from input type []T, passing each item to 'get' and appending V to the return slice.
func GatherIf ¶
GatherIf is functionally similar to Gather(), but only when return bool is true. If you don't need to check the boolean, Gather() will be very slightly faster.
func GrowJust ¶
GrowJust increases slice capacity to guarantee extra room 'size', where in the case that it does need to allocate more it ONLY allocates 'size' extra. This is different to typical slices.Grow behaviour, which simply guarantees extra through append() which may allocate more than necessary extra size.
func OrderBy ¶
func OrderBy[T any, K comparable](in []T, keys []K, key func(T) K)
OrderBy orders a slice of given type by the provided alternative slice of comparable type.
Types ¶
This section is empty.