slices

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 1 Imported by: 1

Documentation

Index

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

func MapAny[X any](s []X) []any

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

type Comparator[T any] func(a, b T) int

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

Jump to

Keyboard shortcuts

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