Documentation ¶
Index ¶
- func AllOf[T any](elems []T, pred func(elem T) bool) bool
- func AnyOf[T any](elems []T, pred func(elem T) bool) bool
- func BinarySearch[T constraints.Ordered](elems []T, target T) (index int)
- func CountIf[T any](elems []T, pred func(elem T) bool) (count int)
- func Filter[T any](elems []T, p func(T) bool) (r []T)
- func FilterNot[T any](elems []T, p func(T) bool) (r []T)
- func FindIf[T any](elems []T, pred func(elem T) bool) int
- func Map[T any, U any](elems []T, f func(T) U) (r []U)
- func Max[T constraints.Ordered](x, y T) T
- func Merge[T constraints.Ordered](left, right []T) (sorted []T)
- func Min[T constraints.Ordered](x, y T) T
- func NoneOf[T any](elems []T, pred func(elem T) bool) bool
- func ProdSlice[T constraints.Integer | constraints.Float](elems []T) T
- func Reduce[T any, U any](elems []T, f func(a U, b T) U, initial U) (r U)
- func SumSlice[T constraints.Ordered](elems []T) T
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllOf ¶
AllOf returns true if and only if all of the elements in the slice satisfy the given predicate.
func AnyOf ¶
AnyOf returns true if and only if at least one of the elements in the slice satisfy the given predicate.
func BinarySearch ¶
func BinarySearch[T constraints.Ordered](elems []T, target T) (index int)
BinarySearch returns the index of the given target in the provided sorted elems slice. If the target is not in the sorted slice, -1 is returned.
func CountIf ¶
CountIf returns the number of elements in the slice that satisfy the given predicate.
func FilterNot ¶
Filter returns all elements that do NOT satisfy the given predicate in a new slice.
func FindIf ¶
FindIf returns the index to the first element in the slice that satisfies the given predicate. If no such element exists, -1 is returned.
func Max ¶
func Max[T constraints.Ordered](x, y T) T
func Merge ¶
func Merge[T constraints.Ordered](left, right []T) (sorted []T)
Merge merges the two provided sorted slices into a single sorted slice.
func Min ¶
func Min[T constraints.Ordered](x, y T) T
func NoneOf ¶
NoneOf returns true if and only if none of the elements in the slice satisfy the given predicate.
func ProdSlice ¶
func ProdSlice[T constraints.Integer | constraints.Float](elems []T) T
ProdSlice returns the product of all the elemenst in the given slice. No attempt is made to detect overflow.
func Reduce ¶
Reduce reduces the given slice to a single value using the given function and initial value.
func SumSlice ¶
func SumSlice[T constraints.Ordered](elems []T) T
SumSlice returns the sum of all the elements in the given slice. No attempt is made to detect overflow.