slices

package
v0.0.0-...-8e7861b Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[T any](slice []T, f func(T) bool) []T

Applies the predicate f to each element of slice in order, and returns those elements that satisfy f.

func FilterIndex

func FilterIndex[T any](slice []T, f func(int, T) bool) []T

Like Filter, but f also takes in the element's index.

func FilterIndexWithErr

func FilterIndexWithErr[T any](slice []T, f func(int, T) (bool, error)) ([]T, error)

Like FilterWithErr, but f also takes in the element's index.

func FilterMap

func FilterMap[T1, T2 any](slice []T1, f func(T1) optionals.Optional[T2]) []T2

Applies f to each element of slice in order, removes any None results, and returns the rest.

func FilterMapIndex

func FilterMapIndex[T1, T2 any](slice []T1, f func(int, T1) optionals.Optional[T2]) []T2

Like FilterMap, but f also takes in the element's index.

func FilterMapIndexWithErr

func FilterMapIndexWithErr[T1, T2 any](slice []T1, f func(int, T1) (optionals.Optional[T2], error)) ([]T2, error)

Like FilterMapWithErr, but f also takes in the element's index.

func FilterMapWithErr

func FilterMapWithErr[T1, T2 any](slice []T1, f func(T1) (optionals.Optional[T2], error)) ([]T2, error)

Applies f to each element of slice in order, removes any None results, and returns the rest. If f returns a non-nil error on any element, iteration immediately stops, and the error is returned.

func FilterWithErr

func FilterWithErr[T any](slice []T, f func(T) (bool, error)) ([]T, error)

Applies the predicate f to each element of slice in order, and returns those elements that satisfy f. If f returns a non-nil error on any element, iteration immediately stops, and the error is returned.

func Map

func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2

Apply f to each element of slice in order, returning the results.

func MapIndex

func MapIndex[T1, T2 any](slice []T1, f func(int, T1) T2) []T2

Like Map, but f also takes in the element's index.

func MapIndexWithErr

func MapIndexWithErr[T1, T2 any](slice []T1, f func(int, T1) (T2, error)) (rv []T2, err error)

Like MapWithErr, but f also takes in the element's index.

func MapWithErr

func MapWithErr[T1, T2 any](slice []T1, f func(T1) (T2, error)) (rv []T2, err error)

Apply f to each element of slice in order, returning the results. If f returns a non-nil error on any element, iteration immediately stops, and the error is returned.

func Reverse

func Reverse[T any](s []T) []T

Returns a new slice with elements from s in reverse order.

Types

This section is empty.

Jump to

Keyboard shortcuts

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