Help us shape the future of Go! Take the 2026 Go Developer Survey

slc

package
v0.0.0-...-135a05b Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package slc contains additions to the standard slices package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Allow

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

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. Also, the result is the exact size, no extra.

func CommonPrefix

func CommonPrefix[E comparable](s, t []E) []E

CommonPrefix returns the common prefix of two slices

func CommonPrefixLen

func CommonPrefixLen[E comparable](s, t []E) int

CommonPrefixLen returns the length of the common prefix of two slices

func ContainsFn

func ContainsFn[E any, S ~[]E](s S, e E, eq func(E, E) bool) bool

func Empty

func Empty[E any](s []E) bool

Empty returns true if the list is empty but not nil

func Fill

func Fill[E any](data []E, value E)

Fill sets all the elements of data to value

func Grow

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

Grow grows the buffer to guarantee space for n more elements. NOTE: Unlike x/exp/slices.Grow it extends the length, as well as the capacity Using append and make like slices.Grow assuming that is optimized.

func HasDup

func HasDup[E comparable](list []E) bool

HasDup returns true if the slice contains any duplicate values

func HasPrefix

func HasPrefix[E comparable](list, list2 []E) bool

HasPrefix returns true if list2 is a prefix of list

func IndexFn

func IndexFn[E, E2 any](list []E, e2 E2, eq func(E, E2) bool) int

func LastIndex

func LastIndex[E comparable](list []E, e E) int

func MapFn

func MapFn[E1, E2 any](list []E1, fn func(E1) E2) []E2

MapFn returns a new slice with each element the result of calling fn on the original element.

func Max

func Max[E cmp.Ordered](list []E) E

Max returns the maximum value in the list

func Min

func Min[E cmp.Ordered](list []E) E

Min returns the minimum value in the list

func Partition

func Partition(n int, pivot func(int) bool, swap func(int, int)) int

Partition rearranges based on a pivot function

func Repeat

func Repeat[E any](x E, n int) []E

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 Reverse

func Reverse[S ~[]E, E any](x S) S

func Same

func Same[E any](x, y []E) bool

Same returns true if x and y are the same slice

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 Shuffle

func Shuffle[E any](rnd *rand.Rand, list []E)

func StartsWith

func StartsWith[E comparable](list []E, e E) bool

func Swap

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

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.

func WithoutFn

func WithoutFn[S ~[]E, E any](list S, fn func(E) bool) S

WithoutFn returns a slice omitting any values where fn returns true, maintaining the existing order. If there are no changes, it returns the original slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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