Documentation ¶
Overview ¶
Package slc contains additions to the standard slices package
Index ¶
- func Allow[S ~[]E, E any](s S, n int) S
- func Clone[E any](list []E) []E
- func ContainsFn[E any, S ~[]E](s S, e E, eq func(E, E) bool) bool
- func Empty[E any](s []E) bool
- func Fill[E any](data []E, value E)
- func Grow[S ~[]E, E any](s S, n int) S
- func HasPrefix[E comparable](list, list2 []E) bool
- func IndexFn[E any](list []E, e E, eq func(E, E) bool) int
- func LastIndex[E comparable](list []E, e E) int
- func MapFn[S ~[]E, E any](list S, fn func(E) E) S
- func Max[E cmp.Ordered](list []E) E
- func Min[E cmp.Ordered](list []E) E
- func Repeat[E any](x E, n int) []E
- func Replace1[S ~[]E, E comparable](list S, from, to E) S
- func Reverse[S ~[]E, E any](x S) S
- func Same[E any](x, y []E) bool
- func Shrink[S ~[]E, E any](s S) S
- func StartsWith[E comparable](list []E, e E) bool
- func Swap[E any](data []E, i, j int)
- func With[S ~[]E, E any](s1 S, s2 ...E) S
- func Without[S ~[]E, E comparable](list S, str E) S
- func WithoutFn[S ~[]E, E any](list S, fn func(E) bool) S
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Allow ¶
Allow increases the length of the slice to guarantee space for n elements. NOTE: Unlike x/exp/slices.Grow it extends the length, not the capacity. Using append and make like x/exp/slices.Grow assuming that is optimized.
func Clone ¶
func Clone[E any](list []E) []E
Clone is like slices.Clone except that it guarantees that the returned slice does not reference the original. slices.Clone for a zero length slice still references the original which can cause memory retention issues.
func ContainsFn ¶
func Grow ¶
Grow grows the buffer to guarantee space for n more elements. NOTE: Unlike x/exp/slices.Grow it extends the length, not the capacity. Using append and make like x/exp/slices.Grow assuming that is optimized.
func HasPrefix ¶
func HasPrefix[E comparable](list, list2 []E) bool
HasPrefix returns true if list2 is a prefix of list
func LastIndex ¶
func LastIndex[E comparable](list []E, e E) int
func MapFn ¶
func MapFn[S ~[]E, E any](list S, fn func(E) E) S
MapFn returns a new slice with each element the result of calling fn on the original element.
func Replace1 ¶
func Replace1[S ~[]E, E comparable](list S, from, to E) S
Replace1 returns a new list with occurrences of from replaced by to
func Shrink ¶
func Shrink[S ~[]E, E any](s S) S
Shrink returns a copy of the list with the excess capacity removed or the original if there is no excess capacity.
func StartsWith ¶
func StartsWith[E comparable](list []E, e E) bool
func With ¶
func With[S ~[]E, E any](s1 S, s2 ...E) S
With returns a copy of the list with the values appended. Unlike append, it allocates just the right size, no extra.
func Without ¶
func Without[S ~[]E, E comparable](list S, str E) S
Without returns a new slice omitting any occurrences of the given value, maintaining the existing order.
Types ¶
This section is empty.