shared

package module
v0.0.0-...-95100be Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 11 Imported by: 0

README

go-shared

common used go funcs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Defaultify

func Defaultify[T comparable](v T, defaultValue T) T

Defaultify returns defaultValue if v is equal to its default value.

func Filter

func Filter[E any](s []E, f keepFunc[E]) []E

func FilterIsEven

func FilterIsEven[T constraints.Integer](v T) bool

func FilterIsOdd

func FilterIsOdd[T constraints.Integer](v T) bool

func ForEach

func ForEach[E any](s []E, f forEachFunc[E]) error

func GetMD5ShortHash

func GetMD5ShortHash(text string) string

func Map

func Map[E any](s []E, f mapFunc1[E]) []E

func Map2

func Map2[T1, T2 any](s []T1, f mapFunc2[T1, T2]) []T2

func OneOf

func OneOf[T comparable](value T, coll ...T) bool

func PrettifyBytes

func PrettifyBytes(b int64) string

func PrettifyTime

func PrettifyTime(micro int64) string

func Reduce

func Reduce[E any](s []E, init E, f reduceFunc[E]) E

func Sort

func Sort[E constraints.Ordered](s []E) []E

Types

type Balancer

type Balancer struct {
	// contains filtered or unexported fields
}

func NewBalancer

func NewBalancer(items ...interface{}) *Balancer

func NewStringBalancer

func NewStringBalancer(items ...string) *Balancer

func (*Balancer) MustPick

func (p *Balancer) MustPick() interface{}

func (*Balancer) MustPickString

func (p *Balancer) MustPickString() string

func (*Balancer) Pick

func (p *Balancer) Pick() (interface{}, error)

type Int64Range

type Int64Range struct {
	Min, Max int64
}

range specification, note that min <= max

func (*Int64Range) NextMedian

func (ir *Int64Range) NextMedian() int64

get next median value within the interval including min and max

func (*Int64Range) NextRandom

func (ir *Int64Range) NextRandom(r *rand.Rand) int64

get next random value within the interval including min and max

type Normalizer

type Normalizer[T Number] struct {
	// contains filtered or unexported fields
}

func (*Normalizer[T]) Get

func (p *Normalizer[T]) Get(v T) T

func (*Normalizer[T]) Update

func (p *Normalizer[T]) Update(v T)

type Number

type Number interface {
	constraints.Float | constraints.Integer
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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