Documentation
¶
Index ¶
- func Assert(err error)
- func BContains[T comparable](xs []T, x T) bool
- func BSearch[T comparable](xs []T, x T) int
- func Compose[A, B, C any](f func(A) B, g func(B) C) func(A) C
- func Compose3[A, B, C, D any](f func(A) B, g func(B) C, h func(C) D) func(A) D
- func Contains[T comparable](xs []T, x T) bool
- func Filter[T any](f func(T) bool, xs []T) []T
- func GroupBy[T any, K comparable](f func(T) K, xs []T) map[K][]T
- func Map[A, B any](f func(A) B, xs []A) []B
- func MapKeys[K comparable, V any](m map[K]V) (keys []K)
- func MapValues[K comparable, V any](m map[K]V) (values []V)
- func Must[T any](x T, err error) T
- func Must2[T1, T2 any](x1 T1, x2 T2, err error) (T1, T2)
- func Reduce[A, V any](f func(A, V) A, acc A, xs []V) A
- func SlicePop[T any](xs []T, idx int) ([]T, T)
- func Sort[T constraints.Ordered](xs []T)
- func SortBy[T any, K constraints.Ordered](xs []T, f func(T) K)
- func Sorted[T constraints.Ordered](xs []T) []T
- func Uniq[T comparable](xs []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BContains ¶
func BContains[T comparable](xs []T, x T) bool
Check if xs (which must be sorted) contains x, using binary search.
func BSearch ¶
func BSearch[T comparable](xs []T, x T) int
Search for the position of x in xs, using binary search. The input slice xs must be sorted. Return len(xs) if no match is found.
func Compose ¶
func Compose[A, B, C any](f func(A) B, g func(B) C) func(A) C
Create a function that composes f and g into a single function n, such that n(x) = g(f(x)).
func Compose3 ¶
func Compose3[A, B, C, D any](f func(A) B, g func(B) C, h func(C) D) func(A) D
Create a function that composes f, g and h into a single function n, such that n(x) = h(g(f(x))).
func Contains ¶
func Contains[T comparable](xs []T, x T) bool
Check if x exists in xs (linear time).
func GroupBy ¶
func GroupBy[T any, K comparable](f func(T) K, xs []T) map[K][]T
Group xs by key function f into a map of arrays. Relative order of xs in map values is preserved.
func Map ¶
func Map[A, B any](f func(A) B, xs []A) []B
Apply f to each element in xs and return an array with the results.
func MapValues ¶
func MapValues[K comparable, V any](m map[K]V) (values []V)
Return the values in the map.
func Reduce ¶
func Reduce[A, V any](f func(A, V) A, acc A, xs []V) A
Reduce the array of xs into an accumulator value using reducer f.
func SortBy ¶
func SortBy[T any, K constraints.Ordered](xs []T, f func(T) K)
Sort xs in place, comparing elements using keyfunc f.
func Uniq ¶
func Uniq[T comparable](xs []T) []T
Return only unique values in xs, disregarding order.
Types ¶
This section is empty.