Documentation
¶
Overview ¶
Package slices implements generic (type-parameterized) utilities for working with simple Go slices.
Index ¶
- func Contains[T comparable](needle T, haystack []T) bool
- func Max[T constraints.Ordered](a T, rest ...T) T
- func Min[T constraints.Ordered](a T, rest ...T) T
- func RemoveAll[T comparable](haystack []T, needle T) []T
- func RemoveAllFunc[T any](haystack []T, f func(T) bool) []T
- func Reverse[T any](slice []T)
- func Search[T any](slice []T, fn func(T) int) (int, bool)
- func SearchHighest[T any](slice []T, fn func(T) int) (int, bool)
- func SearchLowest[T any](slice []T, fn func(T) int) (int, bool)
- func Sort[T constraints.Ordered](slice []T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](needle T, haystack []T) bool
func Max ¶
func Max[T constraints.Ordered](a T, rest ...T) T
func Min ¶
func Min[T constraints.Ordered](a T, rest ...T) T
func RemoveAll ¶
func RemoveAll[T comparable](haystack []T, needle T) []T
func Search ¶
Search searches the slice for a value for which `fn(slice[i]) = 0`.
: + + + 0 0 0 - - - : ^ ^ ^ : any of
You can conceptualize `fn` as subtraction:
func(straw T) int { return needle - straw }
func SearchHighest ¶
SearchHighest searches the slice for the right-most value for which `fn(slice[i]) = 0`.
: + + + 0 0 0 - - - : ^
You can conceptualize `fn` as subtraction:
func(straw T) int { return needle - straw }
func SearchLowest ¶
SearchLowest searches the slice for the left-most value for which `fn(slice[i]) = 0`.
: + + + 0 0 0 - - - : ^
You can conceptualize `fn` as subtraction:
func(straw T) int { return needle - straw }
func Sort ¶
func Sort[T constraints.Ordered](slice []T)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.