ext

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayAdd

func ArrayAdd[TValue any](arr []TValue, val TValue) []TValue

ArrayAdd adds the value to the array

func ArrayAddRange

func ArrayAddRange[TItem any](list []TItem, items []TItem) []TItem

ArrayAddRange adds a range of elements to the array

func ArrayCut

func ArrayCut[TValue any](arr []TValue, startIndex int, endIndex int) []TValue

ArrayCut returns a section of the original array between and including the 'startIndex' and excludes the 'endIndex'

func ArrayExists

func ArrayExists[TValue any](arr []TValue, matcher func(TValue) bool) bool

ArrayExists return true if the 'matcher' function return true on any of the values

func ArrayFilter

func ArrayFilter[TInput any, TResult any](items []TInput, test func(TInput) (TResult, bool)) []TResult

ArrayFilter returns a new array with the elements that match the 'test'

func ArrayOfStringToInt

func ArrayOfStringToInt(sArr []string) []int

ArrayOfStringToInt tries to convert every value in the array to and int, it will panic if a convertion failes

func ArrayPop

func ArrayPop[TValue any](arr []TValue) ([]TValue, TValue)

ArrayPop removes the first element from the array and return the new array and the value popped

func ArrayRemove

func ArrayRemove[TValue any](arr []TValue, index int) []TValue

ArrayRemove removes the index from the array and keeps the order of elements

func ArrayRemoveFast

func ArrayRemoveFast[TValue any](s []TValue, index int) []TValue

ArrayRemoveFast removes the index from the array, but the order of elements are not kept

func ArrayReverse

func ArrayReverse[TValue any](arr []TValue) []TValue

ArrayReverse returns the array in opposite order

func ArraySplit

func ArraySplit[TItem any](list []TItem, max int) map[int][]TItem

ArraySplit splits the array into groups of max items defined by 'max'

func ArraySurroundWith

func ArraySurroundWith(arr []string, char string) []string

ArraySurroundWith updates the array and puts the specified characters in front and behind each value in the array

func ArrayToArrayGroups

func ArrayToArrayGroups[TItem any, TOutput any](arr []TItem, count int, selector FuncSelector[TItem, TOutput]) [][]TOutput

ArrayToArrayGroups convert an array of type 'TItem' into a 2-dim array of group with defined count

func ArrayToCommaString

func ArrayToCommaString[TItem int | int32 | int64](list []TItem, approxLen int) string

ArrayToCommaString converts an array of numbers to a comma separated string for use in sqls 'where in' statement

func ArrayToMap

func ArrayToMap[TItem any, TKey int | int8 | int32 | int16 | int64 | string, TOutput any](arr []TItem, keySelector FuncSelector[TItem, TKey], valueSelector FuncSelector[TItem, TOutput]) map[TKey]TOutput

ArrayToMap converts an array of type 'TItem' into a map on the value returned by 'keySelector'

func ArrayToMapIgnore

func ArrayToMapIgnore[TItem any, TKey int | int8 | int32 | int16 | int64 | string, TOutput any](arr []TItem, keySelector FuncSelector[TItem, TKey], valueSelector FuncSelector[TItem, TOutput], ignoreKeyMatcher FuncSelector[TItem, bool]) map[TKey]TOutput

ArrayToMapIgnore converts an array of type 'TItem' into a map on the value returned by 'keySelector', but ignores the key if 'ignoreKeyMatcher' returns true

func ArrayToMapList

func ArrayToMapList[TItem any, TKey int | int8 | int32 | int16 | int64 | string, TOutput any](arr []TItem, keySelector FuncSelector[TItem, TKey], valueSelector FuncSelector[TItem, TOutput]) map[TKey][]TOutput

ArrayToMapList converts an array of type 'TItem' into a map with array grouped on the value returned by 'keySelector'

func ArrayUnique

func ArrayUnique[TKey int | int8 | int32 | int16 | int64 | string, TValue any](arr []TValue, keySelector func(TValue) TKey) []TValue

ArrayUnique returns a new array with only the unique values based on the result of 'keySelector'

func CloneMap

func CloneMap[Key int | string, Value any](this map[Key]Value) map[Key]Value

CloneMap returns a new map with the same values as the original

