slices

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 0 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect added in v0.1.1

func Collect[S any, T any](s []S, f func(S) T) (r []T)

Collect (map) slice through given function.

func Contains

func Contains[T comparable](s []T, x T) bool

Check if slice contains given element.

func Equal

func Equal[T comparable](s []T, t []T) bool

Compare two slices of comparable elements.

func EqualBy

func EqualBy[S any, T any](s []S, t []T, f func(S, T) bool) bool

Compare two slices by a given equality function.

func Remove

func Remove[T comparable](s []T, x T) (r []T)

Remove all occurrences of given element from slice (and return new slice; old slice remains unchanged).

func Reverse

func Reverse[T any](s []T) (r []T)

Reverse slice.

func Sort

func Sort[T Orderable](s []T) []T

Sort slice of orderable elements.

func SortBy

func SortBy[T any](s []T, f func(x, y T) bool) (r []T)

Sort slice by given comparator function. The comparator function f(x,y) must return true if x is larger than y, and false if x is smaller than y; the return value in case of equality does not matter (may be true or false).

func Uniq

func Uniq[T comparable](s []T) (r []T)

Remove duplicates from slice of comparable elements.

Types

type Orderable

type Orderable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
}

Orderable constraint.

Jump to

Keyboard shortcuts

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