utils

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitIndices added in v0.0.6

func BitIndices[T constraints.Integer](num T) []int

func CloneSlice

func CloneSlice[T Cloner[T]](srcs []T) []T

func CloneSliceWithCloner

func CloneSliceWithCloner[T any](srcs []T, clone func(T) T) []T

func Crop added in v0.0.11

func Crop[T any](slice []T, index int) []T

func CropElement added in v0.0.25

func CropElement[T comparable, E ~[]T](slice E, element T) []T

func CropElements added in v0.0.25

func CropElements[T comparable, E ~[]T](slice E, elements ...T) []T

func FindPred added in v0.0.14

func FindPred[E ~[]T, T any](list E, pred func(T) bool) (T, bool)

func Indented added in v0.0.6

func Indented[T ~string](indent T, strings ...T) []T

func Intersect

func Intersect[T comparable](list1, list2 []T) []T

func IsNilOrZero added in v0.0.25

func IsNilOrZero[T any](val T) bool

func Last added in v0.0.14

func Last[E ~[]T, T any](list E) (T, bool)

func MapToStruct

func MapToStruct[T any](m map[string]any) (T, error)

MapToStruct converts a map to a struct by converting through json

func MergeMaps

func MergeMaps[K comparable, V any](target, source map[K]V) map[K]V

MergeMaps creates a new map and copies target and then source into it

func Repeat

func Repeat[T any](item T, count int) []T

func Reversed added in v0.0.22

func Reversed[E ~[]T, T any](list E) []T

func Same

func Same[T comparable](a, b []T) bool

Same checks if two slices have the same elements in any order

func SortKeys added in v0.0.25

func SortKeys[K comparable, V any, U ~map[K]V](self U, pred func(a, b K) bool) []K

SortKeys gets a slice of all the keys in a map, sorted by a predicate func

func SortedKeys added in v0.0.6

func SortedKeys[K constraints.Ordered, V any](self map[K]V) []K

SortedKeys gets a slice of all the keys in a map, sorted

func Strings

func Strings[T fmt.Stringer](slice []T) []string

func StructToMap

func StructToMap[T any](t T) (map[string]any, error)

StructToMap converts a struct to a map by converting through json

func TakeOne added in v0.0.21

func TakeOne[TM ~map[TK]TV, TK comparable, TV any](dict TM) (TK, TV)

func Timestamp added in v0.0.16

func Timestamp(dt time.Time) string

func TimestampNow added in v0.0.16

func TimestampNow() string

func Transcase added in v0.0.9

func Transcase(input string, from, to StringCase) string

func Transform added in v0.0.25

func Transform[E ~[]T, T, U any](l E, t func(T) U) []U

func TypeFor added in v0.0.25

func TypeFor[T any]() reflect.Type

Types

type BitFlag added in v0.0.25

type BitFlag uint8

func (*BitFlag) Clear added in v0.0.25

func (bf *BitFlag) Clear(flag BitFlag)

func (*BitFlag) ClearAll added in v0.0.25

func (bf *BitFlag) ClearAll()

func (*BitFlag) ClearMany added in v0.0.25

func (bf *BitFlag) ClearMany(flags ...BitFlag)

func (*BitFlag) Cleared added in v0.0.25

func (bf *BitFlag) Cleared(flag BitFlag) bool

Cleared with multiple flags is effectively ClearedAll

func (*BitFlag) ClearedAll added in v0.0.25

func (bf *BitFlag) ClearedAll(flags ...BitFlag) bool

func (*BitFlag) ClearedAny added in v0.0.25

func (bf *BitFlag) ClearedAny(flags ...BitFlag) bool

func (*BitFlag) Get added in v0.0.25

func (bf *BitFlag) Get(flag BitFlag) BitFlag

func (*BitFlag) GetMany added in v0.0.25

func (bf *BitFlag) GetMany(flags ...BitFlag) BitFlag

func (*BitFlag) Set added in v0.0.25

func (bf *BitFlag) Set(flag BitFlag)

func (*BitFlag) SetMany added in v0.0.25

func (bf *BitFlag) SetMany(flags ...BitFlag)

func (*BitFlag) Test added in v0.0.25

func (bf *BitFlag) Test(flag BitFlag) bool

Test with multiple flags is effectively TestAny

func (*BitFlag) TestAll added in v0.0.25

func (bf *BitFlag) TestAll(flags ...BitFlag) bool

func (*BitFlag) TestAny added in v0.0.25

func (bf *BitFlag) TestAny(flags ...BitFlag) bool

func (*BitFlag) Toggle added in v0.0.25

func (bf *BitFlag) Toggle(flag BitFlag)

func (*BitFlag) ToggleMany added in v0.0.25

func (bf *BitFlag) ToggleMany(flags ...BitFlag)

type Cloner

type Cloner[T any] interface {
	Clone() T
}

type DurationReport added in v0.0.25

type DurationReport struct {
	Min    time.Duration
	Bot1p  time.Duration
	Bot10p time.Duration
	Avg    time.Duration
	Top10p time.Duration
	Top1p  time.Duration
	Max    time.Duration
}

type FrameStats added in v0.0.25

type FrameStats struct {
	Durations []time.Duration
}

func (*FrameStats) AddFrame added in v0.0.25

func (fs *FrameStats) AddFrame(duration time.Duration)

func (*FrameStats) Report added in v0.0.25

func (fs *FrameStats) Report() DurationReport

type Pipe added in v0.0.18

type Pipe[T any] func(T) T

func Pipeline added in v0.0.18

func Pipeline[T any](pipes ...Pipe[T]) Pipe[T]

type StringCase added in v0.0.9

type StringCase int
const (
	// camelCaseText
	CamelCase StringCase = iota
	// PascalCaseText
	PascalCase
	// snake_case_text
	SnakeCase
	// Title Case Text
	TitleCase
)

func (StringCase) Parse added in v0.0.9

func (c StringCase) Parse(phrase string) []string

func (StringCase) Render added in v0.0.9

func (c StringCase) Render(words []string) string

Jump to

Keyboard shortcuts

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