Documentation
¶
Overview ¶
Package slicesx provides additional slice functions beyond those in the standard slices package.
Index ¶
- func As[F, T any](s []F) []T
- func CopyFrom[E any](dest []E, src []E) []E
- func GrowTo[S ~[]E, E any](s S, n int) S
- func Move[E any](s []E, from, to int) []E
- func Search[E any](slice []E, match func(e E) bool, startIndex ...int) int
- func SetLength[E any](s []E, n int) []E
- func Swap[E any](s []E, i, j int)
- func ToBytes[E any](src []E) []byte
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 ¶
GrowTo increases the slice's capacity, if necessary, so that it can hold at least n elements.
func Move ¶
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 ¶
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 ¶
SetLength sets the length of the given slice, re-using and preserving existing values to the extent possible.
Types ¶
This section is empty.