Documentation ¶
Overview ¶
Package slices defines various functions useful with slices of any type.
Index ¶
- func Clone[S ~[]E, E any](s S) S
- func Contains[E comparable](s []E, v E) bool
- func Delete[S ~[]E, E any](s S, i int) S
- func Dereference[E any](s []*E) []E
- func Equal[E comparable](s1, s2 []E) bool
- func EqualFunc[E1, E2 comparable](s1 []E1, s2 []E2, eq func(E1, E2) bool) bool
- func Filter[E any](s []E, f func(E) bool) []E
- func FilterInPlace[E any](s []E, f func(E) bool) []E
- func FindFunc[E any](s []E, f func(E) bool) *E
- func Map[E any, O any](s []E, f func(E) O) []O
- func MapFilter[E any, O any](s []E, f func(E) *O) []O
- func Reference[E any](s []E) []*E
- func Reverse[E any](r []E) []E
- func Sort[E constraints.Ordered](x []E) []E
- func SortFunc[S ~[]E, E any](x S, less func(a, b E) int) S
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.
func Contains ¶
func Contains[E comparable](s []E, v E) bool
Contains reports whether v is present in s.
func Dereference ¶
func Dereference[E any](s []*E) []E
Dereference returns all non-nil references, dereferenced
func Equal ¶
func Equal[E comparable](s1, s2 []E) bool
Equal reports whether two slices are equal: the same length and all elements equal. If the lengths are different, Equal returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first unequal pair. Floating point NaNs are not considered equal.
func EqualFunc ¶
func EqualFunc[E1, E2 comparable](s1 []E1, s2 []E2, eq func(E1, E2) bool) bool
EqualFunc reports whether two slices are equal using a comparison function on each pair of elements. If the lengths are different, EqualFunc returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first index for which eq returns false.
func Filter ¶
Filter retains all elements in []E that f(E) returns true for. A new slice is created and returned. Use FilterInPlace to perform in-place
func FilterInPlace ¶
FilterInPlace retains all elements in []E that f(E) returns true for. The array is *mutated in place* and returned. Used Filter to avoid mutation
func Reference ¶
func Reference[E any](s []E) []*E
Reference takes a pointer to all elements in the slice
func Sort ¶
func Sort[E constraints.Ordered](x []E) []E
Sort sorts a slice of any ordered type in ascending order. The slice is modified in place but returned.
Types ¶
This section is empty.