slices

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone[S ~[]E, E any](s S) S

Clone returns a copy of the slice. The elements are copied using assignment, so this is a shallow clone. TODO(rfindley): use go1.21 slices.Clone.

func Concat

func Concat[S ~[]E, E any](slices ...S) S

Concat returns a new slice concatenating the passed in slices. TODO(rfindley): use go1.22 slices.Concat.

func Contains

func Contains[S ~[]E, E comparable](slice S, x E) bool

Contains reports whether x is present in slice. TODO(adonovan): use go1.21 slices.Contains.

func ContainsFunc

func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool

ContainsFunc reports whether at least one element e of s satisfies f(e). TODO(adonovan): use go1.21 slices.ContainsFunc.

func DeleteFunc added in v0.16.0

func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S

DeleteFunc removes any elements from s for which del returns true, returning the modified slice. DeleteFunc zeroes the elements between the new length and the original length. TODO(adonovan): use go1.21 slices.DeleteFunc.

func Grow

func Grow[S ~[]E, E any](s S, n int) S

Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation. If n is negative or too large to allocate the memory, Grow panics. TODO(rfindley): use go1.21 slices.Grow.

func IndexFunc

func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int

IndexFunc returns the first index i satisfying f(s[i]), or -1 if none do. TODO(adonovan): use go1.21 slices.IndexFunc.

func Remove

func Remove[T comparable](slice []T, elem T) []T

Remove removes all values equal to elem from slice.

The closest equivalent in the standard slices package is:

DeleteFunc(func(x T) bool { return x == elem })

func Reverse added in v0.16.0

func Reverse[S ~[]E, E any](s S)

Reverse reverses the elements of the slice in place. TODO(adonovan): use go1.21 slices.Reverse.

Types

This section is empty.

Jump to

Keyboard shortcuts

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