slices

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 1 Imported by: 2

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 Map

func Map[X, Y any](s []X, f func(X) Y) []Y

Map every element in an input slice to a countepart output element by applying the specified function.

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