sliceutils

package
v0.0.0-...-53a60af Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 5 Imported by: 61

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendUnique

func AppendUnique[S ~[]E, E comparable](in S, add ...E) S

AppendUnique appends elements to a slice, if they are not net contained.

func AppendUniqueFunc

func AppendUniqueFunc[S ~[]E, E any](in S, eq general.EqualsFunc[E], add ...E) S

AppendUniqueFunc returns appends additional elements, if they are considered by the given function not to be yet present.

func AsAny

func AsAny[S ~[]T, T any](s S) []any

AsAny converts any slice to an interface slice.

func AsSlice

func AsSlice[T any](elems ...T) []T

AsSlice provides a slice for a given list of elements. If the elements are not og the same type, but only share a common super type, the intended super type must be passed as type parameter.

func Convert

func Convert[T, S any](a []S) []T

Convert converts a slice to a slice with a more general element type.

func ConvertPointer

func ConvertPointer[T any, S ~[]P, E any, P generics.PointerType[E]](s S) []T

ConvertPointer converts a slice of pointers to an interface slice avoiding typed nil interfaces.

func ConvertWith

func ConvertWith[S, T, I any](in []S, c func(I) T) []T

ConvertWith converts the element type of a slice using a converter function. Unfortunately this cannot be expressed in a type-safe way in Go. I MUST follow the type constraint I super S, which cannot be expressed in Go. If I == S the Transform function should be used, instead.

func CopyAppend

func CopyAppend[E any](slice []E, elems ...E) []E

CopyAppend returns a new slice containing the additional elements appended to to the original slice.

func CopyAppendUnique

func CopyAppendUnique[S ~[]E, E comparable](in S, add ...E) S

CopyAppendUnique returns a new slice with additional elements appended, if they are not net contained.

func CopyAppendUniqueFunc

func CopyAppendUniqueFunc[S ~[]E, E any](in S, eq general.EqualsFunc[E], add ...E) S

CopyAppendUniqueFunc returns a new slice with additional elements appended, if they are considered by the given function not to be yet present.

func Filter

func Filter[S ~[]E, E any](in S, f matcher.Matcher[E]) S

Filter filters a slice by a matcher.Matcher.

func FilterType

func FilterType[T any, S ~[]E, E any](elems S) []T

FilterType filters elements of a dedicated super type from a list of specialized types.

func InitialSliceFor

func InitialSliceFor[S ~[]E, E any](in S) S

InitialSliceFor provides a new initial slice with length and capacity taken from the given one.

func InitialSliceWithTypeFor

func InitialSliceWithTypeFor[TS ~[]TE, TE any, S ~[]E, E any](in S) TS

InitialSliceWithTypeFor is like InitialSliceFor, but provides a slice of the explicitly given type TS instead of the one from the given slice S.

func Reverse

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

func Transform

func Transform[S ~[]E, E any, T any](in S, m func(E) T) []T

Types

type ComparableSlice

type ComparableSlice[E comparable] Slice[E]

func (*ComparableSlice[E]) Add

func (s *ComparableSlice[E]) Add(elems ...E)

Add appends element to the slice.

func (*ComparableSlice[E]) AppendUnique

func (s *ComparableSlice[E]) AppendUnique(elems ...E)

func (*ComparableSlice[E]) AppendUniqueFunc

func (s *ComparableSlice[E]) AppendUniqueFunc(cmp general.EqualsFunc[E], elems ...E)

func (*ComparableSlice[E]) Clip

func (s *ComparableSlice[E]) Clip()

func (*ComparableSlice[E]) CompactFunc

func (s *ComparableSlice[E]) CompactFunc(eq general.EqualsFunc[E])

func (ComparableSlice[E]) Contains

func (s ComparableSlice[E]) Contains(e E) bool

Contains reports whether s contains at least one element e

func (ComparableSlice[E]) ContainsAll

func (s ComparableSlice[E]) ContainsAll(elems ...E) bool

func (ComparableSlice[E]) ContainsFunc

func (s ComparableSlice[E]) ContainsFunc(f general.ContainsFunc[E]) bool

ContainsFunc reports whether at least one element e of s satisfies f(e).

func (ComparableSlice[E]) CopyAppend

