slice

package
v12.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 5 Imported by: 0

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

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 added in v12.0.2

func NaturalSort[T fmt.Stringer](list []T) []T

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 added in v12.0.2

type WindowArgs struct {
	CursorPos    int
	ElementCount int
	WindowSize   int
}

type WindowResult added in v12.0.2

type WindowResult struct {
	EndRow   int
	StartRow int
}

func Window added in v12.0.2

func Window(args WindowArgs) WindowResult

Window provides the largest window in a collection with the given number of elements around the given cursor position.

Jump to

Keyboard shortcuts

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