xslices

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

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

func GatherIf[T, V any](out []V, in []T, get func(T) (V, bool)) []V

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

func GrowJust[T any](in []T, size int) []T

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL