Documentation
¶
Overview ¶
Package slices provides generic slice utility functions.
Index ¶
- func Difference[S ~[]E, E comparable](a, b S) S
- func Filter[S ~[]E, E any](s S, p ...func(e E) bool) S
- func Intersection[S ~[]E, E comparable](a, b S) S
- func Map[AS ~[]A, BS ~[]B, A, B any](as AS, fn func(a A) B) BS
- func Subset[S ~[]E, E comparable](a, b S) bool
- func Sum[S ~[]E, E constraints.Ordered](s S) E
- func Union[S ~[]E, E comparable](a, b S) S
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Difference ¶ added in v1.1.0
func Difference[S ~[]E, E comparable](a, b S) S
Difference returns all the elements in 'a' that are not in 'b'.
NOTE: The provided slices may contain duplicates but the returned slice will not.
func Filter ¶
Filter removes all elements in the given slice that do not match the given predicates.
NOTE: Providing no predicates results in a no-op.
func Intersection ¶ added in v1.1.0
func Intersection[S ~[]E, E comparable](a, b S) S
Intersection returns all the elements that are in both 'a' and 'b'.
NOTE: The provided slices may contain duplicates but the returned slice will not.
func Map ¶ added in v1.2.0
func Map[AS ~[]A, BS ~[]B, A, B any](as AS, fn func(a A) B) BS
Map applies the given function to each element of the provided slice.
func Subset ¶
func Subset[S ~[]E, E comparable](a, b S) bool
Subset returns a boolean indicating whether a, is a subset of b.
NOTE: Returns true if a has zero elements since an empty set is a subset of all sets.
func Sum ¶
func Sum[S ~[]E, E constraints.Ordered](s S) E
Sum returns the summation of the elements in the provided slice.
func Union ¶
func Union[S ~[]E, E comparable](a, b S) S
Union returns all the elements that are in either 'a' or 'b'.
NOTE: The provided slices may contain duplicates but the returned slice will not.
Types ¶
This section is empty.