Documentation
¶
Overview ¶
Package constraints defines a set of useful constraints to be used with type parameters.
Package gen contains a bunch of generic functions that will probably be in the Go std lib someday
Index ¶
- func Abs[T Integer | Float](a T) T
- func Clamp[T Ordered](v, min, max T) T
- func CopyMap[K comparable, V any](src map[K]V) map[K]V
- func CopySlice[T any](src []T) []T
- func DeleteFirst[T comparable](slice []T, elem T) []T
- func DeleteFromSliceOrdered[T any](src []T, i int) []T
- func DeleteFromSliceUnordered[T any](src []T, i int) []T
- func DrainChannel[T any](ch chan T)
- func DrainChannelIntoSlice[T any](ch chan T) []T
- func Filter[T any](items []T, predicate func(T) bool) []T
- func IndexOf[T comparable](src []T, v T) int
- func IsChannelClosed[T any](ch chan T) bool
- func Max[T Ordered](a, b T) T
- func Min[T Ordered](a, b T) T
- func Mode[T comparable](src []T) (mode T, count int)
- func WaitForChannelToClose[T any](ch chan T)
- type Complex
- type Float
- type Integer
- type Ordered
- type Signed
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteFirst ¶
func DeleteFirst[T comparable](slice []T, elem T) []T
Finds an element in the slice and returns a copy with that element removed. If the element does not exist, returns the original slice. If the element exists more than once, removes only the first one.
func DeleteFromSliceOrdered ¶
Deletes the i'th element of the slice, and returns a new slice. Preserves order, but is much slower than DeleteFromSliceUnordered.
func DeleteFromSliceUnordered ¶
Deletes the i'th element of the slice, and returns a new slice. Does not preserve order, but is much faster than DeleteFromSliceOrdered.
func DrainChannelIntoSlice ¶
func DrainChannelIntoSlice[T any](ch chan T) []T
DrainChannelIntoSlice reads from a channel until it is empty, and returns all items in a slice
func Filter ¶
Filter takes a slice of any type and a predicate function, returning a new slice with only the elements that satisfy the predicate.
func IndexOf ¶
func IndexOf[T comparable](src []T, v T) int
Returns the index of the first 'v' in 'src', or -1 if not found
func IsChannelClosed ¶
func Mode ¶
func Mode[T comparable](src []T) (mode T, count int)
func WaitForChannelToClose ¶
func WaitForChannelToClose[T any](ch chan T)
Types ¶
type Complex ¶
type Complex interface {
~complex64 | ~complex128
}
Complex is a constraint that permits any complex numeric type. If future releases of Go add new predeclared complex numeric types, this constraint will be modified to include them.
type Float ¶
Float is a constraint that permits any floating-point type. If future releases of Go add new predeclared floating-point types, this constraint will be modified to include them.
type Integer ¶
Integer is a constraint that permits any integer type. If future releases of Go add new predeclared integer types, this constraint will be modified to include them.
type Ordered ¶
Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.