slc

package
v0.0.0-...-f022186 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 1 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 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, 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 IndexFn

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

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 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 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 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 new slice omitting any values where fn returns true, maintaining the existing order.

Types

This section is empty.

Jump to

Keyboard shortcuts

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