slices

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MPL-2.0 Imports: 1 Imported by: 0

README

Generic Slice Functions

Complements golang.org/x/exp/slices.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](s []T, f Predicate[T]) bool

All returns `true` if the filter function `f` retruns `true` for all items

func Any

func Any[T any](s []T, f Predicate[T]) bool

Any returns `true` if the filter function `f` retruns `true` for any item

func AppendUnique

func AppendUnique[T comparable](s []T, vs ...T) []T

AppendUnique appends unique (not already in the slice) values to a slice.

func ApplyToAll

func ApplyToAll[T, U any](s []T, f func(T) U) []U

ApplyToAll returns a new slice containing the results of applying the function `f` to each element of the original slice `s`.

func Chunks

func Chunks[S ~[]E, E any](s S, size int) []S

Chunks returns a slice of S, each of the specified size (or less).

func Filter

func Filter[T any](s []T, f Predicate[T]) []T

Filter returns a new slice containing all values that return `true` for the filter function `f`

func RemoveAll

func RemoveAll[E comparable](s []E, r E) []E

RemoveAll removes all occurrences of the specified value from a slice.

func Reverse

func Reverse[S ~[]E, E any](s S) S

Reverse returns a reversed copy of the slice.

Types

type Predicate

type Predicate[T any] func(T) bool

Predicate represents a predicate (boolean-valued function) of one argument.

func PredicateEquals

func PredicateEquals[T comparable](v T) Predicate[T]

PredicateEquals returns a Predicate that evaluates to true if the predicate's argument equals `v`.

func PredicateTrue

func PredicateTrue[T any]() Predicate[T]

PredicateTrue returns a Predicate that always evaluates to true.

Jump to

Keyboard shortcuts

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