slicesx

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package slicesx provides additional slice functions beyond those in the standard slices package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[F, T any](s []F) []T

As converts a slice of the given type to a slice of the other given type. The underlying types of the slice elements must be equivalent.

func CopyFrom

func CopyFrom[E any](dest []E, src []E) []E

CopyFrom efficiently copies from src into dest, using SetLength to ensure the destination has sufficient capacity, and returns the destination (which may have changed location as a result).

func GrowTo

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

GrowTo increases the slice's capacity, if necessary, so that it can hold at least n elements.

func Move

func Move[E any](s []E, from, to int) []E

Move moves the element in the given slice at the given old position to the given new position and returns the resulting slice.

func Search[E any](slice []E, match func(e E) bool, startIndex ...int) int

Search returns the index of the item in the given slice that matches the target according to the given match function, using the given optional starting index to optimize the search by searching bidirectionally outward from given index. This is much faster when you have some idea about where the item might be. If no start index is given, it starts in the middle, which is a good default. It returns -1 if no item matching the match function is found.

func SetLength

func SetLength[E any](s []E, n int) []E

SetLength sets the length of the given slice, re-using and preserving existing values to the extent possible.

func Swap

func Swap[E any](s []E, i, j int)

Swap swaps the elements at the given two indices in the given slice.

func ToBytes

func ToBytes[E any](src []E) []byte

ToBytes returns the underlying bytes of given slice. for items not in a slice, make one of length 1. This is copied from webgpu.

Types

This section is empty.

Jump to

Keyboard shortcuts

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