func ConvertToArray

func ConvertToArray[TItem any, TOutput any](arr []TItem, selector FuncSelector[TItem, TOutput]) []TOutput

ConvertToArray converts one array of type 'TItem' into a new array of type 'TOutput'

func Cut

func Cut(val string, length int) string

Cut cuts a string to the specified length, if it is longer than the specified length

func Float32ToString

func Float32ToString(num float32) string

Float32ToString converts 'num' into a base(10) string of the number

func Float64ToString

func Float64ToString(num float64) string

Float64ToString converts 'num' into a base(10) string of the number

func Ifi

func Ifi[TVal any](x bool, t TVal, f TVal) TVal

Ifi is an "if" that is inline, since go does not provide one in its syntax

func Iif

func Iif[TVal any](x bool, t TVal, f TVal) TVal

Iif is an inline "if", since go does not provide one in its syntax

func Int32ToString

func Int32ToString(num int32) string

Int32ToString converts 'num' into a base(10) string of the number

func Int64ToString

func Int64ToString(num int64) string

Int64ToString converts 'num' into a base(10) string of the number

func IntToString

func IntToString(num int) string

IntToString converts 'num' into a base(10) string of the number

func MapAddOrUpdate

func MapAddOrUpdate[TKey int | int8 | int32 | int16 | int64 | string, TValue any](this map[TKey]TValue, key TKey, val TValue) map[TKey]TValue

MapAddOrUpdate updates the 'key' with the 'value' if it already exists, else it will add the value to the map

func MapArrayAdd

func MapArrayAdd[TKey int | int8 | int32 | int16 | int64 | string, TValue any](this map[TKey][]TValue, key TKey, val TValue) map[TKey][]TValue

MapArrayAdd adds 'value' to the array of the 'key' in the map

func MapKeyExists

func MapKeyExists[TKey int | int8 | int32 | int16 | int64 | string, TValue any](this map[TKey]TValue, key TKey, def TValue) (bool, TValue)

MapKeyExists returns true and the value if the 'key' exists in the map

func MapToArray

func MapToArray[TKey int | int8 | int32 | int16 | int64 | string, TValue any](this map[TKey]TValue) []TValue

MapToArray returns an array of each of the values in the map

func ParseDuration

func ParseDuration(value string, def time.Duration) time.Duration

ParseDuration takes a duration string representation and converts it into a time.Duration, or returns the 'def' if it fails Examples such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

func SplitFloat32

func SplitFloat32(num float32) (int32, int32, error)

SplitFloat32 tries to split a 'num' into its two components the number and precision, or an error if it fails

func SplitFloat32WithPrecision

func SplitFloat32WithPrecision(num float32, prec int) (int32, int32, error)

SplitFloat32WithPrecision tries to split a 'num' into its two components the number and precision, 'prec' can be used to define the precision (number of decimals), or an error if it fails

func SplitFloat64

func SplitFloat64(num float64) (int64, int64, error)

SplitFloat64 tries to split a 'num' into its two components the number and precision, or an error if it fails

func SplitFloat64WithPrecision

func SplitFloat64WithPrecision(num float64, prec int) (int64, int64, error)

SplitFloat64WithPrecision tries to split a 'num' into its two components the number and precision, 'prec' can be used to define the precision (number of decimals), or an error if it fails

func StripAnsiColors

func StripAnsiColors(str string) string

StripAnsiColors strips all ansi color values from a string

func TimeWithOffsetFromLocal

func TimeWithOffsetFromLocal(input time.Time, location *time.Location) time.Time

TimeWithOffsetFromLocal returns the 'input' time with an offset of the defined 'location'

func TimeWithoutOffsetFromUTC

func TimeWithoutOffsetFromUTC(input time.Time, location *time.Location) time.Time

TimeWithoutOffsetFromUTC returns the 'input' time without offset from utc

func WorkingDir

func WorkingDir() string

WorkingDir tries to get the correct path of the current execution based on the value of the ENV environment variable. if the ENV is debug, then it wil used os.Getwd() else it will use filepath.Dir(os.Executable())

Types

type FuncSelector

type FuncSelector[TItem any, TOutput any] func(TItem) TOutput

Jump to

Keyboard shortcuts

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