utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptions

func ApplyOptions[C any, F ~func(*C)](cfg *C, opts ...F) *C

ApplyOptions ...

func BuildConfig

func BuildConfig[C any, F ~func(*C)](opts []F) *C

BuildConfig ...

func Cast

func Cast[T any](origin any) (T, bool)

Cast ...

func CastInto

func CastInto[T any](origin any, into *T) bool

CastInto ...

func Default

func Default[T any](v *T, d T) T

Default return the value of "v" if not nil, otherwise return the default "d" value

func EnsureRange

func EnsureRange(min, max int64) (int64, int64)

EnsureRange ensure min is smaller or equal to max

func Find

func Find[T any](arr []T, predicate func(T) bool) (out *T)

Find looks through each value in the list, returning the first one that passes a truth test (predicate), or nil if no value passes the test. The function returns as soon as it finds an acceptable element, and doesn't traverse the entire list

func FindIdx

func FindIdx[T any](arr []T, predicate func(T) bool) (*T, int)

FindIdx ...

func FindIdxIter

func FindIdxIter[T any](it iter.Seq[T], predicate func(T) bool) (*T, int)

FindIdxIter ...

func FindIter

func FindIter[T any](it iter.Seq[T], predicate func(T) bool) (out *T)

FindIter ...

func First

func First[T any](a T, _ ...any) T

First returns the first argument

func ForEach

func ForEach[T any](arr []T, clb func(T))

ForEach ...

func NewAtomicPtr

func NewAtomicPtr[T any](v *T) atomic.Pointer[T]

NewAtomicPtr ...

func NonBlockingSend

func NonBlockingSend[T any](c chan T, el T)

NonBlockingSend ...

func Or

func Or[T comparable](a, b T) (zero T)

Or return "a" if it is non-zero otherwise "b"

func ParallelForEach

func ParallelForEach[T any](ctx context.Context, s iter.Seq[T], workerCount int, fn func(T))

ParallelForEach ...

func Ptr

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

Ptr ...

func RandDuration

func RandDuration(min, max time.Duration) time.Duration

RandDuration generates random duration

func Random

func Random(min, max int64) (out int64)

Random generates a number between min and max inclusively

func RandomFrom

func RandomFrom(r *rand.Rand, min, max int64) int64

func Second

func Second[T any](_ any, a T, _ ...any) T

Second returns the second argument

func ShortDur

func ShortDur(v any) string

ShortDur ...

func SliceSeq

func SliceSeq[T any](s []T) iter.Seq[T]

func Some

func Some[T any](arr []T, predicate func(T) bool) bool

Some returns true if any of the values in the list pass the predicate truth test. Short-circuits and stops traversing the list if a true element is found.

func SomeIter

func SomeIter[T any](it iter.Seq[T], predicate func(T) bool) bool

SomeIter ...

func Ternary

func Ternary[T any](predicate bool, a, b T) T

Ternary ...

func TernaryOrZero

func TernaryOrZero[T any](predicate bool, a T) (zero T)

TernaryOrZero ...

func TryCast

func TryCast[T any](origin any) bool

TryCast ...

func UuidV4

func UuidV4() (uuid [16]byte)

UuidV4 generates a new UUID v4

func UuidV4Str

func UuidV4Str() string

UuidV4Str ...

Types

This section is empty.

Jump to

Keyboard shortcuts

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