common

package
v6.0.0-...-d29ee10 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsInterfaceSlice

func AsInterfaceSlice[T any](in []T) []interface{}

func Max

func Max[T cmp.Ordered](i1 T, rest ...T) T

Max returns the greatest item of all supplied

func Min

func Min[T cmp.Ordered](i1 T, rest ...T) T

Min returns the minimum item of all supplied

func PartitionSliceByLength

func PartitionSliceByLength[T comparable](items []T, maxItems int) [][]T

PartitionSliceByLength partitions a slice into multiple slices of up to `maxItems` size

func PointerOf

func PointerOf[T any](x interface{}) *T

PointerOf performs a type-assertion to T and returns a pointer if successful, nil otherwise.

func Ref

func Ref[T any](x T) *T

Ref creates a copy of `x` in heap and returns a pointer to it

func RefOrNil

func RefOrNil[T comparable](x T) *T

RefOrNil returns a pointer to the value supplied if it's not the default value, nil otherwise

func UnorderedDedupedCopy

func UnorderedDedupedCopy[T comparable](items []T) []T

DedupeInNewSlice creates a new slice from `items` without duplicate elements

func ValueOr

func ValueOr[T comparable](in T, fallback T) T

ValueOr returns the supplied value if it has something other than the default value for type T. Returns `fallback` otherwise

func WithAttempts

func WithAttempts(attempts int, main func() error) error

WithAttempts executes a function N times or until no error is returned

func WithBackoff

func WithBackoff(duration time.Duration, main func() error) func() error

WithBackoff wraps the function to add Exponential backoff

func WithBackoffCancelling

func WithBackoffCancelling(unit time.Duration, max time.Duration, main func() bool) func()

WithBackoffCancelling wraps the function to add Exponential backoff

Types

This section is empty.

Jump to

Keyboard shortcuts

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