Documentation
¶
Overview ¶
Package slices provides a rich set of generic functions for common operations on slices of any element type.
This package is a generated adapter that mirrors the public API of the standard Go experimental package `golang.org/x/exp/slices`. It offers a convenient way to access these common utilities for searching, sorting, comparing, and manipulating slices.
For detailed information on the behavior of specific functions, please refer to the pkg.go.dev documentation for the `slices` package.
Package slices implements the functions, types, and interfaces for the module.
Package slices contains generated code by adptool.
Package slices implements the functions, types, and interfaces for the module.
Index ¶
- Variables
- func Append[S any](arr []S, v S) ([]S, int)
- func BinarySearch[S ~[]E, E constraints.Ordered](x S, target E) (int, bool)
- func BinarySearchFunc[S ~[]E, E, T any](x S, target T, cmp func(E, T) int) (int, bool)
- func Clip[S ~[]E, E any](s S) S
- func Clone[S ~[]E, E any](s S) S
- func Compact[S ~[]E, E comparable](s S) S
- func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S
- func Compare[S ~[]E, E constraints.Ordered](s1, s2 S) int
- func CompareFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, cmp func(E1, E2) int) int
- func Contains[S ~[]E, E comparable](s S, v E) bool
- func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool
- func CopyAt[S any](s, t []S, i int) []S
- func Count[S E](s, sub []S) int
- func CountArray[S E](ss []S, s S) int
- func Cut[S E](s, sep []S) (before, after []S, found bool)
- func Delete[S ~[]E, E any](s S, i, j int) S
- func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S
- func Equal[S ~[]E, E comparable](s1, s2 S) bool
- func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool
- func Filter[S any](s []S, f func(S) bool) []S
- func FilterExcluded[S comparable](s []S, excludes []S) []S
- func FilterIncluded[S comparable](s []S, includes []S) []S
- func Grow[S ~[]E, E any](s S, n int) S
- func Index[S ~[]E, E comparable](s S, v E) int
- func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int
- func IndexSlice[S E](s, substr []S) int
- func Insert[S ~[]E, E any](s S, i int, v ...E) S
- func InsertWith[S any](s []S, v S, fn func(a, b S) bool) []S
- func IsSorted[S ~[]E, E constraints.Ordered](x S) bool
- func IsSortedFunc[S ~[]E, E any](x S, cmp func(a, b E) int) bool
- func Join[S any](s [][]S, sep []S) []S
- func LastIndexSlice[S E](s, sep []S) int
- func Map[S, T any](s []S, f func(S) T) []T
- func Max[S ~[]E, E constraints.Ordered](x S) E
- func MaxFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E
- func Min[S ~[]E, E constraints.Ordered](x S) E
- func MinFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E
- func OverWithError[S any](s []S, err error) func(func(int, S) bool)
- func Read[S any](arr []S, offset int, limit int) []S
- func Reduce[S, T any](s []S, initial T, f func(T, S) T) T
- func RemoveWith[S any](s []S, fn func(a S) bool) []S
- func Repeat[S any](b []S, count int) []S
- func Replace[S ~[]E, E any](s S, i, j int, v ...E) S
- func Reverse[S ~[]E, E any](s S)
- func Sort[S ~[]E, E constraints.Ordered](x S)
- func SortFunc[S ~[]E, E any](x S, cmp func(a, b E) int)
- func SortStableFunc[S ~[]E, E any](x S, cmp func(a, b E) int)
- func Split[S E](s, sep []S) [][]S
- func Transform[S any, T any](s []S, f func(S) (T, bool)) []T
- func Unique[S E](s []S) []S
- type E
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWrongIndex is an error returned when an index is out of range. ErrWrongIndex = errors.New("slices: index out of range") )
Functions ¶
func BinarySearch ¶ added in v0.4.0
func BinarySearch[S ~[]E, E constraints.Ordered](x S, target E) (int, bool)
func BinarySearchFunc ¶ added in v0.4.0
func Compact ¶ added in v0.4.0
func Compact[S ~[]E, E comparable](s S) S
func CompactFunc ¶ added in v0.4.0
func Compare ¶ added in v0.4.0
func Compare[S ~[]E, E constraints.Ordered](s1, s2 S) int
func CompareFunc ¶ added in v0.4.0
func Contains ¶
func Contains[S ~[]E, E comparable](s S, v E) bool
func ContainsFunc ¶ added in v0.4.0
func CopyAt ¶
CopyAt copies the elements from t into s at the specified index. It panics if the index is negative. If the required length is greater than the length of s, s is grown to accommodate the new elements.
func CountArray ¶
CountArray counts the number of occurrences of c in s.
func Cut ¶
Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, nil, false.
func DeleteFunc ¶ added in v0.4.0
func Equal ¶
func Equal[S ~[]E, E comparable](s1, s2 S) bool
func Filter ¶ added in v0.4.0
Filter returns a new slice containing all elements of s for which f(s) is true.
func FilterExcluded ¶ added in v0.6.0
func FilterExcluded[S comparable](s []S, excludes []S) []S
FilterExcluded returns a new slice containing all elements of s that are not present in excludes.
func FilterIncluded ¶ added in v0.6.0
func FilterIncluded[S comparable](s []S, includes []S) []S
FilterIncluded returns a new slice containing all elements of s that are present in includes.
func Index ¶
func Index[S ~[]E, E comparable](s S, v E) int
func IndexSlice ¶ added in v0.4.0
IndexSlice returns the index of the first instance of substr in s, or -1 if not present.
func InsertWith ¶
InsertWith inserts v into s at the first index where fn(a, b) is true.
func IsSorted ¶ added in v0.4.0
func IsSorted[S ~[]E, E constraints.Ordered](x S) bool
func IsSortedFunc ¶ added in v0.4.0
func Join ¶
func Join[S any](s [][]S, sep []S) []S
Join concatenates the elements of s to create a single slice. The separator sep is placed between elements in the resulting slice.
func LastIndexSlice ¶ added in v0.4.0
LastIndexSlice returns the index of the last instance of sep in s, or -1 if not present.
func Map ¶ added in v0.4.0
func Map[S, T any](s []S, f func(S) T) []T
Map transforms a slice of one type to a slice of another type using a mapping function.
func Max ¶ added in v0.4.0
func Max[S ~[]E, E constraints.Ordered](x S) E
func Min ¶ added in v0.4.0
func Min[S ~[]E, E constraints.Ordered](x S) E
func OverWithError ¶
OverWithError returns an iterator function for a slice that may have an associated error.
func Reduce ¶ added in v0.4.0
func Reduce[S, T any](s []S, initial T, f func(T, S) T) T
Reduce aggregates all elements of a slice into a single value by applying a function.
func RemoveWith ¶
RemoveWith removes elements from a slice based on a predicate function.
func Sort ¶ added in v0.4.0
func Sort[S ~[]E, E constraints.Ordered](x S)
func SortStableFunc ¶ added in v0.4.0
func Split ¶ added in v0.4.0
func Split[S E](s, sep []S) [][]S
Split slices s into all subslices separated by sep.
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bytes contains generated code by adptool.
|
Package bytes contains generated code by adptool. |
|
Package runes provides a rich set of functions for the manipulation of rune slices (`[]rune`).
|
Package runes provides a rich set of functions for the manipulation of rune slices (`[]rune`). |