utils

package
v0.0.0-...-325667f Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[V any](it iter.Seq[V], clb func(V) bool) bool

All return true if calling clb with all item in Seq return true

func Any2

func Any2[K, V any](it iter.Seq2[K, V], clb func(K, V) bool) bool

Any2 return true if calling clb with any item in Seq2 return true

func Clamp

func Clamp[T cmp.Ordered](val, pMin, pMax T) T

Clamp ensure the value is within a range

func Count2

func Count2[K, V any](it iter.Seq2[K, V]) (out int)

Count2 counts element in an iter.Seq2

func Default

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

Default ...

func Deref

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

Deref generic deref return the zero value if v is nil

func DoCastF64

func DoCastF64(v any) float64

func DoCastStr

func DoCastStr(v any) string

func DoParseI64

func DoParseI64(v string) (out int64)

func FI64

func FI64[T Ints](v T) string

FI64 formats any int types to string

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)

func First

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

func GetNbr

func GetNbr(doc *goquery.Document, name string) int64

func GetNbrShips

func GetNbrShips(doc *goquery.Document, name string) int64

func I64Ptr

func I64Ptr(v int64) *int64

I64Ptr returns a pointer to int64

func InArr

func InArr[T comparable](needle T, haystack []T) bool

func InArray

func InArray[T Equalable[T]](needle T, haystack []T) bool

func Noop

func Noop(_ ...any)

Noop ...

func Or

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

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

func ParseI64

func ParseI64(v string) (out int64, err error)

func ParseInt

func ParseInt(val string) int64

ParseInt ...

func Ptr

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

Ptr return a pointer to v

func RandChoice

func RandChoice[T any](arr []T) T

RandChoice returns a random element from an array

func RandDuration

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

RandDuration generates random duration

func RandFloat

func RandFloat(min, max float64) float64

func RandMs

func RandMs(min, max int64) time.Duration

RandMs generates random duration in milliseconds

func Random

func Random(min, max int64) int64

Random generates a number between min and max inclusively

func RoundThousandth

func RoundThousandth(n float64) float64

RoundThousandth round value to the nearest thousandth

func Second

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

func Ternary

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

func TernaryOrZero

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

func ToInt

func ToInt(buf []byte) (n int)

Types

type Equalable

type Equalable[T any] interface {
	Equal(other T) bool
}

type Ints

type Ints interface {
	~int64 | ~int
}

Jump to

Keyboard shortcuts

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