langext

package
v0.0.594 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Base58BitcoinEncoding = newBase58Encoding("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
View Source
var Base58DefaultEncoding = newBase58Encoding("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
View Source
var Base58FlickrEncoding = newBase58Encoding("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ")
View Source
var Base58RippleEncoding = newBase58Encoding("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz")
View Source
var PFalse = Ptr(false)

PFalse := &false

View Source
var PNil = Ptr[any](nil)

PNil := &nil

View Source
var PTrue = Ptr(true)

PTrue := &true

Functions

func AddToSet

func AddToSet[T comparable](set []T, add T) []T

func ArrAll

func ArrAll[T any](arr []T, fn func(T) bool) bool

func ArrAllErr

func ArrAllErr[T any](arr []T, fn func(T) (bool, error)) (bool, error)

func ArrAny

func ArrAny[T any](arr []T, fn func(T) bool) bool

func ArrAnyErr

func ArrAnyErr[T any](arr []T, fn func(T) (bool, error)) (bool, error)

func ArrAppend

func ArrAppend[T any](arr []T, add ...T) []T

ArrAppend works similar to append(x, y, z) - but doe snot touch the old array and creates a new one

func ArrCastErr

func ArrCastErr[T1 any, T2 any](arr []T1) ([]T2, error)

func ArrCastPanic

func ArrCastPanic[T1 any, T2 any](arr []T1) []T2

func ArrCastSafe

func ArrCastSafe[T1 any, T2 any](arr []T1) []T2

func ArrCastToAny

func ArrCastToAny[T1 any](arr []T1) []any

func ArrChunk

func ArrChunk[T any](arr []T, chunkSize int) [][]T

ArrChunk splits the array into buckets of max-size `chunkSize` order is being kept. The last chunk may contain less than length elements.

(chunkSize == -1) means no chunking

see https://www.php.net/manual/en/function.array-chunk.php

func ArrConcat

func ArrConcat[T any](arr ...[]T) []T

func ArrContains

func ArrContains[T comparable](haystack []T, needle T) bool

ArrContains checks if the value is contained in the array (same as InArray, but odther name for better findability)

func ArrCopy

func ArrCopy[T any](in []T) []T

ArrCopy does a shallow copy of the 'in' array

func ArrDeRef

func ArrDeRef[T1 any](arr []*T1) []T1

func ArrEqualsExact

func ArrEqualsExact[T comparable](arr1 []T, arr2 []T) bool

func ArrExcept

func ArrExcept[T comparable](arr []T, needles ...T) []T

func ArrFilter

func ArrFilter[T any](arr []T, filter func(v T) bool) []T

func ArrFilterMap

func ArrFilterMap[T1 any, T2 any](arr []T1, filter func(v T1) bool, conv func(v T1) T2) []T2

func ArrFirst

func ArrFirst[T any](arr []T, comp func(v T) bool) (T, bool)

func ArrFirstIndex

func ArrFirstIndex[T comparable](arr []T, needle T) int

func ArrFirstIndexFunc

func ArrFirstIndexFunc[T any](arr []T, comp func(v T) bool) int

func ArrFirstOrNil

func ArrFirstOrNil[T any](arr []T, comp func(v T) bool) *T

func ArrFlatten

func ArrFlatten[T1 any, T2 any](arr []T1, conv func(v T1) []T2) []T2

func ArrFlattenDirect

func ArrFlattenDirect[T1 any](arr [][]T1) []T1

func ArrGroupBy

func ArrGroupBy[T1 any, T2 comparable](arr []T1, groupfunc func(v T1) T2) map[T2][]T1

func ArrIdxAll

func ArrIdxAll(arr any, fn func(int) bool) bool

func ArrIdxAllErr

func ArrIdxAllErr(arr any, fn func(int) (bool, error)) (bool, error)

func ArrIdxAny

func ArrIdxAny(arr any, fn func(int) bool) bool

func ArrIdxAnyErr

func ArrIdxAnyErr(arr any, fn func(int) (bool, error)) (bool, error)

func ArrIdxNone

func ArrIdxNone(arr any, fn func(int) bool) bool

func ArrIdxNoneErr

func ArrIdxNoneErr(arr any, fn func(int) (bool, error)) (bool, error)

func ArrLast

func ArrLast[T any](arr []T, comp func(v T) bool) (T, bool)

func ArrLastIndex

func ArrLastIndex[T comparable](arr []T, needle T) int

func ArrLastIndexFunc

func ArrLastIndexFunc[T any](arr []T, comp func(v T) bool) int

func ArrLastOrNil

func ArrLastOrNil[T any](arr []T, comp func(v T) bool) *T

func ArrMap

func ArrMap[T1 any, T2 any](arr []T1, conv func(v T1) T2) []T2

func ArrMapErr

func ArrMapErr[T1 any, T2 any](arr []T1, conv func(v T1) (T2, error)) ([]T2, error)

func ArrMapExt

func ArrMapExt[T1 any, T2 any](arr []T1, conv func(idx int, v T1) T2) []T2

func ArrMapSum

func ArrMapSum[T1 any, T2 NumberConstraint](arr []T1, conv func(v T1) T2) T2

func ArrNone

func ArrNone[T any](arr []T, fn func(T) bool) bool

func ArrNoneErr

func ArrNoneErr[T any](arr []T, fn func(T) (bool, error)) (bool, error)

func ArrPrepend

func ArrPrepend[T any](arr []T, add ...T) []T

ArrPrepend works similar to append(x, y, z) - but doe snot touch the old array and creates a new one Also - in contrast to ArrAppend - the add values are inserted at the start of the resulting array (in reverse order)

func ArrPtr

func ArrPtr[T any](v ...T) *[]T

func ArrRemove

func ArrRemove[T comparable](arr []T, needle T) []T

func ArrRemoveAt

func ArrRemoveAt[T any](arr []T, idx int) []T

func ArrSum

func ArrSum[T NumberConstraint](arr []T) T

func ArrToKVMap

func ArrToKVMap[T any, K comparable, V any](a []T, keyfunc func(T) K, valfunc func(T) V) map[K]V

func ArrToMap

func ArrToMap[T comparable, V any](a []V, keyfunc func(V) T) map[T]V

func ArrToSet

func ArrToSet[T comparable](a []T) map[T]bool

func ArrUnique

func ArrUnique[T comparable](array []T) []T

func ArrUniqueStable

func ArrUniqueStable[T comparable](array []T) []T

func ArrayToInterface

func ArrayToInterface[T any](t []T) []interface{}

func AsSorted

func AsSorted[T OrderedConstraint](arr []T) []T

func AsSortedBy

func AsSortedBy[TElem any, TSel OrderedConstraint](arr []TElem, selector func(v TElem) TSel) []TElem

func AsSortedByStable

func AsSortedByStable[TElem any, TSel OrderedConstraint](arr []TElem, selector func(v TElem) TSel) []TElem

func AsSortedSlice

func AsSortedSlice[T any](arr []T, less func(v1, v2 T) bool) []T

func AsSortedSliceStable

func AsSortedSliceStable[T any](arr []T, less func(v1, v2 T) bool) []T

func AsSortedStable

func AsSortedStable[T OrderedConstraint](arr []T) []T

func BoolCount

func BoolCount(arr ...bool) int

func BuildUrl

func BuildUrl(url, path string, params *map[string]string) string

func BytesXOR

func BytesXOR(a []byte, b []byte) ([]byte, error)

func Coalesce

func Coalesce[T any](v1 *T, def T) T

func Coalesce3

func Coalesce3[T any](v1 *T, v2 *T, def T) T

func Coalesce3Opt

func Coalesce3Opt[T any](v1 *T, v2 *T, v3 *T) *T

func Coalesce4

func Coalesce4[T any](v1 *T, v2 *T, v3 *T, def T) T

func Coalesce4Opt

func Coalesce4Opt[T any](v1 *T, v2 *T, v3 *T, v4 *T) *T

func CoalesceBool

func CoalesceBool(b *bool, def bool) bool

func CoalesceDblPtr

func CoalesceDblPtr[T any](v1 **T, v2 *T) *T

func CoalesceDefault

func CoalesceDefault[T comparable](v1 T, def T) T

func CoalesceDefaultArr

func CoalesceDefaultArr[T comparable](v1 T, vMore ...T) T

func CoalesceInt

func CoalesceInt(i *int, def int) int

func CoalesceInt32

func CoalesceInt32(i *int32, def int32) int32

func CoalesceOpt

func CoalesceOpt[T any](v1 *T, v2 *T) *T

func CoalesceString

func CoalesceString(s *string, def string) string

func CoalesceStringer

func CoalesceStringer(s fmt.Stringer, def string) string

func CoalesceTime

func CoalesceTime(t *time.Time, def time.Time) time.Time

func Compare

func Compare[T OrderedConstraint](a, b T) int

func CompareArr

func CompareArr[T OrderedConstraint](arr1 []T, arr2 []T) int

func CompareInt

func CompareInt(a, b int) int

func CompareInt64

func CompareInt64(a, b int64) int

func CompareIntArr

func CompareIntArr(arr1 []int, arr2 []int) bool

func CompareString

func CompareString(a, b string) int

func Conditional

func Conditional[T any](v bool, resTrue T, resFalse T) T

func ConditionalFn00

func ConditionalFn00[T any](v bool, resTrue T, resFalse T) T

func ConditionalFn01

func ConditionalFn01[T any](v bool, resTrue T, resFalse func() T) T

func ConditionalFn10

func ConditionalFn10[T any](v bool, resTrue func() T, resFalse T) T

func ConditionalFn11

func ConditionalFn11[T any](v bool, resTrue func() T, resFalse func() T) T

func ConvertStringerArray

func ConvertStringerArray[T fmt.Stringer](inarr []T) []string

func CopyMap

func CopyMap[K comparable, V any](a map[K]V) map[K]V

func DblPtr

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

func DblPtrIfNotNil

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

func DblPtrNil

func DblPtrNil[T any]() **T

func DeRefStringer

func DeRefStringer(v fmt.Stringer) *string

func DecodeBase62

func DecodeBase62(str string) (uint64, error)

func DecodeBase64Any added in v0.0.581

func DecodeBase64Any(data string) ([]byte, error)

DecodeBase64Any decodes a base64 encoded string Works with all variants (std, url, imap), padded and unpadded and even ignores linrebreaks and indents

func DeepCopyByJson

func DeepCopyByJson[T any](v T) (T, error)

func DegToRad

func DegToRad(deg float64) float64

func EncodeBase62

func EncodeBase62(num uint64) string

func FileExists

func FileExists(filename string) bool

func ForceArray

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

ForceArray ensures that the given array is not nil (nil will be converted to empty)

func ForceMap

func ForceMap[K comparable, V any](v map[K]V) map[K]V

func FormatBool

func FormatBool(v bool, strTrue string, strFalse string) string

func FormatBytes

func FormatBytes(b int64) string

func FormatBytesToSI

func FormatBytesToSI(b uint64) string

func GeoDistance

func GeoDistance(lon1 float64, lat1 float64, lon2 float64, lat2 float64) float64

func InArray

func InArray[T comparable](needle T, haystack []T) bool

func Indent

func Indent(str string, pad string) string

func IsNil

func IsNil(i interface{}) bool

func IsSliceSorted

func IsSliceSorted[T any](arr []T, less func(v1, v2 T) bool) bool

func IsSorted

func IsSorted[T OrderedConstraint](arr []T) bool

func IsSortedBy

func IsSortedBy[TElem any, TSel OrderedConstraint](arr []TElem, selector func(v TElem) TSel)

func IterSingleValueSeq

func IterSingleValueSeq[T any](value T) iter.Seq[T]

func IterSingleValueSeq2

func IterSingleValueSeq2[T1 any, T2 any](v1 T1, v2 T2) iter.Seq2[T1, T2]

func JoinString

func JoinString(arr []string, delimiter string) string

func MapKeyArr

func MapKeyArr[T comparable, V any](v map[T]V) []T

func MapMap

func MapMap[TK comparable, TV any, TR any](inmap map[TK]TV, conv func(k TK, v TV) TR) []TR

func MapMapErr

func MapMapErr[TK comparable, TV any, TR any](inmap map[TK]TV, conv func(k TK, v TV) (TR, error)) ([]TR, error)

func MapMerge

func MapMerge[K comparable, V any](base map[K]V, arr ...map[K]V) map[K]V

func MapValueArr

func MapValueArr[T comparable, V any](v map[T]V) []V

func MarshalJsonIndentOrDefault

func MarshalJsonIndentOrDefault(v any, prefix, indent string, def string) string

func MarshalJsonIndentOrNil

func MarshalJsonIndentOrNil(v any, prefix, indent string) *string

func MarshalJsonIndentOrPanic

func MarshalJsonIndentOrPanic(v any, prefix, indent string) string

func MarshalJsonOrDefault

func MarshalJsonOrDefault(v any, def string) string

func MarshalJsonOrNil

func MarshalJsonOrNil(v any) *string

func MarshalJsonOrPanic

func MarshalJsonOrPanic(v any) string

func Must

func Must[T any](v T, err error) T

Must returns a value and panics on error

Usage: Must(methodWithError(...))

func MustBool

func MustBool[T any](v T, ok bool) T

MustBool returns a value and panics on missing

Usage: MustBool(methodWithOkayReturn(...))

func MustBracesUUID

func MustBracesUUID() string

func MustHexUUID

func MustHexUUID() string

func MustParensUUID

func MustParensUUID() string

func MustRawHexUUID

func MustRawHexUUID() string

func MustUpperHexUUID

func MustUpperHexUUID() string

func NewBracesUUID

func NewBracesUUID() (string, error)

func NewHexUUID

func NewHexUUID() (string, error)

func NewParensUUID

func NewParensUUID() (string, error)

func NewRawHexUUID

func NewRawHexUUID() (string, error)

func NewUUID

func NewUUID() ([16]byte, error)

func NewUpperHexUUID

func NewUpperHexUUID() (string, error)

func NumToStringOpt

func NumToStringOpt[V IntConstraint](v *V, fallback string) string

func PatchJson

func PatchJson[JV string | []byte](rawjson JV, key string, value any) (JV, error)

func PatchRemJson

func PatchRemJson[JV string | []byte](rawjson JV, key string) (JV, error)

func PrettyPrintJson

func PrettyPrintJson(str string) (string, bool)

func Ptr

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

func PtrEquals

func PtrEquals[T comparable](v1 *T, v2 *T) bool

func PtrFloat32

func PtrFloat32(v float32) *float32

func PtrFloat64

func PtrFloat64(v float64) *float64

func PtrInt32

func PtrInt32(v int32) *int32

func PtrInt64

func PtrInt64(v int64) *int64

func RadToDeg

func RadToDeg(rad float64) float64

func RandBase62

func RandBase62(rlen int) string

func RandBytes

func RandBytes(size int) []byte

func Range

func Range[T IntegerConstraint](start T, end T) []T

func ReverseArray

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

func RunPanicSafe

func RunPanicSafe(fn func()) (err error)

func RunPanicSafeR1

func RunPanicSafeR1(fn func() error) (err error)

func RunPanicSafeR2

func RunPanicSafeR2[T1 any](fn func() (T1, error)) (r1 T1, err error)

func RunPanicSafeR3

func RunPanicSafeR3[T1 any, T2 any](fn func() (T1, T2, error)) (r1 T1, r2 T2, err error)

func RunPanicSafeR4

func RunPanicSafeR4[T1 any, T2 any, T3 any](fn func() (T1, T2, T3, error)) (r1 T1, r2 T2, r3 T3, err error)

func SafeCast

func SafeCast[T any](v any, def T) T

func Sort

func Sort[T OrderedConstraint](arr []T)

func SortBy

func SortBy[TElem any, TSel OrderedConstraint](arr []TElem, selector func(v TElem) TSel)

func SortByStable

func SortByStable[TElem any, TSel OrderedConstraint](arr []TElem, selector func(v TElem) TSel)

func SortSlice

func SortSlice[T any](arr []T, less func(v1, v2 T) bool)

func SortSliceStable

func SortSliceStable[T any](arr []T, less func(v1, v2 T) bool)

func SortStable

func SortStable[T OrderedConstraint](arr []T)

func StrLimit

func StrLimit(val string, maxlen int, suffix string) string

func StrPadLeft

func StrPadLeft(str string, pad string, padlen int) string

func StrPadRight

func StrPadRight(str string, pad string, padlen int) string

func StrRepeat

func StrRepeat(val string, count int) string

func StrRunePadLeft

func StrRunePadLeft(str string, pad string, padlen int) string

func StrRunePadRight

func StrRunePadRight(str string, pad string, padlen int) string

func StrSplit

func StrSplit(val string, sep string, allowEmpty bool) []string

func StrWrap

func StrWrap(val string, linelen int, seperator string) string

func TryPrettyPrintJson

func TryPrettyPrintJson(str string) string

func WriteNopCloser

func WriteNopCloser(w io.Writer) io.WriteCloser

Types

type A

type A []any

type AnyBaseConverter

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

func NewAnyBaseConverter

func NewAnyBaseConverter(cs string) AnyBaseConverter

func (AnyBaseConverter) Decode

func (bc AnyBaseConverter) Decode(src string) ([]byte, error)

func (AnyBaseConverter) DecodeToBigInt

func (bc AnyBaseConverter) DecodeToBigInt(_src string) (*big.Int, error)

func (AnyBaseConverter) DecodeUInt64

func (bc AnyBaseConverter) DecodeUInt64(str string) (uint64, error)

func (AnyBaseConverter) Encode

func (bc AnyBaseConverter) Encode(src []byte) string

func (AnyBaseConverter) EncodeBigInt

func (bc AnyBaseConverter) EncodeBigInt(src *big.Int) string

func (AnyBaseConverter) EncodeUInt64

func (bc AnyBaseConverter) EncodeUInt64(num uint64) string

func (AnyBaseConverter) Rand

func (bc AnyBaseConverter) Rand(rlen int) string

type B58Encoding

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

func (*B58Encoding) Decode

func (enc *B58Encoding) Decode(src []byte) ([]byte, error)

func (*B58Encoding) DecodeString

func (enc *B58Encoding) DecodeString(src string) (string, error)

func (*B58Encoding) Encode

func (enc *B58Encoding) Encode(src []byte) ([]byte, error)

func (*B58Encoding) EncodeString

func (enc *B58Encoding) EncodeString(src string) (string, error)

type ComplexConstraint

type ComplexConstraint interface {
	~complex64 | ~complex128
}

type FloatConstraint

type FloatConstraint interface {
	~float32 | ~float64
}

type H

type H map[string]any

type IntConstraint

type IntConstraint interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64
}

type IntegerConstraint

type IntegerConstraint interface {
	SignedConstraint | UnsignedConstraint
}

type MapEntry

type MapEntry[T comparable, V any] struct {
	Key   T
	Value V
}

func MapToArr

func MapToArr[T comparable, V any](v map[T]V) []MapEntry[T, V]

type NumberConstraint

type NumberConstraint interface {
	IntegerConstraint | FloatConstraint
}

type OrderedConstraint

type OrderedConstraint interface {
	IntegerConstraint | FloatConstraint | ~string
}

type PanicWrappedErr

type PanicWrappedErr struct {
	Stack string
	// contains filtered or unexported fields
}

func (PanicWrappedErr) Error

func (p PanicWrappedErr) Error() string

func (PanicWrappedErr) RecoveredObj

func (p PanicWrappedErr) RecoveredObj() any

type SignedConstraint

type SignedConstraint interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type UnsignedConstraint

type UnsignedConstraint interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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