slices

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MPL-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T any](s []T, fn func(T) bool) bool

Contains reports whether v is present in s.

func Copy

func Copy[S ~[]V, V any](s S, n int) S

Copy returns a slice of V with the last n elements removed.

func Filter

func Filter[S ~[]T, T any](slc S, fn func(T) bool) S

Filter returns a slice containing all the elements of s that satisfy fn.

func FilterInPlace

func FilterInPlace[S ~[]V, V any](slc S, fn func(V) bool) S

FilterInPlace filters the slice in place.

func FlatMap

func FlatMap[T, R any](slc []T, fn func(T) []R) []R

FlatMap applies the function fn to each element of the slice and returns a new slice with the results. It flattens the result of fn into the result slice.

func IndexFunc

func IndexFunc[T any](slc []T, fn func(T) bool) int

IndexFunc returns the first index satisfying fn(slc[i]), or -1 if none do.

func Map

func Map[T, R any](slc []T, fn func(T) R) []R

Map applies the function fn to each element of the slice and returns a new slice with the results.

func ToMap

func ToMap[T any, K comparable, V any](slc []T, fn func(T) (K, V)) map[K]V

ToMap converts a slice to a map.

func ToSet

func ToSet[T comparable](slc []T) map[T]struct{}

ToSet converts a slice to a set.

func ToSetFunc

func ToSetFunc[T any, K comparable](slc []T, fn func(T) K) map[K]struct{}

ToSetFunc converts a slice to a set using the function fn.

Types

This section is empty.

Jump to

Keyboard shortcuts

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