func (s ComparableSlice[E]) CopyAppend(elems ...E) Slice[E]

func (ComparableSlice[E]) CopyAppendUniqueFunc

func (s ComparableSlice[E]) CopyAppendUniqueFunc(cmp general.EqualsFunc[E], elems ...E) ComparableSlice[E]

func (*ComparableSlice[E]) DeleteIndex

func (s *ComparableSlice[E]) DeleteIndex(i int)

func (*ComparableSlice[E]) DeleteRange

func (s *ComparableSlice[E]) DeleteRange(i, j int)

Delete removes the elements s[i:j] from s. Delete panics if j > len(s) or s[i:j] is not a valid slice of s. Delete is O(len(s)-i), so if many items must be deleted, it is better to make a single call deleting them all together than to delete one at a time. Delete zeroes the elements s[len(s)-(j-i):len(s)].

func (ComparableSlice[E]) Get

func (s ComparableSlice[E]) Get(i int) E

func (*ComparableSlice[E]) Grow

func (s *ComparableSlice[E]) Grow(n int)

func (ComparableSlice[E]) IndexFunc

func (s ComparableSlice[E]) IndexFunc(f general.ContainsFunc[E]) int

IndexFunc returns the first index i satisfying f(s[i]), or -1 if none do.

func (*ComparableSlice[E]) InsertIndex

func (s *ComparableSlice[E]) InsertIndex(i int, elems ...E)

func (ComparableSlice[E]) MaxFunc

func (s ComparableSlice[E]) MaxFunc(cmp func(a, b E) int)

func (ComparableSlice[E]) MinFunc

func (s ComparableSlice[E]) MinFunc(cmp func(a, b E) int)

func (*ComparableSlice[E]) Replace

func (s *ComparableSlice[E]) Replace(i, j int, v ...E)

func (ComparableSlice[E]) Set

func (s ComparableSlice[E]) Set(i int, e E)

func (ComparableSlice[E]) SortFunc

func (s ComparableSlice[E]) SortFunc(cmp general.CompareFunc[E])

func (ComparableSlice[E]) SortStableFunc

func (s ComparableSlice[E]) SortStableFunc(cmp general.CompareFunc[E])

type OrderedSlice

type OrderedSlice[E cmp.Ordered] Slice[E]

OrderedSlice if a slice with comparable elements. It offers additional convenience methods relying on the comparable feature.

func (*OrderedSlice[E]) Add

func (s *OrderedSlice[E]) Add(elems ...E)

func (*OrderedSlice[E]) AppendUnique

func (s *OrderedSlice[E]) AppendUnique(elems ...E)

func (*OrderedSlice[E]) Clip

func (s *OrderedSlice[E]) Clip()

func (*OrderedSlice[E]) Compact

func (s *OrderedSlice[E]) Compact()

func (*OrderedSlice[E]) CompactFunc

func (s *OrderedSlice[E]) CompactFunc(eq general.EqualsFunc[E])

func (OrderedSlice[E]) Contains

func (s OrderedSlice[E]) Contains(e E) bool

Contains reports whether s contains at least one element e

func (OrderedSlice[E]) ContainsAll

func (s OrderedSlice[E]) ContainsAll(elems ...E) bool

func (OrderedSlice[E]) ContainsFunc

func (s OrderedSlice[E]) ContainsFunc(f general.ContainsFunc[E]) bool

func (OrderedSlice[E]) CopyAppend

func (s OrderedSlice[E]) CopyAppend(elems ...E) OrderedSlice[E]

func (OrderedSlice[E]) CopyAppendUnique

func (s OrderedSlice[E]) CopyAppendUnique(elems ...E) OrderedSlice[E]

func (OrderedSlice[E]) CopyAppendUniqueFunc

func (s OrderedSlice[E]) CopyAppendUniqueFunc(cmp general.EqualsFunc[E], elems ...E) OrderedSlice[E]

func (*OrderedSlice[E]) DeleteIndex

func (s *OrderedSlice[E]) DeleteIndex(i int)

func (*OrderedSlice[E]) DeleteRange

func (s *OrderedSlice[E]) DeleteRange(i, j int)

func (OrderedSlice[E]) Get

