slicez

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: BSD-2-Clause Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concat added in v0.3.0

func Concat[T any](slices ...[]T) []T

Concat concatenates multiple slices together into a single slice. The input slices are not modified, order is preserved and the returned slice is exactly sized to hold its elements.

func Diff

func Diff[T comparable](a, b []T) []T

Diff returns `a` with all elements occurring in `b` removed.

func Filter

func Filter[T any](a []T, cb func(a T) bool) []T

Filter returns `a` with only the elements for which the callback returned true.

func MakePointers added in v0.15.0

func MakePointers[T any](n int) []*T

MakePointers creates a slice of pointers and allocates the entries.

All Ts are allocated in a single batch, and won't be garbage collected until the entire batch is no longer referenced.

func Map added in v0.8.0

func Map[T, U any](s []T, fn func(e T) U) []U

Map returns a new slice with every element from `s` converted by `fn`.

func MustIndex added in v0.19.0

func MustIndex[S ~[]E, E comparable](s S, v E) int

MustIndex is like slices.Index, but panics instead of returning -1.

func MustPop added in v0.18.0

func MustPop[T any](s *[]T) T

MustPop returns the last element of a slice, and shrinks the slice by one. MustPop panics if the slice is empty.

func Pop added in v0.18.0

func Pop[T any](s *[]T) (T, bool)

Pop returns the last element of a slice, and shrinks the slice by one. Pop returns _, false iff the given slice is empty.

func Sum added in v0.7.0

Sum all entries in a slice together.

func Unique

func Unique[T comparable](a []T) []T

Unique returns `a` with all duplicate elements removed. Order is preserved.

Types

This section is empty.

Jump to

Keyboard shortcuts

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