util

package
v0.7.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayCast

func ArrayCast[T any](source []interface{}) []T

func ArrayConvert

func ArrayConvert[T any, Y any](source []Y,
	convert func(item Y) T) []T

func ArrayFilter

func ArrayFilter[T any](source []T, filter func(item T) bool) []T

func Average

func Average(source []float64) float64

func If

func If[T any](cond bool, vtrue, vfalse T) T

func IfNillable added in v0.6.9

func IfNillable[T any](cond bool, vtrueNillable func() T, vfalse T) T

In case vtrue value depends on a variable checked on condition which could be nil as params are evaluated within the If function invokation it will produce a panic error in that case we will pass the vtrue as a function which will be evaluated only if condition is met

i.e. If(foo != nil, foo.bar, "") In this case if foo is nill this will error with panic as the evaluation will try access foo which is nil

so, in this case we will use IfNillable: bar = func() { return foo.bar} IfNillable(foo != nil, bar, "")

func Max

func Max(source []float64) float64

func Random

func Random(max, min int) int

func RandomID

func RandomID(name string) string

func RandomItemFromArray

func RandomItemFromArray[X any](source []X) X

func SplitSlice

func SplitSlice[T any, Y comparable](source []T,
	identification func(item T) Y) (m map[Y][]T)

This function split a list based on a evaluation function the result is a map of lists

func SplitString

func SplitString(source, delimiter string) []string

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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