slice

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any added in v0.2.7

func Any[T comparable](slice []T, value T) bool

Any returns true if any element of the given slice is equal to the given value.

func AnyF added in v0.2.7

func AnyF[T any](slice []T, fn func(T) (bool, error)) (result bool, err error)

AnyF returns true if any element of the given slice satisfies the given function.

func FastRemove added in v0.3.0

func FastRemove[T any](slice []T, index int) []T

FastRemove removes the element at the given index from the given slice. The order of the elements is not preserved. More efficient than Remove.

func Filter

func Filter[T any](slice []T, fn func(T) (bool, error)) (result []T, err error)

Filter returns a new slice containing only the elements of the given slice for which the given function returns true.

func Find added in v0.2.7

func Find[T any](slice []T, fn func(T) (bool, error)) (result T, ok bool, err error)

Find returns the first element of the given slice for which the given function returns true.

func Findi added in v0.2.7

func Findi[T any](slice []T, fn func(T) (bool, error)) (result int, ok bool, err error)

Findi returns the index of the first element of the given slice for which the given function returns true.

func Map

func Map[TIn any, TOut any](slice []TIn, fn func(TIn) (TOut, error)) (result []TOut, err error)

Map returns a new slice with the results of applying the given function to each element of the given slice.

func Remove added in v0.2.7

func Remove[T any](slice []T, index int) []T

Remove removes the element at the given index from the given slice.

func RemoveF added in v0.3.0

func RemoveF[T any](slice []T, fn func(T) (bool, error)) (result []T, ok bool, err error)

RemoveF removes the first element of the given slice for which the given function returns true.

func Reverse

func Reverse[T generics.LTGTConstraint](slice []T) error

Reverse sorts the given slice in descending order. The type parameter must be a native number type.

func Sort

func Sort[T generics.LTGTConstraint](slice []T) error

Sort sorts the given slice in ascending order. The type parameter must be a native number type.

func SortF

func SortF[T any](slice []T, fn func(T, T) (bool, error)) error

SortF sorts the given slice using the given function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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