Documentation ¶
Index ¶
- func Apply[T any](s []T, f func(T) T) []T
- func FlatMap[X, Y any](s []X, f func(X) []Y) []Y
- func Flatten[X any](s [][]X) []X
- func Map[X, Y any](s []X, f func(X) Y) []Y
- func MapAny[X any](s []X) []any
- func Sort[T any](s []T, f Comparator[T])
- func Sorted[T any](s []T, f Comparator[T]) []T
- type Comparator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply[T any](s []T, f func(T) T) []T
Apply a function to every element in a slice, returning the parameter slice, whose elements may be mutated.
func FlatMap ¶ added in v1.28.0
func FlatMap[X, Y any](s []X, f func(X) []Y) []Y
FlatMap converts every element in an input slice to a countepart output slice by applying the specified function, then flatten the output slices into a single array of elements.
This is conceptually the equivalent of Flatten(Map(...))
func Flatten ¶ added in v1.28.0
func Flatten[X any](s [][]X) []X
Flatten creates a new output slice that contains the elements from the specified input slices.
func Map ¶
func Map[X, Y any](s []X, f func(X) Y) []Y
Map converts every element in an input slice to a countepart output element by applying the specified function.
func MapAny ¶ added in v1.30.0
MapAny converts every element in an input slice to a countepart output element containing the same input but cast to any/interface{}. This is a special case of Map which provides a convenience for a common use case.
func Sort ¶ added in v1.20.0
func Sort[T any](s []T, f Comparator[T])
Sort a slice in place by appying the specified comparator function to elements.
func Sorted ¶ added in v1.20.0
func Sorted[T any](s []T, f Comparator[T]) []T
Sort a copy of a slice by appying the specified comparator function to elements. The sorted copy is returned.
Types ¶
type Comparator ¶ added in v1.20.0
Comparator evalutes two arguments of the same type and returns an integer value describing how they compare, returning:
- 1 if a > b
- 0 if the elements are equal
- -1 if a < b