Documentation
¶
Index ¶
- func Contains[T comparable](ts []T, needle T) bool
- func Filter[T any](ts []T, predicate func(t T) bool) []T
- func FindWhere[T comparable](ts []T, predicate func(t T) bool) (T, bool)
- func Flatten[T any](tss [][]T) []T
- func ForEachWithError[T any](ts []T, fn func(t T) error) error
- func Map[T, U any](ts []T, fn func(t T) U) (us []U)
- func MapWithError[T, U any](ts []T, fn func(t T) (U, error)) (us []U, err error)
- func Uniq[T comparable](ts []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](ts []T, needle T) bool
func Filter ¶
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 ForEachWithError ¶
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 ¶
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.