Documentation ¶
Index ¶
- func Batch[D any, R any](req []D, f func([]D) (R, error), batchSize int, failOnErr bool) ([]R, []error)
- func Clamp[T constraints.Ordered](x, min, max T) T
- func Contains[T comparable, S ~[]T](s S, e T) bool
- func Deref[T any](p *T) T
- func EqualSlices[T comparable, S ~[]T](s1, s2 S) bool
- func FilterSlice[T any, S ~[]T](s S, f func(T) bool) S
- func Max[T constraints.Ordered](t1, t2 T) T
- func Min[T constraints.Ordered](t1, t2 T) T
- func Ptr[T any](t T) *T
- func RemoveDupes[T comparable, S ~[]T](s S) S
- func ReverseSlice[T any, S ~[]T](s S) S
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Batch ¶
func Batch[D any, R any](req []D, f func([]D) (R, error), batchSize int, failOnErr bool) ([]R, []error)
Batch can call the function f with batches of slice sl in sizes of batchSize. If failOnErr is true, it returns all responses and errors so far upon the first returned error from the function.
func Clamp ¶ added in v0.0.7
func Clamp[T constraints.Ordered](x, min, max T) T
Clamp returns the value of x clamped to the range [min, max]. If max is less than min, the function will return max, no checks are performed to ensure that min is less than max.
func Contains ¶
func Contains[T comparable, S ~[]T](s S, e T) bool
Contains checks if the slice contains the given element.
func Deref ¶
func Deref[T any](p *T) T
Deref returns the underlying value of the pointer. If it is nil, it returns a newly initialized type.
func EqualSlices ¶
func EqualSlices[T comparable, S ~[]T](s1, s2 S) bool
EqualSlices checks if two slices of comparable types are equal. From personal testing, this seems to be faster than reflect.DeepEqual(), but this has not been tested thoroughly.
func FilterSlice ¶
FilterSlice filters a slice by passed function. The passed function should return true to keep item, and false to remove it.
func Max ¶
func Max[T constraints.Ordered](t1, t2 T) T
Max compares two variables and returns the largest of them. When passing strings, this returns the lexically last one.
func Min ¶
func Min[T constraints.Ordered](t1, t2 T) T
Min compares two variables and returns the smallest of them. When passing strings, this returns the lexically first one.
func RemoveDupes ¶
func RemoveDupes[T comparable, S ~[]T](s S) S
RemoveDupes removes duplicates from a slice, order is preserved.
func ReverseSlice ¶
func ReverseSlice[T any, S ~[]T](s S) S
ReverseSlice reverses the order of the elements in the array passed.
Types ¶
This section is empty.