slices

package
v0.0.0-...-a02f6fc Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](ts []T, needle T) bool

func Filter

func Filter[T any](ts []T, predicate func(t T) bool) []T

Filter returns a slice containing all the elements of ts for which the passed in predicate returns true. If no items match the predicate, the function will return an empty slice. If ts is nil, the function will also return nil.

func FindWhere

func FindWhere[T comparable](ts []T, predicate func(t T) bool) (T, bool)

func Flatten

func Flatten[T any](tss [][]T) []T

func ForEachWithError

func ForEachWithError[T any](ts []T, fn func(t T) error) error

ForEachWithError runs the passed in function for each element of T. If an error is encountered, the error is returned immediately and any subsequence elements will not be processed.

func Map

func Map[T, U any](ts []T, fn func(t T) U) (us []U)

Map returns a new slice containing the elements of ts transformed by the passed in function.

func MapWithError

func MapWithError[T, U any](ts []T, fn func(t T) (U, error)) (us []U, err error)

Map returns a new slice containing the elements of ts transformed by the passed in function, which can either either a mapped value of U, or an error. If the mapping function returns an error, MapWithError will return nil and the returned error.

func Uniq

func Uniq[T comparable](ts []T) []T

Types

This section is empty.

Jump to

Keyboard shortcuts

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