func (s OrderedSlice[E]) Get(i int) E

func (*OrderedSlice[E]) Grow

func (s *OrderedSlice[E]) Grow(n int)

func (OrderedSlice[E]) Index

func (s OrderedSlice[E]) Index(e E) int

func (OrderedSlice[E]) IndexFunc

func (s OrderedSlice[E]) IndexFunc(f general.ContainsFunc[E]) int

func (OrderedSlice[E]) Max

func (s OrderedSlice[E]) Max() E

func (OrderedSlice[E]) MaxFunc

func (s OrderedSlice[E]) MaxFunc(cmp general.CompareFunc[E]) E

func (OrderedSlice[E]) Min

func (s OrderedSlice[E]) Min() E

func (OrderedSlice[E]) MinFunc

func (s OrderedSlice[E]) MinFunc(cmp general.CompareFunc[E]) E

func (*OrderedSlice[E]) Replace

func (s *OrderedSlice[E]) Replace(i, j int, v ...E)

func (OrderedSlice[E]) Set

func (s OrderedSlice[E]) Set(i int, e E)

func (OrderedSlice[E]) Sort

func (s OrderedSlice[E]) Sort()

func (OrderedSlice[E]) SortFunc

func (s OrderedSlice[E]) SortFunc(cmp general.CompareFunc[E])

func (OrderedSlice[E]) SortStableFunc

func (s OrderedSlice[E]) SortStableFunc(cmp general.CompareFunc[E])

type Slice

type Slice[E any] []E

Slice is a slice of an arbitrary type. It offers convenience methods.

func (*Slice[E]) Add

func (s *Slice[E]) Add(elems ...E)

Add appends element to the slice.

func (*Slice[E]) AppendUniqueFunc

func (s *Slice[E]) AppendUniqueFunc(cmp general.EqualsFunc[E], elems ...E)

func (*Slice[E]) Clip

func (s *Slice[E]) Clip()

func (*Slice[E]) CompactFunc

func (s *Slice[E]) CompactFunc(eq general.EqualsFunc[E])

func (Slice[E]) ContainsFunc

func (s Slice[E]) ContainsFunc(f general.ContainsFunc[E]) bool

ContainsFunc reports whether at least one element e of s satisfies f(e).

func (Slice[E]) CopyAppend

func (s Slice[E]) CopyAppend(elems ...E) Slice[E]

func (Slice[E]) CopyAppendUniqueFunc

func (s Slice[E]) CopyAppendUniqueFunc(cmp general.EqualsFunc[E], elems ...E) Slice[E]

func (*Slice[E]) DeleteIndex

func (s *Slice[E]) DeleteIndex(i int)

func (*Slice[E]) DeleteRange

func (s *Slice[E]) DeleteRange(i, j int)

Delete removes the elements s[i:j] from s. Delete panics if j > len(s) or s[i:j] is not a valid slice of s. Delete is O(len(s)-i), so if many items must be deleted, it is better to make a single call deleting them all together than to delete one at a time. Delete zeroes the elements s[len(s)-(j-i):len(s)].

func (Slice[E]) Get

func (s Slice[E]) Get(i int) E

func (*Slice[E]) Grow

func (s *Slice[E]) Grow(n int)

func (Slice[E]) IndexFunc

func (s Slice[E]) IndexFunc(f general.ContainsFunc[E]) int

IndexFunc returns the first index i satisfying f(s[i]), or -1 if none do.

func (*Slice[E]) InsertIndex

func (s *Slice[E]) InsertIndex(i int, elems ...E)

func (Slice[E]) MaxFunc

func (s Slice[E]) MaxFunc(cmp func(a, b E) int)

func (Slice[E]) MinFunc

func (s Slice[E]) MinFunc(cmp func(a, b E) int)

func (*Slice[E]) Replace

func (s *Slice[E]) Replace(i, j int, v ...E)

func (Slice[E]) Set

func (s Slice[E]) Set(i int, e E)

func (Slice[E]) SortFunc

func (s Slice[E]) SortFunc(cmp general.CompareFunc[E])

func (Slice[E]) SortStableFunc

func (s Slice[E]) SortStableFunc(cmp general.CompareFunc[E])

Jump to

Keyboard shortcuts

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