books

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 2 Imported by: 0

README

Books

GoDoc Go ReportCard

This is just a small library of commonly used Golang utility functions!

Each function is designed to be as widely available as possible, utilizing generics wherever possible.

Docs

Read full documentation here.

Documentation

Index

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

func FilterSlice[T any, S ~[]T](s S, f func(T) bool) S

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 Ptr

func Ptr[T any](t T) *T

Ptr takes any type and returns a pointer to it.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL