Documentation ¶
Overview ¶
Package slice provides generic functions to work with slices. Ideally this package will be replaced by a properly written and tested third-party package.
Index ¶
- func AppendAllMissing[S ~[]C, C comparable](existing S, additional ...C) S
- func Contains[C comparable](list []C, value C) bool
- func FindAll[C comparable](list []C, element C) []int
- func FindMany[S ~[]C, C comparable](haystack S, needles S) []int
- func FirstElementOr[C comparable](list []C, alternative C) C
- func Hoist[S ~[]C, C comparable](list S, needle C) S
- func NaturalSort[T fmt.Stringer](list []T) []T
- func Remove[S ~[]C, C comparable](list S, value C) S
- func RemoveAt[S ~[]C, C comparable](list S, indexes ...int) S
- func TruncateLast[S ~[]C, C comparable](list S) S
- type WindowArgs
- type WindowResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendAllMissing ¶
func AppendAllMissing[S ~[]C, C comparable](existing S, additional ...C) S
AppendAllMissing provides the given list with all missing elements of `additional` appended.
func Contains ¶
func Contains[C comparable](list []C, value C) bool
Contains indicates whether the given slice contains the given element.
func FindAll ¶
func FindAll[C comparable](list []C, element C) []int
FindAll provides the indexes of all occurrences of the given element in the given list.
func FindMany ¶
func FindMany[S ~[]C, C comparable](haystack S, needles S) []int
FindMany provides the indixes of all needles in the give haystack.
func FirstElementOr ¶
func FirstElementOr[C comparable](list []C, alternative C) C
FirstElementOr provides the first element of the given list or the given alternative if the list is empty.
func Hoist ¶
func Hoist[S ~[]C, C comparable](list S, needle C) S
Hoist provides the given list with the given element moved to the first position.
func NaturalSort ¶
sorts the given elements in natural sort order (https://en.wikipedia.org/wiki/Natural_sort_order)
func Remove ¶
func Remove[S ~[]C, C comparable](list S, value C) S
Remove provides the given list without the given element.
func RemoveAt ¶
func RemoveAt[S ~[]C, C comparable](list S, indexes ...int) S
RemoveAt provides the given list without the elements at the given positions.
func TruncateLast ¶
func TruncateLast[S ~[]C, C comparable](list S) S
TruncateLast provides the given list without its last element.
Types ¶
type WindowArgs ¶
type WindowResult ¶
func Window ¶
func Window(args WindowArgs) WindowResult
Window provides the largest window in a collection with the given number of elements around the given cursor position.