fns

package
v1.35.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MPL-2.0 Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any added in v1.35.3

func Any[A any](src []A, pred func(A) bool) bool

Any returns true if any element in src satisfies the predicate.

func CloseIgnore added in v1.25.0

func CloseIgnore(c io.Closer)

CloseIgnore closes c, ignoring any error. Its main use is to satisfy linters.

func Filter

func Filter[Elem any](src []Elem, fn func(Elem) bool) []Elem

Filter applies fn on all elements in src, producing a new slice containing the elements for which fn returned true, preserving the same order.

func Find added in v1.33.0

func Find[A any](src []A, pred func(A) bool) (A, bool)

Find returns the first element where pred returns true. The second argument is true if an element was found.

func FlatMap added in v1.35.3

func FlatMap[A, B any](src []A, fn func(A) []B) []B

FlatMap applies fn on all elements in src, producing a new slice with the results, in order.

func Map

func Map[A, B any](src []A, fn func(A) B) []B

Map applies fn on all elements in src, producing a new slice with the results, in order.

func MapAndFilter added in v1.35.3

func MapAndFilter[A, B any](src []A, fn func(A) (B, bool)) []B

MapAndFilter applies fn on all elements in src, producing a new slice with the results, in order. If fn returns false, the element is not included in the result.

func MapErr added in v1.35.3

func MapErr[A, B any](src []A, fn func(A) (B, error)) ([]B, error)

MapErr applies fn on all elements in src, producing a new slice with the results, in order. If fn returns an error, MapErr returns that error and the resulting slice is nil.

func MapKeys added in v1.25.0

func MapKeys[M ~map[K]V, K comparable, V any](m M) []K

MapKeys returns the keys of the map m. The keys will be in an indeterminate order.

func ToMap added in v1.35.3

func ToMap[K comparable, V any](src []V, key func(V) K) map[K]V

ToMap converts a slice to a map.

func TransformMapKeys added in v1.35.3

func TransformMapKeys[K1, K2 comparable, V any](m map[K1]V, fn func(K1) K2) map[K2]V

TransformMapKeys creates a new map with the same values as m, but with the keys transformed by fn.

func TransformMapToSlice added in v1.35.3

func TransformMapToSlice[K comparable, V any, R any](m map[K]V, fn func(K, V) R) []R

TransformMapToSlice creates a new slice with the results of applying fn to each key-value pair in m.

Types

This section is empty.

Jump to

Keyboard shortcuts

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