typer

package
v0.0.0-...-2d29fd2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: MIT Imports: 9 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPropertyType = errors.New("got/typer: convert type failed")

Functions

func Any

func Any[T any](v T) any

func AssertNil

func AssertNil[T any](v T, terminator ...delegate.Action) bool

func AssertNotNil

func AssertNotNil[T any](v T, terminator ...delegate.Action) bool

func AssertType

func AssertType[TAssert, TVal any](v TVal, terminator ...delegate.Action) bool

func AssertZeroVal

func AssertZeroVal[T comparable](v T, terminator ...delegate.Action) bool

func Between

func Between[T constraints.Ordered](v T, begin, end T) bool

func ConvI2I64Any

func ConvI2I64Any(val any) (int64, error)

func Convert

func Convert[T any](val any, defaultV T) (T, error)

func ConvertMust

func ConvertMust[T any](val any) T

func DoAsSlice

func DoAsSlice[T any](input any, cb func(val T) error) error

func Flatten2DSlice

func Flatten2DSlice(input any) ([]any, error)

Flatten2DSlice flattens a 2D array into a 1D array.

func Flatten2DSliceGeneric

func Flatten2DSliceGeneric[T any](input ...[]T) []T

Flatten2DSliceGeneric flattens a 2D array of type T into a 1D array.

func FlattenNestedSlices

func FlattenNestedSlices(input any, depth int) []any

FlattenNestedSlices flattens nested slices or arrays into a single-dimensional slice.

It takes two parameters:

  • input: the input data of any type, which may contain nested slices or arrays.
  • depth: the target flattening depth, controlling the number of levels to flatten.

If the target depth is 0, no flattening is performed, and the input is returned as a slice.

The function recursively flattens the input data up to the specified depth. If the current depth reaches the target depth, the elements are added to the result slice without further flattening.

It returns a []any slice containing the flattened elements.

func I2Str

func I2Str[T constraints.Integer](num T) string

func IfThen

func IfThen[T any](cond bool, a T, b T) T

func Is2DSlice

func Is2DSlice(v any) bool

Is2DSlice checks if the given variable is a 2D array.

func IsNil

func IsNil(v any) bool

func IsNotNil

func IsNotNil(v any) bool

func IsSlice

func IsSlice(v any) bool

IsSlice checks if the given variable is a slice.

func IsType

func IsType[TAssert, TVal any](v TVal) bool

func IsZero

func IsZero[T comparable](v T) bool

func KVs

func KVs[TKey comparable, TVal any](m map[TKey]TVal) []struct {
	Key TKey
	Val TVal
}

func Keys

func Keys[TKey comparable, TVal any](m map[TKey]TVal) []TKey

func KeysSorted

func KeysSorted[TKey constraints.Ordered, TVal any](m map[TKey]TVal) []TKey

func MapDump

func MapDump[TKey comparable, TVal any](m map[TKey]TVal, dumper delegate.Func2[TKey, TVal, string]) []string

func MapForEachOrderly

func MapForEachOrderly[TKey constraints.Ordered, TVal any](m map[TKey]TVal, traver func(key TKey, val TVal))

func MapMap

func MapMap[TKey comparable, TVal any, TKey1 comparable, TVal1 any](m map[TKey]TVal, keyConv delegate.Convert[TKey, TKey1], valConv delegate.Convert[TVal, TVal1]) map[TKey1]TVal1

func Or

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

func PanicWhenError

func PanicWhenError(err error, fmtOrMsg string, args ...any)

func Ptr

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

func S2IMust

func S2IMust[T constraints.Integer](str string) T

func SliceContains

func SliceContains[TVal comparable](slice []TVal, val TVal) bool

func SliceDiff

func SliceDiff[TSliceVal comparable](oldLst, newLst []TSliceVal) (toAdd, toRemove []TSliceVal)

func SliceFilter

func SliceFilter[TVal comparable](slice []TVal, pred delegate.Predicate[TVal]) []TVal

func SliceFirst

func SliceFirst[TVal comparable](slice []TVal, val TVal) int

func SliceFirstMatch

func SliceFirstMatch[TVal comparable](slice []TVal, pred delegate.Predicate[TVal]) int

func SliceForeach

func SliceForeach[TSliceVal any](slice []TSliceVal, foreachFn delegate.Action1[TSliceVal])

func SliceForeachI

func SliceForeachI[TSliceVal any](slice []TSliceVal, foreachFn delegate.Action2[TSliceVal, int])

func SliceLast

func SliceLast[TSliceVal any](slice []TSliceVal) TSliceVal

func SliceMap

func SliceMap[TFrom, TTo any](from []TFrom, mapFn delegate.Convert[TFrom, TTo]) []TTo

func SliceMax

func SliceMax[TSliceVal constraints.Ordered](data []TSliceVal) (ret TSliceVal)

func SliceMin

func SliceMin[TSliceVal constraints.Ordered](data []TSliceVal) (ret TSliceVal)

func SlicePadRight

func SlicePadRight[TSliceVal any](slice []TSliceVal, length int, padVal TSliceVal) []TSliceVal

func SliceRand

func SliceRand[TVal comparable](slice []TVal, defaultVal TVal) TVal

func SliceReduce

func SliceReduce[TSliceVal, TTarget any](slice []TSliceVal, reduceFn func(TSliceVal, TTarget) TTarget, defaultVal TTarget) TTarget

func SliceReverse

func SliceReverse[TSliceVal any](data []TSliceVal)

func SliceSort

func SliceSort[TSliceVal constraints.Ordered](slice []TSliceVal)

func SliceToTrueMap

func SliceToTrueMap[TSliceVal comparable](list []TSliceVal) map[TSliceVal]struct{}

func SliceTryGet

func SliceTryGet[TSliceVal any](slice []TSliceVal, i int, defaultVal TSliceVal) TSliceVal

func Str

func Str[T any](v T) string

func Vals

func Vals[TKey comparable, TVal any](m map[TKey]TVal) []TVal

func ZeroVal

func ZeroVal[T any]() (v T)

Types

This section is empty.

Jump to

Keyboard shortcuts

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