slice

package
v10.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 0 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 S)

AppendAllMissing appends all elements of `additional` that aren't contained in `existing` to `existing`.

func Contains

func Contains[C comparable](list []C, value C) bool

Contains returns 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 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)

Hoist moves the given element in the given slice to the first position.

func Remove

func Remove[S ~[]C, C comparable](list *S, value C)

Remove removes the given element from the given slice.

func RemoveAt

func RemoveAt[S ~[]C, C comparable](list *S, index int)

RemoveAt removes the element at the given position from the given list.

func TruncateLast

func TruncateLast[S ~[]C, C comparable](list *S)

TruncateLast removes the last element from the given list.

Types

This section is empty.

Jump to

Keyboard shortcuts

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