Documentation
¶
Overview ¶
Package slices provides utilities to manipulate slices.
Index ¶
- func Clone[S ~[]E, E any](s S) S
- func Contains[S ~[]T, T comparable](s S, t T) bool
- func Equal[S ~[]T, T comparable](s1, s2 S) bool
- func Filter[S ~[]T, T any](s S, f func(T) bool) []T
- func FilterAndMap[S ~[]T, T any, O any](s S, f func(T) (O, bool)) []O
- func Find[S ~[]T, T any](s S, f func(T) bool) (t T, ok bool)
- func GroupBy[S ~[]T, T any, K comparable](s S, f func(T) K) map[K][]T
- func Map[S ~[]T, T any, O any](s S, f func(T) O) []O
- func MapWithError[S ~[]T, T any, O any](s S, f func(T) (O, error)) ([]O, error)
- func Reverse[S ~[]T, T any](s S) []T
- func Unique[S ~[]T, T comparable](s S) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶ added in v0.2.0
func Contains[S ~[]T, T comparable](s S, t T) bool
Contains returns true if the slice contains the given element.
func Equal ¶ added in v0.3.0
func Equal[S ~[]T, T comparable](s1, s2 S) bool
Equal returns true if the two slices are equal.
func Filter ¶
Filter returns a new slice containing all elements in the slice that satisfy the predicate f.
func FilterAndMap ¶ added in v0.4.0
FilterAndMap returns a new slice containing the results of applying the given function to all elements in the slice that satisfy the predicate f.
func GroupBy ¶ added in v0.5.0
func GroupBy[S ~[]T, T any, K comparable](s S, f func(T) K) map[K][]T
GroupBy returns a map of slices grouped by the given function.
func MapWithError ¶ added in v0.4.0
MapWithError returns a new slice containing the results of applying the given function to all elements in the slice that satisfy the predicate f.
func Reverse ¶ added in v0.3.0
func Reverse[S ~[]T, T any](s S) []T
Reverse returns a new slice containing the elements of the slice in reverse order.
func Unique ¶ added in v0.3.0
func Unique[S ~[]T, T comparable](s S) []T
Unique returns a new slice containing only the unique elements in the slice.
Types ¶
This section is empty.