slicesutil

package
v0.68.11 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 6 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendBulk added in v0.67.9

func AppendBulk[S ~[]E, E any](s S, ss []S) S

AppendBulk appends multiple slice to a slice, and skips 0 length slices.

func Dedupe

func Dedupe[S ~[]E, E comparable](s S) S

Dedupe returns a string slice with duplicate values removed. First observance is kept.

func ElementCounts added in v0.56.0

func ElementCounts[E comparable](s []E) map[E]int

func IndexValueOrDefault added in v0.54.0

func IndexValueOrDefault[E any](s []E, idx int, def E) E

IndexValueOrDefault returns the value at the supplied index or a supplied default value.

func LengthCounts added in v0.61.1

func LengthCounts[E any](s [][]E) map[uint]uint

LengthCounts returns a `map[uint]uint` where the keys are element lengths and the values are counts of slices with those lengths.

func MakeMatrix2D added in v0.44.0

func MakeMatrix2D[E any](n, m int) [][]E

MakeMatrix2D returns a 2-dimensional matrix. Usage as follows `a := Make2D[uint8](dy, dx)`. Sourced from: https://stackoverflow.com/a/71781206/1908967

func MakeRepeatingElement added in v0.67.1

func MakeRepeatingElement[V any](l int, v V) []V

func MatchAny added in v0.68.7

func MatchAny[C comparable](s1, s2 []C) bool

func MatchFilters added in v0.50.0

func MatchFilters[E comparable](s, inclFilters, exclFilters []E, inclAll bool) bool

func MatrixGetOneOrDefault added in v0.47.0

func MatrixGetOneOrDefault[C comparable](m [][]C, keyIdx int, keyValue C, wantIdx int, defaultValue C) C

func MatrixIntColSums added in v0.63.2

func MatrixIntColSums(m [][]int) []int

func NewWithDefault added in v0.48.0

func NewWithDefault[E any](size int, d E) []E

NewWithDefault creates a slice of length `size` which values populated by default value `d`.

func Prepend added in v0.60.0

func Prepend[S ~[]E, E any](s []E, e E) []E

func Reverse added in v0.45.0

func Reverse[E comparable](s []E)

Reverse reverses the order of a slice.

func ReverseIndex added in v0.50.0

func ReverseIndex(n, i uint) uint

ReverseIndex returns the forward index value from the end of the string.

func Shift added in v0.60.0

func Shift[S ~[]E, E any](s S) (E, S)

func SliceIntSum added in v0.63.2

func SliceIntSum(s []int) int

func Sort added in v0.61.1

func Sort[E constraints.Ordered](s []E)

func SortSliceOfSlice added in v0.59.0

func SortSliceOfSlice[S ~[][]E, E constraints.Ordered | string](s S, indexes ...uint)

func Split added in v0.47.0

func Split[S ~[]E, E comparable](s S, n int) []S

Split will split a slice into a slice of slices where each slice has a max size `n`.

func SplitMaxLength added in v0.62.5

func SplitMaxLength[S ~[]E, E any](s S, maxLen int) []S

SplitMaxLength returns a slice of slices where each sub-slice has the max length supplied. A supplied `maxLength` of `0` indicates no max length.

func Sub added in v0.45.0

func Sub[S ~[]E, E comparable](s, t S) S

Sub returns a string slice with duplicate values removed. First observance is kept.

func SubRegexpString added in v0.45.0

func SubRegexpString(s []string, r *regexp.Regexp) []string

Sub returns a string slice with duplicate values removed. First observance is kept.

func ToMatrix added in v0.47.0

func ToMatrix[S ~[]E, E comparable](s S) []S

func Unique added in v0.67.5

func Unique[S ~[]E, E comparable](s S) bool

Types

type SplitVennResultComparable added in v0.68.9

type SplitVennResultComparable[C comparable] struct {
	Intersection []C
	FirstOnly    []C
	SecondOnly   []C
}

func SplitVenn2 added in v0.68.7

func SplitVenn2[C comparable](s1, s2 []C) SplitVennResultComparable[C]

type SplitVennResultOrdered added in v0.68.9

type SplitVennResultOrdered[O cmp.Ordered] struct {
	Intersection []O
	FirstOnly    []O
	SecondOnly   []O
}

func SplitVenn2Sort added in v0.68.7

func SplitVenn2Sort[O cmp.Ordered](s1, s2 []O) SplitVennResultOrdered[O]

Jump to

Keyboard shortcuts

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