sliceutil

package
v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert[A, B any, S ~[]B](v S) []A

Convert converts a slice of type B to a slice of type A. Convert panics if B cannot be type asserted to type A.

func DeleteVal

func DeleteVal[E any](s []E, v E) []E

DeleteVal deletes the first occurrence of a value in a slice of the type E and returns a new slice without the value.

func Filter added in v0.8.0

func Filter[E any](s []E, c func(E) bool) []E

Filter iterates over elements of collection, returning an array of all elements function c returns true for.

func Index

func Index[E any](s []E, v E) int

Index returns the index of the first occurrence of v in s, or -1 if not present. Index accepts any type, as opposed to slices.Index, but might panic if E is not comparable.

func SearchValue added in v0.8.4

func SearchValue[A any, S ~[]A](v S, f func(a A) bool) (a A, ok bool)

SearchValue iterates through slice v, calling function f for every element. If true is returned in this function, the respective element is returned and ok is true. If the function f does not return true for any element, false is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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