Documentation ¶
Overview ¶
Package xslices contains a utility functions to work with slices.
Index ¶
- func CopyN[S ~[]V, V any](s S, n int) S
- func Filter[S ~[]T, T any](slc S, fn func(T) bool) S
- func FilterInPlace[S ~[]V, V any](slc S, fn func(V) bool) S
- func FlatMap[T, R any](slc []T, fn func(T) []R) []R
- func Map[T, R any](slc []T, fn func(T) R) []R
- func ToMap[T any, K comparable, V any](slc []T, fn func(T) (K, V)) map[K]V
- func ToSet[T comparable](slc []T) map[T]struct{}
- func ToSetFunc[T any, K comparable](slc []T, fn func(T) K) map[K]struct{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyN ¶
CopyN copies first n elements. If n is greater than the length of the slice, it will copy the whole slice.
func FilterInPlace ¶
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 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 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.
Click to show internal directories.
Click to hide internal directories.