Documentation
¶
Index ¶
- Variables
- func Abs(n int64) int64
- func All[T comparable](s ...T) bool
- func Any[T comparable](s ...T) bool
- func Bind1Arg0Ret[A1 any](fn func(A1), a1 A1) func()
- func Bind1Arg1Ret[A1 any, R1 any](fn func(A1) R1, a1 A1) func() R1
- func Bind1Arg2Ret[A1 any, R1 any, R2 any](fn func(A1) (R1, R2), a1 A1) func() (R1, R2)
- func Bind1Arg3Ret[A1 any, R1 any, R2 any, R3 any](fn func(A1) (R1, R2, R3), a1 A1) func() (R1, R2, R3)
- func Bind2Arg0Ret[A1 any, A2 any](fn func(A1, A2), a1 A1, a2 A2) func()
- func Bind2Arg1Ret[A1 any, A2 any, R1 any](fn func(A1, A2) R1, a1 A1, a2 A2) func() R1
- func Bind2Arg2Ret[A1 any, A2 any, R1 any, R2 any](fn func(A1, A2) (R1, R2), a1 A1, a2 A2) func() (R1, R2)
- func Bind2Arg3Ret[A1 any, A2 any, R1 any, R2 any, R3 any](fn func(A1, A2) (R1, R2, R3), a1 A1, a2 A2) func() (R1, R2, R3)
- func Bind3Arg0Ret[A1 any, A2 any, A3 any](fn func(A1, A2, A3), a1 A1, a2 A2, a3 A3) func()
- func Bind3Arg1Ret[A1 any, A2 any, A3 any, R1 any](fn func(A1, A2, A3) R1, a1 A1, a2 A2, a3 A3) func() R1
- func Bind3Arg2Ret[A1 any, A2 any, A3 any, R1 any, R2 any](fn func(A1, A2, A3) (R1, R2), a1 A1, a2 A2, a3 A3) func() (R1, R2)
- func Bind3Arg3Ret[A1 any, A2 any, A3 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3) (R1, R2, R3), a1 A1, a2 A2, a3 A3) func() (R1, R2, R3)
- func Bind4Arg0Ret[A1 any, A2 any, A3 any, A4 any](fn func(A1, A2, A3, A4), a1 A1, a2 A2, a3 A3, a4 A4) func()
- func Bind4Arg1Ret[A1 any, A2 any, A3 any, A4 any, R1 any](fn func(A1, A2, A3, A4) R1, a1 A1, a2 A2, a3 A3, a4 A4) func() R1
- func Bind4Arg2Ret[A1 any, A2 any, A3 any, A4 any, R1 any, R2 any](fn func(A1, A2, A3, A4) (R1, R2), a1 A1, a2 A2, a3 A3, a4 A4) func() (R1, R2)
- func Bind4Arg3Ret[A1 any, A2 any, A3 any, A4 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3, A4) (R1, R2, R3), a1 A1, a2 A2, a3 A3, a4 A4) func() (R1, R2, R3)
- func Bind5Arg0Ret[A1 any, A2 any, A3 any, A4 any, A5 any](fn func(A1, A2, A3, A4, A5), a1 A1, a2 A2, a3 A3, a4 A4, a5 A5) func()
- func Bind5Arg1Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any](fn func(A1, A2, A3, A4, A5) R1, a1 A1, a2 A2, a3 A3, a4 A4, a5 A5) func() R1
- func Bind5Arg2Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any, R2 any](fn func(A1, A2, A3, A4, A5) (R1, R2), a1 A1, a2 A2, a3 A3, a4 A4, a5 A5) func() (R1, R2)
- func Bind5Arg3Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3, A4, A5) (R1, R2, R3), a1 A1, a2 A2, a3 A3, a4 A4, a5 A5) func() (R1, R2, R3)
- func Chunk[T any, S ~[]T](s S, chunkSize int) []S
- func ChunkByPieces[T any, S ~[]T](s S, chunkCount int) []S
- func Clamp[T NumberExt | StringExt](value, min, max T) T
- func Coalesce[T comparable](args ...T) (result T)
- func Compact[T comparable, S ~[]T](s S) S
- func Concat[T any, S ~[]T](slices ...S) S
- func Contain[T comparable, S ~[]T](a S, t T) bool
- func ContainAll[T comparable, S ~[]T](a S, b ...T) bool
- func ContainAny[T comparable, S ~[]T](a S, b ...T) bool
- func ContainBy[T any, S ~[]T](a S, pred func(t T) bool) bool
- func ContainByPtr[T any, S ~[]T](a S, pred func(t *T) bool) bool
- func ContainSlice[T comparable, S ~[]T](a, b S) bool
- func ContentEqual[T comparable, S ~[]T](a, b S) bool
- func ContentEqualBy[T any, K comparable, S ~[]T](a, b S, keyFunc func(t T) K) bool
- func ContentEqualPtr[T comparable, S ~[]*T](a, b S) bool
- func CountValue[T comparable, S ~[]T](a S, val T) int
- func CountValueBy[T any, S ~[]T](a S, pred func(t T) bool) int
- func Difference[T comparable, S ~[]T](a, b S) (S, S)
- func DifferenceBy[T any, K comparable, S ~[]T](a, b S, keyFunc func(t T) K) (S, S)
- func Drop[T comparable, S ~[]T](a S, values ...T) S
- func Equal[T comparable, S ~[]T](a, b S) bool
- func EqualBy[T any, S ~[]T](a, b S, equalCmp func(a, b T) bool) bool
- func EqualByPtr[T any, S ~[]T](a, b S, equalCmp func(a, b *T) bool) bool
- func ErrUnwrap(err error) []error
- func ErrUnwrapToRoot(err error) error
- func ErrWrap(err error, msg string) error
- func ErrWrapL(msg string, err error) error
- func ExecDuration(fn func()) time.Duration
- func ExecDuration1[T any](fn func() T) (T, time.Duration)
- func ExecDuration2[T1, T2 any](fn func() (T1, T2)) (T1, T2, time.Duration)
- func ExecDuration3[T1, T2, T3 any](fn func() (T1, T2, T3)) (T1, T2, T3, time.Duration)
- func ExecRetry(fn func() error, maxRetries int, delay time.Duration, ...) error
- func ExecRetry2[T any](fn func() (T, error), maxRetries int, delay time.Duration, ...) (T, error)
- func ExecRetry3[T1, T2 any](fn func() (T1, T2, error), maxRetries int, delay time.Duration, ...) (T1, T2, error)
- func ExecRetry4[T1, T2, T3 any](fn func() (T1, T2, T3, error), maxRetries int, delay time.Duration, ...) (T1, T2, T3, error)
- func ExecRetry5[T1, T2, T3, T4 any](fn func() (T1, T2, T3, T4, error), maxRetries int, delay time.Duration, ...) (T1, T2, T3, T4, error)
- func ExecRetryCtx(ctx context.Context, fn func() error, maxRetries int, delay time.Duration, ...) error
- func ExecRetryCtx2[T any](ctx context.Context, fn func() (T, error), maxRetries int, delay time.Duration, ...) (T, error)
- func ExecRetryCtx3[T1, T2 any](ctx context.Context, fn func() (T1, T2, error), maxRetries int, ...) (T1, T2, error)
- func ExecRetryCtx4[T1, T2, T3 any](ctx context.Context, fn func() (T1, T2, T3, error), maxRetries int, ...) (T1, T2, T3, error)
- func ExecRetryCtx5[T1, T2, T3, T4 any](ctx context.Context, fn func() (T1, T2, T3, T4, error), maxRetries int, ...) (T1, T2, T3, T4, error)
- func ExecTaskFunc[T any](ctx context.Context, maxConcurrentTasks uint, ...) error
- func ExecTaskFuncEx[T any](ctx context.Context, maxConcurrentTasks uint, stopOnError bool, ...) map[int]error
- func ExecTasks(ctx context.Context, maxConcurrentTasks uint, ...) error
- func ExecTasksEx(ctx context.Context, maxConcurrentTasks uint, stopOnError bool, ...) map[int]error
- func FastRemove[T comparable, S ~[]T](ps *S, v T) bool
- func FastRemoveAt[T any, S ~[]T](ps *S, i int)
- func FastRemoveLastOf[T comparable, S ~[]T](ps *S, v T) bool
- func Fill[T any, S ~[]T](a S, val T)
- func Filter[T any, S ~[]T](s S, filterFunc func(t T) bool) S
- func FilterGT[T NumberExt | StringExt, S ~[]T](s S, v T) S
- func FilterGTE[T NumberExt | StringExt, S ~[]T](s S, v T) S
- func FilterILIKE[T StringExt, S ~[]T](s S, v string) S
- func FilterIN[T comparable, S ~[]T](s S, v ...T) S
- func FilterLIKE[T StringExt, S ~[]T](s S, v string) S
- func FilterLT[T NumberExt | StringExt, S ~[]T](s S, v T) S
- func FilterLTE[T NumberExt | StringExt, S ~[]T](s S, v T) S
- func FilterNE[T comparable, S ~[]T](s S, v T) S
- func FilterNIN[T comparable, S ~[]T](s S, v ...T) S
- func FilterPtr[T any, S ~[]T](s S, filterFunc func(t *T) bool) S
- func FilterRange[T NumberExt | StringExt, S ~[]T](s S, min, max T) S
- func Find[T any, S ~[]T](a S, pred func(t T) bool) (t T, found bool)
- func FindDuplicates[T comparable, S ~[]T](s S) S
- func FindDuplicatesBy[T any, U comparable, S ~[]T](s S, keyFunc func(T) U) S
- func FindEx[T any, V any, S ~[]T](a S, pred func(t T) (V, bool)) (v V, found bool)
- func FindLast[T any, S ~[]T](a S, pred func(t T) bool) (t T, found bool)
- func FindLastEx[T any, V any, S ~[]T](a S, pred func(t T) (V, bool)) (v V, found bool)
- func FindLastPtr[T any, S ~[]T](a S, pred func(t *T) bool) (t T, found bool)
- func FindPtr[T any, S ~[]T](a S, pred func(t *T) bool) (t T, found bool)
- func FindUniques[T comparable, S ~[]T](s S) S
- func FindUniquesBy[T any, U comparable, S ~[]T](s S, keyFunc func(T) U) S
- func First[T any, S ~[]T](s S) (T, bool)
- func FirstNonEmpty[T any](args ...T) (val T)
- func FirstOr[T any, S ~[]T](s S, defaultVal T) T
- func Flatten[T any, S ~[]T](s ...S) S
- func Flatten3[T any, S ~[]T, SS ~[]S](s ...SS) S
- func ForEach[T any, S ~[]T](s S, pred func(i int, t T))
- func ForEachPtr[T any, S ~[]T](s S, pred func(i int, t *T))
- func ForEachPtrReverse[T any, S ~[]T](s S, pred func(i int, t *T))
- func ForEachReverse[T any, S ~[]T](s S, pred func(i int, t T))
- func FormatFloat[T FloatExt](v T) string
- func FormatFloatEx[T FloatExt](v T, format string) string
- func FormatFloatGroup[T FloatExt](v T) string
- func FormatFloatGroupEx[T FloatExt](v T, format string) string
- func FormatInt[T IntExt](v T) string
- func FormatIntEx[T IntExt](v T, format string) string
- func FormatIntGroup[T IntExt](v T) string
- func FormatUint[T UIntExt](v T) string
- func FormatUintEx[T UIntExt](v T, format string) string
- func FormatUintGroup[T UIntExt](v T) string
- func Head[T any](t T, s ...any) T
- func If[C bool, T any](cond C, v1 T, v2 T) T
- func IndexOf[T comparable, S ~[]T](a S, t T) int
- func IndexOfBy[T any, S ~[]T](a S, pred func(t T) bool) int
- func IndexOfSlice[T comparable, S ~[]T](a, sub S) int
- func Intersection[T comparable, S ~[]T](a, b S) S
- func IntersectionBy[T any, K comparable, S ~[]T](a, b S, keyFunc func(t T) K) S
- func IsSorted[T NumberExt | StringExt, S ~[]T](s S) bool
- func IsSortedDesc[T NumberExt | StringExt, S ~[]T](s S) bool
- func IsUnique[T comparable, S ~[]T](s S) bool
- func IsUniqueBy[T any, U comparable, S ~[]T](s S, keyFunc func(t T) U) bool
- func Iter[T any, S ~[]T](iterFunc func(index int, v T) bool, slices ...S)
- func IterPtr[T any, S ~[]T](iterFunc func(index int, v *T) bool, slices ...S)
- func IterPtrReverse[T any, S ~[]T](iterFunc func(index int, v *T) bool, slices ...S)
- func IterReverse[T any, S ~[]T](iterFunc func(index int, v T) bool, slices ...S)
- func Last[T any, S ~[]T](s S) (T, bool)
- func LastIndexOf[T comparable, S ~[]T](a S, t T) int
- func LastIndexOfBy[T any, S ~[]T](a S, pred func(t T) bool) int
- func LastIndexOfSlice[T comparable, S ~[]T](a, sub S) int
- func LastOr[T any, S ~[]T](s S, defaultVal T) T
- func LinesTrim(s string, cutset string) string
- func LinesTrimLeft(s string, cutset string) string
- func LinesTrimLeftSpace(s string) string
- func LinesTrimRight(s string, cutset string) string
- func LinesTrimRightSpace(s string) string
- func LinesTrimSpace(s string) string
- func MapContainKeys[K comparable, V any, M ~map[K]V](m M, keys ...K) bool
- func MapContainValues[K comparable, V comparable, M ~map[K]V](m M, values ...V) bool
- func MapCopy[K comparable, V any, M ~map[K]V](m M) M
- func MapDifferenceKeys[K comparable, V any, M ~map[K]V](m1, m2 M) ([]K, []K)
- func MapEqual[K comparable, V comparable, M ~map[K]V](m1, m2 M) bool
- func MapEqualBy[K comparable, V any, M ~map[K]V](m1, m2 M, equalCmp func(v1, v2 V) bool) bool
- func MapGet[K comparable, V any, M ~map[K]V](m M, k K, defaultVal V) V
- func MapIntersectionKeys[K comparable, V any, M ~map[K]V](m1 M, ms ...M) []K
- func MapIter[K comparable, V any, M ~map[K]V](iterFunc func(K, V), mapSlice ...M)
- func MapKeys[K comparable, V any, M ~map[K]V](m M) []K
- func MapOmit[K comparable, V any, M ~map[K]V](m M, keys ...K)
- func MapOmitCopy[K comparable, V any, M ~map[K]V](m M, keys ...K) M
- func MapPick[K comparable, V any, M ~map[K]V](m M, keys ...K) M
- func MapPop[K comparable, V any, M ~map[K]V](m M, k K, defaultVal V) V
- func MapReverse[K comparable, V comparable, M ~map[K]V, M2 map[V]K](m M) (M2, []K)
- func MapSetDefault[K comparable, V any, M ~map[K]V](m M, k K, defaultVal V) V
- func MapSlice[T any, U any, S ~[]T](s S, mapFunc func(T) U) []U
- func MapSliceEx[T any, U any, S ~[]T](s S, mapFunc func(T) (U, error)) ([]U, error)
- func MapSliceToMap[T any, K comparable, V any, S ~[]T](s S, mapFunc func(T) (K, V)) map[K]V
- func MapSliceToMapEx[T any, K comparable, V any, S ~[]T](s S, mapFunc func(T) (K, V, error)) (map[K]V, error)
- func MapSliceToMapKeys[T comparable, V any, S ~[]T](s S, defaultVal V) map[T]V
- func MapUnionKeys[K comparable, V any, M ~map[K]V](m1 M, ms ...M) []K
- func MapUpdate[K comparable, V any, M ~map[K]V](m1, m2 M) M
- func MapUpdateExistingOnly[K comparable, V any, M ~map[K]V](m1, m2 M) M
- func MapUpdateNewOnly[K comparable, V any, M ~map[K]V](m1, m2 M) M
- func MapValues[K comparable, V any](m map[K]V) []V
- func Max[T NumberExt | StringExt](v1 T, s ...T) T
- func MaxIn[T NumberExt | StringExt, S ~[]T](s S) (T, error)
- func MaxInBy[T any, S ~[]T](s S, lessFunc func(a, b T) bool) (T, error)
- func MaxTime(t1 time.Time, s ...time.Time) time.Time
- func Min[T NumberExt | StringExt](v1 T, s ...T) T
- func MinIn[T NumberExt | StringExt, S ~[]T](s S) (T, error)
- func MinInBy[T any, S ~[]T](s S, lessFunc func(a, b T) bool) (T, error)
- func MinMax[T NumberExt | StringExt](v1 T, s ...T) (T, T)
- func MinMaxTime(t1 time.Time, s ...time.Time) (time.Time, time.Time)
- func MinTime(t1 time.Time, s ...time.Time) time.Time
- func Must[T any](v T, e error) T
- func Must1(e error)
- func Must2[T any](v T, e error) T
- func Must3[T1, T2 any](v1 T1, v2 T2, e error) (T1, T2)
- func Must4[T1, T2, T3 any](v1 T1, v2 T2, v3 T3, e error) (T1, T2, T3)
- func Must5[T1, T2, T3, T4 any](v1 T1, v2 T2, v3 T3, v4 T4, e error) (T1, T2, T3, T4)
- func Must6[T1, T2, T3, T4, T5 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, e error) (T1, T2, T3, T4, T5)
- func NumberFmtGroup(num string, fractionSep, groupSep byte) string
- func NumberFmtUngroup(num string, groupSep byte) string
- func ParseFloat[T FloatExt](s string) (T, error)
- func ParseFloatDef[T FloatExt](s string, defaultVal T) T
- func ParseFloatUngroup[T FloatExt](s string) (T, error)
- func ParseInt[T IntExt](s string) (T, error)
- func ParseIntDef[T IntExt](s string, defaultVal T) T
- func ParseIntEx[T IntExt](s string, base int) (T, error)
- func ParseIntUngroup[T IntExt](s string) (T, error)
- func ParseUint[T UIntExt](s string) (T, error)
- func ParseUintDef[T UIntExt](s string, defaultVal T) T
- func ParseUintEx[T UIntExt](s string, base int) (T, error)
- func ParseUintUngroup[T UIntExt](s string) (T, error)
- func Partial2Arg0Ret[A1 any, A2 any](fn func(A1, A2), a1 A1) func(A2)
- func Partial2Arg1Ret[A1 any, A2 any, R1 any](fn func(A1, A2) R1, a1 A1) func(A2) R1
- func Partial2Arg2Ret[A1 any, A2 any, R1 any, R2 any](fn func(A1, A2) (R1, R2), a1 A1) func(A2) (R1, R2)
- func Partial2Arg3Ret[A1 any, A2 any, R1 any, R2 any, R3 any](fn func(A1, A2) (R1, R2, R3), a1 A1) func(A2) (R1, R2, R3)
- func Partial3Arg0Ret[A1 any, A2 any, A3 any](fn func(A1, A2, A3), a1 A1) func(A2, A3)
- func Partial3Arg1Ret[A1 any, A2 any, A3 any, R1 any](fn func(A1, A2, A3) R1, a1 A1) func(A2, A3) R1
- func Partial3Arg2Ret[A1 any, A2 any, A3 any, R1 any, R2 any](fn func(A1, A2, A3) (R1, R2), a1 A1) func(A2, A3) (R1, R2)
- func Partial3Arg3Ret[A1 any, A2 any, A3 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3) (R1, R2, R3), a1 A1) func(A2, A3) (R1, R2, R3)
- func Partial4Arg0Ret[A1 any, A2 any, A3 any, A4 any](fn func(A1, A2, A3, A4), a1 A1) func(A2, A3, A4)
- func Partial4Arg1Ret[A1 any, A2 any, A3 any, A4 any, R1 any](fn func(A1, A2, A3, A4) R1, a1 A1) func(A2, A3, A4) R1
- func Partial4Arg2Ret[A1 any, A2 any, A3 any, A4 any, R1 any, R2 any](fn func(A1, A2, A3, A4) (R1, R2), a1 A1) func(A2, A3, A4) (R1, R2)
- func Partial4Arg3Ret[A1 any, A2 any, A3 any, A4 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3, A4) (R1, R2, R3), a1 A1) func(A2, A3, A4) (R1, R2, R3)
- func Partial5Arg0Ret[A1 any, A2 any, A3 any, A4 any, A5 any](fn func(A1, A2, A3, A4, A5), a1 A1) func(A2, A3, A4, A5)
- func Partial5Arg1Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any](fn func(A1, A2, A3, A4, A5) R1, a1 A1) func(A2, A3, A4, A5) R1
- func Partial5Arg2Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any, R2 any](fn func(A1, A2, A3, A4, A5) (R1, R2), a1 A1) func(A2, A3, A4, A5) (R1, R2)
- func Partial5Arg3Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3, A4, A5) (R1, R2, R3), a1 A1) func(A2, A3, A4, A5) (R1, R2, R3)
- func Partition[T any, S ~[]T](s S, partitionFunc func(T, int) bool) (S, S)
- func PartitionN[T any, S ~[]T](s S, numPartitions uint, partitionFunc func(T, int) int) []S
- func Product[T NumberExt | ComplexExt](s ...T) T
- func ProductAs[U, T NumberExt](s ...T) U
- func PtrValueOrEmpty[T any](t *T) (val T)
- func RandChoice[T any](s ...T) (T, bool)
- func RandString(n int) string
- func RandStringEx[S ~[]rune](n int, allowedChars S) string
- func RandToken(length int) []byte
- func RandTokenAsHex(length int) string
- func Reduce[T any, S ~[]T](s S, reduceFunc func(accumulator, currentValue T) T) T
- func ReduceEx[T any, U any, S ~[]T](s S, reduceFunc func(accumulator U, currentValue T, currentIndex int) U, ...) U
- func ReduceReverse[T any, S ~[]T](s S, reduceFunc func(accumulator, currentValue T) T) T
- func ReduceReverseEx[T any, U any, S ~[]T](s S, reduceFunc func(accumulator U, currentValue T, currentIndex int) U, ...) U
- func Remove[T comparable, S ~[]T](ps *S, v T) bool
- func RemoveAll[T comparable, S ~[]T](ps *S, v T) int
- func RemoveAt[T any, S ~[]T](ps *S, i int)
- func RemoveLastOf[T comparable, S ~[]T](ps *S, v T) bool
- func Replace[T comparable, S ~[]T](s S, value, replacement T) bool
- func ReplaceAll[T comparable, S ~[]T](s S, value, replacement T) int
- func ReplaceN[T comparable, S ~[]T](s S, value, replacement T, n int) int
- func Reverse[T any, S ~[]T](s S) S
- func ReverseCopy[T any, S ~[]T](s S) S
- func Shuffle[T any, S ~[]T](s S, randFuncs ...func(n int) int) S
- func SliceByRange[T NumberExt](start, end, step T) []T
- func Sort[T NumberExt | StringExt, S ~[]T](s S) S
- func SortDesc[T NumberExt | StringExt, S ~[]T](s S) S
- func SortEx[T any, S ~[]T](s S, less func(i, j int) bool) S
- func SortStable[T NumberExt | StringExt, S ~[]T](s S) S
- func SortStableDesc[T NumberExt | StringExt, S ~[]T](s S) S
- func SortStableEx[T any, S ~[]T](s S, less func(i, j int) bool) S
- func Splice[T any, S ~[]T](s S, start, deleteCount int, newItems ...T) S
- func SpliceEx[T any, S ~[]T](s S, start, deleteCount int, newItems ...T) (S, S)
- func StringJoin[T any, S ~[]T](s S, sep string) string
- func StringJoinBy[T any, S ~[]T](s S, sep string, fmtFunc func(v T) string) string
- func StringJoinEx[T any, S ~[]T](s S, sep, format string) string
- func StringLexJoin[T any, S ~[]T](s S, sep, lastSep string) string
- func StringLexJoinEx[T any, S ~[]T](s S, sep, lastSep, format string) string
- func StringSplit(s string, sep, quote string) (res []string)
- func StringSplitN(s string, sep, quote string, n int) (res []string)
- func StringToLower1stLetter(s string) string
- func StringToUpper1stLetter(s string) string
- func StringUnwrap(s string, token string) string
- func StringUnwrapLR(s string, tokenLeft, tokenRight string) string
- func StringWrap(s string, token string) string
- func StringWrapLR(s string, tokenLeft, tokenRight string) string
- func SubSlice[T any, S ~[]T](s S, start, end int) S
- func Sum[T NumberExt | ComplexExt](s ...T) T
- func SumAs[U, T NumberExt](s ...T) U
- func Tail[T any](t any, s ...any) (T, bool)
- func ToIfaceSlice[T any, S ~[]T](s S) []any
- func ToNumberSlice[U, T NumberExt, S ~[]T](slice S) []U
- func ToPtr[T any](t T) *T
- func ToPtrSlice[T any, S ~[]T](s S) []*T
- func ToSafeInt8[T IntExt | UIntExt](v T) (int8, error)
- func ToSafeInt16[T IntExt | UIntExt](v T) (int16, error)
- func ToSafeInt32[T IntExt | UIntExt](v T) (int32, error)
- func ToSafeInt64[T IntExt | UIntExt](v T) (int64, error)
- func ToSafeUint8[T IntExt | UIntExt](v T) (uint8, error)
- func ToSafeUint16[T IntExt | UIntExt](v T) (uint16, error)
- func ToSafeUint32[T IntExt | UIntExt](v T) (uint32, error)
- func ToSafeUint64[T IntExt | UIntExt](v T) (uint64, error)
- func ToSet[T comparable, S ~[]T](s S) S
- func ToSetBy[T any, K comparable, S ~[]T](s S, keyFunc func(t T) K) S
- func ToSetByReverse[T any, K comparable, S ~[]T](s S, keyFunc func(t T) K) S
- func ToSlice[T any](s ...T) []T
- func ToSliceSkippingNil[T any](values ...*T) []*T
- func ToSliceSkippingZero[T comparable](values ...T) []T
- func ToStringSlice[U, T ~string, S ~[]T](slice S) []U
- func Union[T comparable, S ~[]T](a, b S) S
- func UnionBy[T any, K comparable, S ~[]T](a, b S, keyFunc func(t T) K) S
- type Complex
- type ComplexExt
- type ComplexPtr
- type ExecRetryConfig
- type ExecRetryOption
- func ExecRetryCheck(checkFunc func(error) bool) ExecRetryOption
- func ExecRetryDelayExpoBackoff(jitter time.Duration) ExecRetryOption
- func ExecRetryDelayIncr(incremental time.Duration) ExecRetryOption
- func ExecRetryDelayMax(maxDelay time.Duration) ExecRetryOption
- func ExecRetryIfErrorIs(errs ...error) ExecRetryOption
- func ExecRetryIfErrorIsNot(errs ...error) ExecRetryOption
- type Float
- type FloatExt
- type FloatPtr
- type Int
- type IntExt
- type IntPtr
- type Number
- type NumberExt
- type NumberPtr
- type RandChoiceMaker
- type String
- type StringExt
- type StringPtr
- type Tuple2
- type Tuple3
- type Tuple4
- type Tuple5
- type UInt
- type UIntExt
- type UIntPtr
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmpty = errors.New("container is empty") ErrIndexOutOfRange = errors.New("index out of range") ErrOverflow = errors.New("overflow") ErrPanic = errors.New("panic occurred") )
var ( StrLowerAlpha = []rune("abcdefghijklmnopqrstuvwxyz") StrUpperAlpha = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ") StrAlpha = Concat(StrLowerAlpha, StrUpperAlpha) StrDigits = []rune("0123456789") StrAlphaNumeric = Concat(StrAlpha, StrDigits) StrSpecialChars = []rune("~!@#$%^&*()-_+`'\";:,.<>/?{[}]\\|") StrAllChars = Concat(StrAlpha, StrDigits, StrSpecialChars) StrDefaultChars = StrAlphaNumeric )
var ( StructToMap = rflutil.StructToMap ParseTag = rflutil.ParseTag ParseTagOf = rflutil.ParseTagOf ParseTagsOf = rflutil.ParseTagsOf )
var ExecDelay = time.AfterFunc
ExecDelay is an alias of time.AfterFunc
var MultilineString = LinesTrimLeftSpace
Deprecated
var RuneLength = utf8.RuneCountInString
RuneLength alias of utf8.RuneCountInString
Functions ¶
func Abs ¶
Abs calculates absolute value of an integer. Ref: http://cavaliercoder.com/blog/optimized-abs-for-int64-in-go.html. Note: if inputs MinInt64, the result is negative.
func All ¶
func All[T comparable](s ...T) bool
All returns true if all given values are evaluated as `true`
func Any ¶
func Any[T comparable](s ...T) bool
Any returns true if at least one of given values is evaluated as `true`
func Bind1Arg0Ret ¶ added in v1.5.0
func Bind1Arg0Ret[A1 any](fn func(A1), a1 A1) func()
func Bind1Arg1Ret ¶ added in v1.5.0
func Bind1Arg2Ret ¶ added in v1.5.0
func Bind1Arg3Ret ¶ added in v1.5.0
func Bind2Arg0Ret ¶ added in v1.5.0
func Bind2Arg1Ret ¶ added in v1.5.0
func Bind2Arg2Ret ¶ added in v1.5.0
func Bind2Arg3Ret ¶ added in v1.5.0
func Bind2Arg3Ret[A1 any, A2 any, R1 any, R2 any, R3 any](fn func(A1, A2) (R1, R2, R3), a1 A1, a2 A2) func() (R1, R2, R3)
nolint: lll
func Bind3Arg0Ret ¶ added in v1.5.0
func Bind3Arg1Ret ¶ added in v1.5.0
func Bind3Arg2Ret ¶ added in v1.5.0
func Bind3Arg2Ret[A1 any, A2 any, A3 any, R1 any, R2 any](fn func(A1, A2, A3) (R1, R2), a1 A1, a2 A2, a3 A3) func() (R1, R2)
nolint: lll
func Bind3Arg3Ret ¶ added in v1.5.0
func Bind3Arg3Ret[A1 any, A2 any, A3 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3) (R1, R2, R3), a1 A1, a2 A2, a3 A3) func() (R1, R2, R3)
nolint: lll
func Bind4Arg0Ret ¶ added in v1.5.0
func Bind4Arg1Ret ¶ added in v1.5.0
func Bind4Arg1Ret[A1 any, A2 any, A3 any, A4 any, R1 any](fn func(A1, A2, A3, A4) R1, a1 A1, a2 A2, a3 A3, a4 A4) func() R1
nolint: lll
func Bind4Arg2Ret ¶ added in v1.5.0
func Bind4Arg2Ret[A1 any, A2 any, A3 any, A4 any, R1 any, R2 any](fn func(A1, A2, A3, A4) (R1, R2), a1 A1, a2 A2, a3 A3, a4 A4) func() (R1, R2)
nolint: lll
func Bind4Arg3Ret ¶ added in v1.5.0
func Bind4Arg3Ret[A1 any, A2 any, A3 any, A4 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3, A4) (R1, R2, R3), a1 A1, a2 A2, a3 A3, a4 A4) func() (R1, R2, R3)
nolint: lll
func Bind5Arg0Ret ¶ added in v1.5.0
func Bind5Arg0Ret[A1 any, A2 any, A3 any, A4 any, A5 any](fn func(A1, A2, A3, A4, A5), a1 A1, a2 A2, a3 A3, a4 A4, a5 A5) func()
nolint: lll
func Bind5Arg1Ret ¶ added in v1.5.0
func Bind5Arg1Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any](fn func(A1, A2, A3, A4, A5) R1, a1 A1, a2 A2, a3 A3, a4 A4, a5 A5) func() R1
nolint: lll
func Bind5Arg2Ret ¶ added in v1.5.0
func Bind5Arg2Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any, R2 any](fn func(A1, A2, A3, A4, A5) (R1, R2), a1 A1, a2 A2, a3 A3, a4 A4, a5 A5) func() (R1, R2)
nolint: lll
func Bind5Arg3Ret ¶ added in v1.5.0
func Bind5Arg3Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3, A4, A5) (R1, R2, R3), a1 A1, a2 A2, a3 A3, a4 A4, a5 A5) func() (R1, R2, R3)
nolint: lll
func ChunkByPieces ¶
ChunkByPieces splits slice content into chunks by number of pieces
func Coalesce ¶ added in v1.11.0
func Coalesce[T comparable](args ...T) (result T)
Coalesce returns the first non-zero value if found, otherwise returns zero.
func Contain ¶
func Contain[T comparable, S ~[]T](a S, t T) bool
Contain tests if a slice contains an item
func ContainAll ¶
func ContainAll[T comparable, S ~[]T](a S, b ...T) bool
ContainAll tests if a slice contains all given values
func ContainAny ¶
func ContainAny[T comparable, S ~[]T](a S, b ...T) bool
ContainAny tests if a slice contains any given value
func ContainByPtr ¶ added in v1.10.0
ContainByPtr tests if a slice contains an item by predicate
func ContainSlice ¶
func ContainSlice[T comparable, S ~[]T](a, b S) bool
ContainSlice tests if a slice contains a slice
func ContentEqual ¶
func ContentEqual[T comparable, S ~[]T](a, b S) bool
ContentEqual compares 2 slices without caring about order. NOTE: if you want to compare content of slices of pointers, use ContentEqualPtr.
func ContentEqualBy ¶ added in v1.10.0
func ContentEqualBy[T any, K comparable, S ~[]T](a, b S, keyFunc func(t T) K) bool
ContentEqualBy compares 2 slices without preserving order
func ContentEqualPtr ¶
func ContentEqualPtr[T comparable, S ~[]*T](a, b S) bool
ContentEqualPtr compares 2 slices of pointers without caring about order
func CountValue ¶
func CountValue[T comparable, S ~[]T](a S, val T) int
CountValue counts number of occurrences of an item in the slice
func CountValueBy ¶ added in v1.10.0
CountValueBy counts number of occurrences of an item in the slice
func Difference ¶
func Difference[T comparable, S ~[]T](a, b S) (S, S)
Difference calculates the differences between two slices. The first result list contains all the values exist in the left list, but the right. The second result list contains all the values exist in the right list, but the left. NOTE: this function does not return unique values.
func DifferenceBy ¶ added in v1.10.0
func DifferenceBy[T any, K comparable, S ~[]T](a, b S, keyFunc func(t T) K) (S, S)
DifferenceBy calculates the differences between two slices using special key function. NOTE: this function does not return unique values.
func Drop ¶ added in v1.9.0
func Drop[T comparable, S ~[]T](a S, values ...T) S
Drop returns a copied slice with dropping items in the list
func Equal ¶
func Equal[T comparable, S ~[]T](a, b S) bool
Equal compares 2 slices with preserving order
func EqualByPtr ¶ added in v1.10.0
EqualByPtr compares 2 slices with preserving order
func ErrUnwrap ¶ added in v1.14.0
ErrUnwrap unwraps an error to get a slice. This function can unwrap error created by errors.Join() and fmt.Errorf(<multiple errors passed>). In case there's only single item wrapped in the input, the slice has only 1 item.
func ErrUnwrapToRoot ¶ added in v1.14.0
ErrUnwrapToRoot unwraps an error until the deepest one
func ExecDuration ¶ added in v1.10.0
ExecDuration measures time duration of running a function
func ExecDuration1 ¶ added in v1.10.0
ExecDuration1 measures time duration of running a function
func ExecDuration2 ¶ added in v1.10.0
ExecDuration2 measures time duration of running a function
func ExecDuration3 ¶ added in v1.10.0
ExecDuration3 measures time duration of running a function
func ExecRetry2 ¶ added in v1.17.0
func ExecRetry3 ¶ added in v1.17.0
func ExecRetry4 ¶ added in v1.17.0
func ExecRetry5 ¶ added in v1.17.0
func ExecRetryCtx ¶ added in v1.17.0
func ExecRetryCtx2 ¶ added in v1.17.0
func ExecRetryCtx3 ¶ added in v1.17.0
func ExecRetryCtx4 ¶ added in v1.17.0
func ExecRetryCtx5 ¶ added in v1.17.0
func ExecTaskFunc ¶ added in v1.9.0
func ExecTaskFunc[T any]( ctx context.Context, maxConcurrentTasks uint, taskFunc func(ctx context.Context, obj T) error, targetObjects ...T, ) error
ExecTaskFunc executes a function on every target objects
func ExecTaskFuncEx ¶ added in v1.9.0
func ExecTaskFuncEx[T any]( ctx context.Context, maxConcurrentTasks uint, stopOnError bool, taskFunc func(ctx context.Context, obj T) error, targetObjects ...T, ) map[int]error
ExecTaskFuncEx executes a function on every target objects
func ExecTasks ¶ added in v1.6.0
func ExecTasks( ctx context.Context, maxConcurrentTasks uint, tasks ...func(ctx context.Context) error, ) error
ExecTasks calls ExecTasksEx with stopOnError is true
func ExecTasksEx ¶ added in v1.6.0
func ExecTasksEx( ctx context.Context, maxConcurrentTasks uint, stopOnError bool, tasks ...func(ctx context.Context) error, ) map[int]error
ExecTasksEx execute multiple tasks concurrently using Go routines maxConcurrentTasks behaves similarly as `pool size`, pass 0 to set no limit. In case you want to cancel the execution, use context.WithTimeout() or context.WithCancel(). nolint: gocognit
func FastRemove ¶
func FastRemove[T comparable, S ~[]T](ps *S, v T) bool
FastRemove removes element value
func FastRemoveAt ¶
FastRemoveAt removes element at the specified index by swapping it with the last item in slice
func FastRemoveLastOf ¶
func FastRemoveLastOf[T comparable, S ~[]T](ps *S, v T) bool
FastRemoveLastOf removes element value
func FilterGTE ¶
FilterGTE returns all values which are greater than or equal to the specified value
func FilterILIKE ¶
FilterILIKE returns all strings which contain the specified substring with case-insensitive
func FilterIN ¶
func FilterIN[T comparable, S ~[]T](s S, v ...T) S
FilterIN returns all values which are present in the specified list
func FilterLIKE ¶
FilterLIKE returns all strings which contain the specified substring. Don't use wildcard in the input string. For example: FilterLIKE(names, "tom").
func FilterNE ¶
func FilterNE[T comparable, S ~[]T](s S, v T) S
FilterNE returns all values which are not equal to the specified value
func FilterNIN ¶
func FilterNIN[T comparable, S ~[]T](s S, v ...T) S
FilterNIN returns all values which are not present in the specified list
func FilterPtr ¶
FilterPtr filters slice elements using pointer in callback. This function is faster than Filter() when used on slices of structs.
func FilterRange ¶ added in v1.15.0
FilterRange returns all values which are in the specified range (lower and upper bound inclusive)
func FindDuplicates ¶ added in v1.11.0
func FindDuplicates[T comparable, S ~[]T](s S) S
FindDuplicates finds all elements that are duplicated in the given slice.
func FindDuplicatesBy ¶ added in v1.11.0
func FindDuplicatesBy[T any, U comparable, S ~[]T](s S, keyFunc func(T) U) S
FindDuplicatesBy finds all elements that are duplicated in the given slice.
func FindEx ¶ added in v1.15.0
FindEx finds value in slice with returning value decided by the given function
func FindLastEx ¶ added in v1.15.0
FindLastEx finds value in slice from the end with returning value decided by the given function
func FindLastPtr ¶ added in v1.10.0
FindLastPtr finds value in slice from the end by predicate
func FindUniques ¶ added in v1.11.0
func FindUniques[T comparable, S ~[]T](s S) S
FindUniques finds all elements that are unique in the given slice.
func FindUniquesBy ¶ added in v1.11.0
func FindUniquesBy[T any, U comparable, S ~[]T](s S, keyFunc func(T) U) S
FindUniquesBy finds all elements that are unique in the given slice.
func First ¶ added in v1.11.0
First returns the first item in slice. Returns zero value and `false` if the slice is empty.
func FirstNonEmpty ¶ added in v1.11.0
func FirstNonEmpty[T any](args ...T) (val T)
FirstNonEmpty returns the first non-empty value in the given arguments if found, otherwise returns the zero value. This function use reflection.
Non-empty value must be not:
- zero value (0, "", nil, false)
- empty slice, array, map, channel
- pointer points to zero value
func FirstOr ¶ added in v1.11.0
func FirstOr[T any, S ~[]T](s S, defaultVal T) T
FirstOr gets the first item in slice. Returns the default value if slice is empty.
func Flatten ¶
func Flatten[T any, S ~[]T](s ...S) S
Flatten flattens 2-dimensional slices. E.g. Flatten([1,2,3], [3,4,5]) -> [1,2,3,3,4,5].
func Flatten3 ¶
func Flatten3[T any, S ~[]T, SS ~[]S](s ...SS) S
Flatten3 flattens 3-dimensional slices
func ForEachPtr ¶
ForEachPtr iterates over pointers to slice items. You can use this to achieve more performance if you have a slice of big structs. For more advanced requirements, see IterPtr.
func ForEachPtrReverse ¶ added in v1.10.0
ForEachPtrReverse iterates over pointers to slice items from the end. For more advanced requirements, see IterPtrReverse.
func ForEachReverse ¶
ForEachReverse iterates over slice items from the end. For more advanced requirements, see IterReverse.
func FormatFloat ¶
func FormatFloatEx ¶
func FormatFloatGroup ¶
FormatFloatGroup format the value then group the decimal using comma
func FormatFloatGroupEx ¶
FormatFloatGroupEx format the value then group the decimal using comma
func FormatIntEx ¶
func FormatIntGroup ¶
FormatIntGroup format the value then group the decimal using comma
func FormatUint ¶
func FormatUintEx ¶
func FormatUintGroup ¶
FormatUintGroup format the value then group the decimal using comma
func If ¶
If returns the 2nd arg if the condition is true, 3rd arg otherwise. This is similar to C-language ternary operation (cond ? val1 : val2).
NOTE: this function may cause unexpected behavior upon misuses. For example: gofn.If(len(slice) > 0, slice[0], defaultVal) will crash if slice is empty
func IndexOf ¶
func IndexOf[T comparable, S ~[]T](a S, t T) int
IndexOf gets index of item in slice. Returns -1 if not found.
func IndexOfBy ¶ added in v1.10.0
IndexOfBy gets index of item in slice by predicate. Returns -1 if not found.
func IndexOfSlice ¶
func IndexOfSlice[T comparable, S ~[]T](a, sub S) int
IndexOfSlice gets index of sub-slice in slice. Returns -1 if not found.
func Intersection ¶
func Intersection[T comparable, S ~[]T](a, b S) S
Intersection returns all unique shared values from multiple slices
func IntersectionBy ¶ added in v1.10.0
func IntersectionBy[T any, K comparable, S ~[]T](a, b S, keyFunc func(t T) K) S
IntersectionBy returns all unique shared values from multiple slices with key function
func IsSortedDesc ¶
IsSortedDesc checks if a slice is sorted in descending order
func IsUnique ¶
func IsUnique[T comparable, S ~[]T](s S) bool
IsUnique checks a slice for uniqueness
func IsUniqueBy ¶ added in v1.10.0
func IsUniqueBy[T any, U comparable, S ~[]T](s S, keyFunc func(t T) U) bool
IsUniqueBy checks a slice for uniqueness using key function
func Iter ¶ added in v1.10.0
Iter iterates over items from multiple slices with ability to stop. When the `iterFunc` function returns false, the iteration stops.
func IterPtr ¶ added in v1.10.0
IterPtr iterates over pointers to items from multiple slices with ability to stop. When the `iterFunc` function returns false, the iterating stops.
func IterPtrReverse ¶ added in v1.10.0
IterPtrReverse iterates over pointers to items from multiple slices with ability to stop. When the `iterFunc` function returns false, the iteration stops.
func IterReverse ¶ added in v1.10.0
IterReverse iterates over items from multiple slices from the end with ability to stop. When the `iterFunc` function returns false, the iteration stops.
func Last ¶ added in v1.11.0
Last returns the last item in slice. Returns zero value and `false` if the slice is empty.
func LastIndexOf ¶
func LastIndexOf[T comparable, S ~[]T](a S, t T) int
LastIndexOf gets index of item from the end in slice. Returns -1 if not found.
func LastIndexOfBy ¶ added in v1.10.0
LastIndexOfBy gets index of item from the end in slice. Returns -1 if not found.
func LastIndexOfSlice ¶
func LastIndexOfSlice[T comparable, S ~[]T](a, sub S) int
LastIndexOfSlice gets last index of sub-slice in slice Returns -1 if not found
func LastOr ¶ added in v1.11.0
func LastOr[T any, S ~[]T](s S, defaultVal T) T
LastOr gets the last item in slice. Returns the default value if slice is empty.
func LinesTrim ¶
LinesTrim trim leading and trailing characters for every line in the given string. Deprecated
func LinesTrimLeft ¶
LinesTrimLeft trim leading characters for every line in the given string. Deprecated
func LinesTrimLeftSpace ¶
LinesTrimLeftSpace trim leading spaces for every line in the given string. Deprecated
func LinesTrimRight ¶
LinesTrimRight trim trailing characters for every line in the given string. Deprecated
func LinesTrimRightSpace ¶
LinesTrimRightSpace trim trailing characters for every line in the given string. Deprecated
func LinesTrimSpace ¶
LinesTrimSpace trim leading and trailing spaces for every line in the given string. Deprecated
func MapContainKeys ¶
func MapContainKeys[K comparable, V any, M ~map[K]V](m M, keys ...K) bool
MapContainKeys tests if a map contains one or more keys
func MapContainValues ¶
func MapContainValues[K comparable, V comparable, M ~map[K]V](m M, values ...V) bool
MapContainValues tests if a map contains one or more values (complexity is O(n)). If you often need to check existence of map value, consider using bi-map data structure.
func MapCopy ¶ added in v1.5.0
func MapCopy[K comparable, V any, M ~map[K]V](m M) M
MapCopy returns a copied a map
func MapDifferenceKeys ¶
func MapDifferenceKeys[K comparable, V any, M ~map[K]V](m1, m2 M) ([]K, []K)
MapDifferenceKeys returns 2 lists of keys that are differences of 2 maps
func MapEqual ¶
func MapEqual[K comparable, V comparable, M ~map[K]V](m1, m2 M) bool
MapEqual compares contents of 2 maps
func MapEqualBy ¶ added in v1.10.0
func MapEqualBy[K comparable, V any, M ~map[K]V](m1, m2 M, equalCmp func(v1, v2 V) bool) bool
MapEqualBy compares contents of 2 maps
func MapGet ¶
func MapGet[K comparable, V any, M ~map[K]V](m M, k K, defaultVal V) V
MapGet gets the value for the key, if not exist, returns the default one
func MapIntersectionKeys ¶
func MapIntersectionKeys[K comparable, V any, M ~map[K]V](m1 M, ms ...M) []K
MapIntersectionKeys returns a list of unique keys that exist in all maps
func MapIter ¶ added in v1.14.0
func MapIter[K comparable, V any, M ~map[K]V](iterFunc func(K, V), mapSlice ...M)
MapIter iterates over entries of multiple maps
func MapKeys ¶
func MapKeys[K comparable, V any, M ~map[K]V](m M) []K
MapKeys gets map keys as slice
func MapOmit ¶ added in v1.9.0
func MapOmit[K comparable, V any, M ~map[K]V](m M, keys ...K)
MapOmit omits keys from a map
func MapOmitCopy ¶ added in v1.9.0
func MapOmitCopy[K comparable, V any, M ~map[K]V](m M, keys ...K) M
MapOmitCopy returns a new map with omitting the specified keys
func MapPick ¶ added in v1.9.0
func MapPick[K comparable, V any, M ~map[K]V](m M, keys ...K) M
MapPick returns a new map with picking up the specified keys only
func MapPop ¶
func MapPop[K comparable, V any, M ~map[K]V](m M, k K, defaultVal V) V
MapPop deletes and returns the value of the key if exists, returns the default one if not
func MapReverse ¶ added in v1.13.0
func MapReverse[K comparable, V comparable, M ~map[K]V, M2 map[V]K](m M) (M2, []K)
MapReverse reverses a map by exchanging its keys and values.
func MapSetDefault ¶
func MapSetDefault[K comparable, V any, M ~map[K]V](m M, k K, defaultVal V) V
MapSetDefault sets default value for a key and returns the current value
func MapSliceEx ¶
MapSliceEx transforms a slice to another with map function and error handling
func MapSliceToMap ¶
func MapSliceToMap[T any, K comparable, V any, S ~[]T](s S, mapFunc func(T) (K, V)) map[K]V
MapSliceToMap transforms a slice to a map with map function
func MapSliceToMapEx ¶
func MapSliceToMapEx[T any, K comparable, V any, S ~[]T](s S, mapFunc func(T) (K, V, error)) (map[K]V, error)
MapSliceToMapEx transforms a slice to a map with map function and error handling
func MapSliceToMapKeys ¶ added in v1.9.0
func MapSliceToMapKeys[T comparable, V any, S ~[]T](s S, defaultVal V) map[T]V
MapSliceToMapKeys transforms a slice to a map using slice items as map keys. For example: MapSliceToMapKeys(s, struct{}{}) -> map[T]struct{}
func MapUnionKeys ¶
func MapUnionKeys[K comparable, V any, M ~map[K]V](m1 M, ms ...M) []K
MapUnionKeys returns a list of unique keys that are collected from multiple maps
func MapUpdate ¶
func MapUpdate[K comparable, V any, M ~map[K]V](m1, m2 M) M
MapUpdate merges map content with another map. Not change the target map, only change the source map.
func MapUpdateExistingOnly ¶
func MapUpdateExistingOnly[K comparable, V any, M ~map[K]V](m1, m2 M) M
MapUpdateExistingOnly update map existing items with another map. Not change the target map, only change the source map.
func MapUpdateNewOnly ¶
func MapUpdateNewOnly[K comparable, V any, M ~map[K]V](m1, m2 M) M
MapUpdateNewOnly update map with another map and not override the existing values. Not change the target map, only change the source map.
func MapValues ¶
func MapValues[K comparable, V any](m map[K]V) []V
MapValues gets map values as slice
func MaxIn ¶
MaxIn finds the maximum value in the list. Use max := Must(MaxIn(slice)) to panic on error.
func MinIn ¶
MinIn find the minimum value in the list. Use min := Must(MinIn(slice)) to panic on error.
func MinMaxTime ¶
MinMaxTime gets the minimum and maximum time values in the list
func MinTime ¶
MinTime finds the minimum time in the list. NOTE: if zero time is in the list, the result will be zero.
func NumberFmtGroup ¶
NumberFmtGroup separate decimal groups in the value string
func NumberFmtUngroup ¶
NumberFmtUngroup ungroup the value string
func ParseFloat ¶
func ParseFloatDef ¶
func ParseFloatUngroup ¶
ParseFloatUngroup omit all grouping commas then parse the string value
func ParseIntDef ¶
func ParseIntUngroup ¶
ParseIntUngroup omit all grouping commas then parse the string value
func ParseUintDef ¶
func ParseUintUngroup ¶
ParseUintUngroup omit all grouping commas then parse the string value
func Partial2Arg0Ret ¶ added in v1.13.0
func Partial2Arg1Ret ¶ added in v1.13.0
func Partial2Arg2Ret ¶ added in v1.13.0
func Partial2Arg3Ret ¶ added in v1.13.0
func Partial2Arg3Ret[A1 any, A2 any, R1 any, R2 any, R3 any](fn func(A1, A2) (R1, R2, R3), a1 A1) func(A2) (R1, R2, R3)
nolint: lll
func Partial3Arg0Ret ¶ added in v1.13.0
func Partial3Arg1Ret ¶ added in v1.13.0
func Partial3Arg2Ret ¶ added in v1.13.0
func Partial3Arg2Ret[A1 any, A2 any, A3 any, R1 any, R2 any](fn func(A1, A2, A3) (R1, R2), a1 A1) func(A2, A3) (R1, R2)
nolint: lll
func Partial3Arg3Ret ¶ added in v1.13.0
func Partial3Arg3Ret[A1 any, A2 any, A3 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3) (R1, R2, R3), a1 A1) func(A2, A3) (R1, R2, R3)
nolint: lll
func Partial4Arg0Ret ¶ added in v1.13.0
func Partial4Arg1Ret ¶ added in v1.13.0
func Partial4Arg1Ret[A1 any, A2 any, A3 any, A4 any, R1 any](fn func(A1, A2, A3, A4) R1, a1 A1) func(A2, A3, A4) R1
nolint: lll
func Partial4Arg2Ret ¶ added in v1.13.0
func Partial4Arg2Ret[A1 any, A2 any, A3 any, A4 any, R1 any, R2 any](fn func(A1, A2, A3, A4) (R1, R2), a1 A1) func(A2, A3, A4) (R1, R2)
nolint: lll
func Partial4Arg3Ret ¶ added in v1.13.0
func Partial4Arg3Ret[A1 any, A2 any, A3 any, A4 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3, A4) (R1, R2, R3), a1 A1) func(A2, A3, A4) (R1, R2, R3)
nolint: lll
func Partial5Arg0Ret ¶ added in v1.13.0
func Partial5Arg0Ret[A1 any, A2 any, A3 any, A4 any, A5 any](fn func(A1, A2, A3, A4, A5), a1 A1) func(A2, A3, A4, A5)
nolint: lll
func Partial5Arg1Ret ¶ added in v1.13.0
func Partial5Arg1Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any](fn func(A1, A2, A3, A4, A5) R1, a1 A1) func(A2, A3, A4, A5) R1
nolint: lll
func Partial5Arg2Ret ¶ added in v1.13.0
func Partial5Arg2Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any, R2 any](fn func(A1, A2, A3, A4, A5) (R1, R2), a1 A1) func(A2, A3, A4, A5) (R1, R2)
nolint: lll
func Partial5Arg3Ret ¶ added in v1.13.0
func Partial5Arg3Ret[A1 any, A2 any, A3 any, A4 any, A5 any, R1 any, R2 any, R3 any](fn func(A1, A2, A3, A4, A5) (R1, R2, R3), a1 A1) func(A2, A3, A4, A5) (R1, R2, R3)
nolint: lll
func PartitionN ¶ added in v1.9.0
PartitionN splits slice items into N lists. partitionFunc should return index of the partition to put the corresponding item into.
func Product ¶
func Product[T NumberExt | ComplexExt](s ...T) T
Product calculates product value of slice elements
func ProductAs ¶
func ProductAs[U, T NumberExt](s ...T) U
ProductAs calculates product value with conversion to another type. Type size of the result should be wider than the input's. E.g. product := ProductAs[int64](int32Slice...)
func PtrValueOrEmpty ¶ added in v1.16.0
func PtrValueOrEmpty[T any](t *T) (val T)
PtrValueOrEmpty returns the value of the pointer var, if it's nil returns empty value
func RandChoice ¶ added in v1.8.0
RandChoice picks up an item randomly from a slice
func RandStringEx ¶
RandStringEx generates a random string
func RandToken ¶ added in v1.15.0
RandToken generates a random token which can be used for crypto purpose
func RandTokenAsHex ¶ added in v1.15.0
RandTokenAsHex generates a random token as hex string
func Reduce ¶
func Reduce[T any, S ~[]T](s S, reduceFunc func(accumulator, currentValue T) T) T
Reduce reduces a slice to a value
func ReduceEx ¶
func ReduceEx[T any, U any, S ~[]T]( s S, reduceFunc func(accumulator U, currentValue T, currentIndex int) U, initVal U, ) U
ReduceEx reduces a slice to a value with custom initial value
func ReduceReverse ¶ added in v1.11.0
func ReduceReverse[T any, S ~[]T](s S, reduceFunc func(accumulator, currentValue T) T) T
ReduceReverse reduces a slice to a value
func ReduceReverseEx ¶ added in v1.11.0
func ReduceReverseEx[T any, U any, S ~[]T]( s S, reduceFunc func(accumulator U, currentValue T, currentIndex int) U, initVal U, ) U
ReduceReverseEx reduces a slice to a value with custom initial value
func RemoveAll ¶
func RemoveAll[T comparable, S ~[]T](ps *S, v T) int
RemoveAll removes all occurrences of value
func RemoveLastOf ¶
func RemoveLastOf[T comparable, S ~[]T](ps *S, v T) bool
RemoveLastOf removes element value
func Replace ¶
func Replace[T comparable, S ~[]T](s S, value, replacement T) bool
Replace replaces a value in slice with another value
func ReplaceAll ¶
func ReplaceAll[T comparable, S ~[]T](s S, value, replacement T) int
ReplaceAll replaces a value in slice with another value
func ReplaceN ¶ added in v1.10.0
func ReplaceN[T comparable, S ~[]T](s S, value, replacement T, n int) int
ReplaceN replaces a value in slice for the first n-occurrences
func Reverse ¶
func Reverse[T any, S ~[]T](s S) S
Reverse reverses slice content, this modifies the slice
func ReverseCopy ¶
func ReverseCopy[T any, S ~[]T](s S) S
ReverseCopy returns a new slice which has content in reversed order
func SliceByRange ¶ added in v1.6.0
func SliceByRange[T NumberExt](start, end, step T) []T
SliceByRange generates a slice by range. start is inclusive, end is exclusive.
func SortStable ¶
SortStable sorts slice values
func SortStableDesc ¶
SortStableDesc sorts slice values in descending order
func SortStableEx ¶
SortStableEx sorts slice values
func Splice ¶ added in v1.13.0
Splice removes a portion of the given slice and inserts elements of another slice into that position.
func SpliceEx ¶ added in v1.13.0
SpliceEx removes a portion of the given slice and inserts elements of another slice into that position. This function returns a new slice at the 1st place, the 2nd is the deleted elements.
func StringJoin ¶
StringJoin join elements from a slice of any type. This function calls fmt.Sprintf("%v", elem) to format every element.
func StringJoinBy ¶ added in v1.10.0
StringJoinBy join elements from a slice of any type with custom format function
func StringJoinEx ¶
StringJoinEx join elements from a slice of any type with custom format string
func StringLexJoin ¶ added in v1.11.0
StringLexJoin lexical joins a list of items of any type.
func StringLexJoinEx ¶ added in v1.11.0
StringLexJoinEx lexical joins a list of items of any type. The input format will be used with fmt.Sprintf() to render slice items as string.
For example:
StringLexJoinEx(["grape", "apple", "orange"], ", ", " and ", "%v") -> grape, apple and orange StringLexJoinEx(["grape", "apple", "orange"], ", ", " or ", "%v") -> grape, apple or orange
func StringSplit ¶ added in v1.15.0
StringSplit splits a string with handling quotes. `quote` param can be a single char (`"`, `'`...) if opening and closing tokens are the same, or a space-delimited string (`{ }`, `[ ]`, `{{ }}`...) if the tokens are different.
func StringSplitN ¶ added in v1.15.0
StringSplitN splits a string with handling quotes. `quote` param can be a single char (`"`, `'`...) if opening and closing tokens are the same, or a space-delimited string (`{ }`, `[ ]`, `{{ }}`...) if the tokens are different.
func StringToLower1stLetter ¶ added in v1.15.0
StringToLower1stLetter lowercases the first letter of the input string
func StringToUpper1stLetter ¶ added in v1.15.0
StringToUpper1stLetter uppercases the first letter of the input string
func StringUnwrap ¶ added in v1.12.0
StringUnwrap unwraps a string wrapped with the given token
func StringUnwrapLR ¶ added in v1.12.0
StringUnwrapLR unwraps a string wrapped with the given tokens
func StringWrap ¶ added in v1.12.0
StringWrap wraps a string with the given token
func StringWrapLR ¶ added in v1.12.0
StringWrapLR wraps a string with the given tokens for the left and right side
func SubSlice ¶ added in v1.6.0
SubSlice gets sub slice from a slice. Passing negative numbers to get items from the end of the slice. For example, using start=-1, end=-2 to get the last item of the slice end param is exclusive.
func SumAs ¶
func SumAs[U, T NumberExt](s ...T) U
SumAs calculates sum value with conversion to another type. Type size of the result should be wider than the input's. E.g. sum := SumAs[int64](int32Slice...)
func ToIfaceSlice ¶ added in v1.10.0
ToIfaceSlice convert a slice to a slice of interface
func ToNumberSlice ¶
func ToNumberSlice[U, T NumberExt, S ~[]T](slice S) []U
ToNumberSlice converts int-approximate slice to int slice
func ToPtr ¶ added in v1.11.0
func ToPtr[T any](t T) *T
ToPtr returns pointer to the address of the input
func ToPtrSlice ¶ added in v1.11.0
func ToPtrSlice[T any, S ~[]T](s S) []*T
ToPtrSlice returns a slice of pointers point to the input slice's elements
func ToSafeInt8 ¶ added in v1.12.0
ToSafeInt8 safely cast the value to type int8 (not using reflection)
func ToSafeInt16 ¶ added in v1.12.0
ToSafeInt16 safely cast the value to type int16 (not using reflection)
func ToSafeInt32 ¶ added in v1.12.0
ToSafeInt32 safely cast the value to type int32 (not using reflection)
func ToSafeInt64 ¶ added in v1.12.0
ToSafeInt64 safely cast the value to type int64 (not using reflection)
func ToSafeUint8 ¶ added in v1.12.0
ToSafeUint8 safely cast the value to type uint8 (not using reflection)
func ToSafeUint16 ¶ added in v1.12.0
ToSafeUint16 safely cast the value to type uint16 (not using reflection)
func ToSafeUint32 ¶ added in v1.12.0
ToSafeUint32 safely cast the value to type uint32 (not using reflection)
func ToSafeUint64 ¶ added in v1.12.0
ToSafeUint64 safely cast the value to type uint64 (not using reflection)
func ToSetBy ¶ added in v1.10.0
func ToSetBy[T any, K comparable, S ~[]T](s S, keyFunc func(t T) K) S
ToSetBy calculates unique values of a slice with custom key function
func ToSetByReverse ¶ added in v1.10.0
func ToSetByReverse[T any, K comparable, S ~[]T](s S, keyFunc func(t T) K) S
ToSetByReverse calculates unique values of a slice with custom key function. Unlike ToSetBy, this function iterates over the slice from the end.
func ToSlice ¶
func ToSlice[T any](s ...T) []T
ToSlice returns a slice for individual input arguments
func ToSliceSkippingNil ¶ added in v1.15.0
func ToSliceSkippingNil[T any](values ...*T) []*T
ToSliceSkippingNil makes a slice from the given values with skipping `nil` ones
func ToSliceSkippingZero ¶ added in v1.15.0
func ToSliceSkippingZero[T comparable](values ...T) []T
ToSliceSkippingZero makes a slice from the given values with skipping `zero` ones
func ToStringSlice ¶
func ToStringSlice[U, T ~string, S ~[]T](slice S) []U
ToStringSlice converts str-approximate slice to string slice
func Union ¶
func Union[T comparable, S ~[]T](a, b S) S
Union returns all unique values from multiple slices
func UnionBy ¶ added in v1.10.0
func UnionBy[T any, K comparable, S ~[]T](a, b S, keyFunc func(t T) K) S
UnionBy returns all unique values from multiple slices with key function
Types ¶
type Complex ¶ added in v1.10.0
type Complex interface {
complex64 | complex128
}
type ComplexExt ¶ added in v1.10.0
type ComplexExt interface {
~complex64 | ~complex128
}
type ComplexPtr ¶ added in v1.10.0
type ComplexPtr interface {
*complex64 | *complex128
}
type ExecRetryConfig ¶ added in v1.17.0
type ExecRetryConfig struct {
// contains filtered or unexported fields
}
type ExecRetryOption ¶ added in v1.17.0
type ExecRetryOption func(*ExecRetryConfig)
func ExecRetryCheck ¶ added in v1.17.1
func ExecRetryCheck(checkFunc func(error) bool) ExecRetryOption
func ExecRetryDelayExpoBackoff ¶ added in v1.17.0
func ExecRetryDelayExpoBackoff(jitter time.Duration) ExecRetryOption
func ExecRetryDelayIncr ¶ added in v1.17.0
func ExecRetryDelayIncr(incremental time.Duration) ExecRetryOption
func ExecRetryDelayMax ¶ added in v1.17.0
func ExecRetryDelayMax(maxDelay time.Duration) ExecRetryOption
func ExecRetryIfErrorIs ¶ added in v1.17.1
func ExecRetryIfErrorIs(errs ...error) ExecRetryOption
func ExecRetryIfErrorIsNot ¶ added in v1.17.1
func ExecRetryIfErrorIsNot(errs ...error) ExecRetryOption
type RandChoiceMaker ¶ added in v1.8.0
type RandChoiceMaker[T any] struct { // contains filtered or unexported fields }
RandChoiceMaker a struct for picking up items randomly from a list of items
func NewRandChoiceMaker ¶ added in v1.8.0
func NewRandChoiceMaker[T any, S ~[]T](s S, randFuncs ...func(n int) int) RandChoiceMaker[T]
func (*RandChoiceMaker[T]) HasNext ¶ added in v1.8.0
func (m *RandChoiceMaker[T]) HasNext() bool
HasNext checks to see the maker has items to return
func (*RandChoiceMaker[T]) Next ¶ added in v1.8.0
func (m *RandChoiceMaker[T]) Next() (T, bool)
Next gets the next item randomly from the source. If there is no item in the source, returns false as the 2nd value.
type Tuple2 ¶
type Tuple2[T1, T2 any] struct { Elem1 T1 Elem2 T2 }
func MapEntries ¶
func MapEntries[K comparable, V any, M ~map[K]V](m M) []*Tuple2[K, V]
MapEntries returns a slice of map entries as Tuple2 type
type Tuple3 ¶
type Tuple3[T1, T2, T3 any] struct { Elem1 T1 Elem2 T2 Elem3 T3 }
type Tuple4 ¶ added in v1.11.0
type Tuple4[T1, T2, T3, T4 any] struct { Elem1 T1 Elem2 T2 Elem3 T3 Elem4 T4 }
type Tuple5 ¶ added in v1.11.0
type Tuple5[T1, T2, T3, T4, T5 any] struct { Elem1 T1 Elem2 T2 Elem3 T3 Elem4 T4 Elem5 T5 }