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, chunkSize int) [][]T
- func ChunkByPieces[T any](s []T, chunkCount int) [][]T
- func Compact[T comparable](s []T) []T
- func Concat[T any](slices ...[]T) []T
- func Contain[T comparable](a []T, t T) bool
- func ContainAll[T comparable](a []T, b ...T) bool
- func ContainAny[T comparable](a []T, b ...T) bool
- func ContainPred[T any](a []T, pred func(t T) bool) bool
- func ContainPredPtr[T any](a []T, pred func(t *T) bool) bool
- func ContainSlice[T comparable](a, b []T) bool
- func ContentEqual[T comparable](a, b []T) bool
- func ContentEqualPred[T any, K comparable](a, b []T, keyFunc func(t T) K) bool
- func ContentEqualPtr[T comparable](a, b []*T) bool
- func CountValue[T comparable](a []T, val T) int
- func CountValuePred[T any](a []T, pred func(t T) bool) int
- func Difference[T comparable](a []T, b []T) ([]T, []T)
- func DifferencePred[T any, K comparable](a, b []T, keyFunc func(t T) K) ([]T, []T)
- func Equal[T comparable](a, b []T) bool
- func EqualPred[T any](a, b []T, equalFunc func(a, b T) bool) bool
- func EqualPredPtr[T any](a, b []T, equalFunc func(a, b *T) bool) bool
- func ExecTasks(ctx context.Context, maxConcurrentTasks uint, ...) error
- func ExecTasksEx(ctx context.Context, maxConcurrentTasks uint, stopOnError bool, ...) map[int]error
- func FastRemove[T comparable](ps *[]T, v T) bool
- func FastRemoveAt[T any](ps *[]T, i int)
- func FastRemoveLastOf[T comparable](ps *[]T, v T) bool
- func Fill[T any](a []T, val T)
- func Filter[T any](s []T, filterFunc func(t T) bool) []T
- func FilterGT[T NumberEx | StringEx](s []T, v T) []T
- func FilterGTE[T NumberEx | StringEx](s []T, v T) []T
- func FilterILIKE[T StringEx](s []T, v string) []T
- func FilterIN[T comparable](s []T, v ...T) []T
- func FilterLIKE[T StringEx](s []T, v string) []T
- func FilterLT[T NumberEx | StringEx](s []T, v T) []T
- func FilterLTE[T NumberEx | StringEx](s []T, v T) []T
- func FilterNE[T comparable](s []T, v T) []T
- func FilterNIN[T comparable](s []T, v ...T) []T
- func FilterPtr[T any](s []T, filterFunc func(t *T) bool) []T
- func FindLastPred[T any](a []T, pred func(t T) bool) (t T, found bool)
- func FindLastPredPtr[T any](a []T, pred func(t *T) bool) (t T, found bool)
- func FindPred[T any](a []T, pred func(t T) bool) (t T, found bool)
- func FindPredPtr[T any](a []T, pred func(t *T) bool) (t T, found bool)
- func FirstTrue[T any](a0 T, args ...T) T
- func Flatten[T any](s ...[]T) []T
- func Flatten3[T any](s ...[][]T) []T
- func ForEach[T any](s []T, pred func(i int, t T))
- func ForEachPtr[T any](s []T, pred func(i int, t *T))
- func ForEachReverse[T any](s []T, pred func(i int, t T))
- func ForEachReversePtr[T any](s []T, pred func(i int, t *T))
- func FormatFloat[T FloatEx](v T) string
- func FormatFloatEx[T FloatEx](v T, format string) string
- func FormatFloatGroup[T FloatEx](v T) string
- func FormatFloatGroupEx[T FloatEx](v T, format string) string
- func FormatInt[T IntEx](v T) string
- func FormatIntEx[T IntEx](v T, format string) string
- func FormatIntGroup[T IntEx](v T) string
- func FormatUint[T UIntEx](v T) string
- func FormatUintEx[T UIntEx](v T, format string) string
- func FormatUintGroup[T UIntEx](v T) string
- func GetFirst[T any](s []T, defaultVal T) T
- func GetLast[T any](s []T, defaultVal T) T
- 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](a []T, t T) int
- func IndexOfPred[T any](a []T, pred func(t T) bool) int
- func IndexOfSlice[T comparable](a, sub []T) int
- func Intersection[T comparable](a, b []T) []T
- func IntersectionPred[T any, K comparable](a, b []T, keyFunc func(t T) K) []T
- func IsSorted[T NumberEx | StringEx](s []T) bool
- func IsSortedDesc[T NumberEx | StringEx](s []T) bool
- func IsUnique[T comparable](s []T) bool
- func IsUniquePred[T any, U comparable](s []T, keyFunc func(t T) U) bool
- func LastIndexOf[T comparable](a []T, t T) int
- func LastIndexOfPred[T any](a []T, pred func(t T) bool) int
- func LastIndexOfSlice[T comparable](a []T, sub []T) int
- 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, keys ...K) bool
- func MapContainValues[K comparable, V comparable](m map[K]V, values ...V) bool
- func MapCopy[K comparable, V any](m map[K]V, onlyKeys ...K) map[K]V
- func MapCopyExcludeKeys[K comparable, V any](m map[K]V, excludedKeys ...K) map[K]V
- func MapDifferenceKeys[K comparable, V any](m1, m2 map[K]V) ([]K, []K)
- func MapEqual[K comparable, V comparable](m1, m2 map[K]V) bool
- func MapEqualPred[K comparable, V any](m1, m2 map[K]V, equalFunc func(v1, v2 V) bool) bool
- func MapGet[K comparable, V any](m map[K]V, k K, defaultVal V) V
- func MapIntersectionKeys[K comparable, V any](m1 map[K]V, ms ...map[K]V) []K
- func MapKeys[K comparable, V any](m map[K]V) []K
- func MapPop[K comparable, V any](m map[K]V, k K, defaultVal V) V
- func MapSetDefault[K comparable, V any](m map[K]V, k K, defaultVal V) V
- func MapSlice[T any, U any](s []T, mapFunc func(b T) U) []U
- func MapSliceEx[T any, U any](s []T, mapFunc func(b T) (U, error)) ([]U, error)
- func MapSliceToMap[T any, K comparable, V any](s []T, mapFunc func(b T) (K, V)) map[K]V
- func MapSliceToMapEx[T any, K comparable, V any](s []T, mapFunc func(b T) (K, V, error)) (map[K]V, error)
- func MapUnionKeys[K comparable, V any](m1 map[K]V, ms ...map[K]V) []K
- func MapUpdate[K comparable, V any](m1, m2 map[K]V) map[K]V
- func MapUpdateExistingOnly[K comparable, V any](m1, m2 map[K]V) map[K]V
- func MapUpdateNewOnly[K comparable, V any](m1, m2 map[K]V) map[K]V
- func MapValues[K comparable, V any](m map[K]V) []V
- func Max[T NumberEx | ~string](v1 T, s ...T) T
- func MaxIn[T NumberEx | ~string](s []T) (T, error)
- func MaxInPred[T any](s []T, lessFunc func(a, b T) bool) (T, error)
- func MaxTime(t1 time.Time, s ...time.Time) time.Time
- func Min[T NumberEx | ~string](v1 T, s ...T) T
- func MinIn[T NumberEx | ~string](s []T) (T, error)
- func MinInPred[T any](s []T, lessFunc func(a, b T) bool) (T, error)
- func MinMax[T NumberEx | ~string](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 New[T any](t T) *T
- func NumberFmtGroup(num string, fractionSep, groupSep byte) string
- func NumberFmtUngroup(num string, groupSep byte) string
- func ParseFloat[T FloatEx](s string) (T, error)
- func ParseFloatDef[T FloatEx](s string, defaultVal T) T
- func ParseFloatUngroup[T FloatEx](s string) (T, error)
- func ParseInt[T IntEx](s string) (T, error)
- func ParseIntDef[T IntEx](s string, defaultVal T) T
- func ParseIntEx[T IntEx](s string, base int) (T, error)
- func ParseIntUngroup[T IntEx](s string) (T, error)
- func ParseUint[T UIntEx](s string) (T, error)
- func ParseUintDef[T UIntEx](s string, defaultVal T) T
- func ParseUintEx[T UIntEx](s string, base int) (T, error)
- func ParseUintUngroup[T UIntEx](s string) (T, error)
- func Product[T IntEx | UIntEx | FloatEx](s ...T) T
- func ProductAs[U, T IntEx | UIntEx | FloatEx](s ...T) U
- func RandString(n int) string
- func RandStringEx(n int, allowedChars []rune) string
- func Reduce[T any](s []T, reduceFunc func(accumulator, currentValue T) T) T
- func ReduceEx[T any, U any](s []T, reduceFunc func(accumulator U, currentValue T, currentIndex int) U, ...) U
- func Remove[T comparable](ps *[]T, v T) bool
- func RemoveAll[T comparable](ps *[]T, v T) int
- func RemoveAt[T any](ps *[]T, i int)
- func RemoveLastOf[T comparable](ps *[]T, v T) bool
- func Replace[T comparable](s []T, value, replacement T) bool
- func ReplaceAll[T comparable](s []T, value, replacement T) int
- func Reverse[T any](s []T) []T
- func ReverseCopy[T any](s []T) []T
- func SliceByRange[T NumberEx](start, end, step T) []T
- func Sort[T NumberEx | StringEx](s []T) []T
- func SortDesc[T NumberEx | StringEx](s []T) []T
- func SortEx[T any](s []T, less func(i, j int) bool) []T
- func SortStable[T NumberEx | StringEx](s []T) []T
- func SortStableDesc[T NumberEx | StringEx](s []T) []T
- func SortStableEx[T any](s []T, less func(i, j int) bool) []T
- func StringJoin[T any](s []T, sep string) string
- func StringJoinEx[T any](s []T, sep, format string) string
- func StringJoinPred[T any](s []T, sep string, fmtFunc func(v T) string) string
- func SubSlice[T any](s []T, start, end int) []T
- func Sum[T IntEx | UIntEx | FloatEx](s ...T) T
- func SumAs[U, T IntEx | UIntEx | FloatEx](s ...T) U
- func Tail[T any](t any, s ...any) (T, bool)
- func ToIntfSlice[T any](s []T) []any
- func ToNumberSlice[U, T NumberEx](slice []T) []U
- func ToSet[T comparable](s []T) []T
- func ToSetPred[T any, K comparable](s []T, keyFunc func(t T) K) []T
- func ToSlice[T any](s ...T) []T
- func ToStringSlice[U, T ~string](slice []T) []U
- func Union[T comparable](a, b []T) []T
- func UnionPred[T any, K comparable](a, b []T, keyFunc func(t T) K) []T
- type Float
- type FloatEx
- type Int
- type IntEx
- type Number
- type NumberEx
- type StringEx
- type Tuple2
- type Tuple3
- type UInt
- type UIntEx
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmpty = errors.New("container is empty") ErrIndexOutOfRange = errors.New("index out of range") ErrPanic = errors.New("panic occurred") )
var ( StrLowerAlpha = []rune("abcdefghijklmnopqrstuvwxyz") StrUpperAlpha = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ") StrDigits = []rune("0123456789") StrDefaultChars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") )
var ( StructToMap = rflutil.StructToMap StructToMapEx = rflutil.StructToMapEx ParseTag = rflutil.ParseTag ParseTagOf = rflutil.ParseTagOf ParseTagsOf = rflutil.ParseTagsOf )
var ( // Deprecated: use ErrEmpty instead ErrSliceEmpty = ErrEmpty )
var MultilineString = LinesTrimLeftSpace
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
func Any ¶
func Any[T comparable](s ...T) bool
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 ¶
func Compact ¶
func Compact[T comparable](s []T) []T
func Contain ¶
func Contain[T comparable](a []T, t T) bool
Contain tests if a slice contains an item
func ContainAll ¶
func ContainAll[T comparable](a []T, b ...T) bool
ContainAll tests if a slice contains all given values
func ContainAny ¶
func ContainAny[T comparable](a []T, b ...T) bool
ContainAny tests if a slice contains any given value
func ContainPred ¶
ContainPred tests if a slice contains an item by predicate
func ContainPredPtr ¶
ContainPredPtr tests if a slice contains an item by predicate
func ContainSlice ¶
func ContainSlice[T comparable](a, b []T) bool
ContainSlice tests if a slice contains a slice
func ContentEqual ¶
func ContentEqual[T comparable](a, b []T) bool
ContentEqual compares 2 slices without caring about order NOTE: if you want to compare content of slices of pointers, use ContentEqualPtr
func ContentEqualPred ¶
func ContentEqualPred[T any, K comparable](a, b []T, keyFunc func(t T) K) bool
ContentEqualPred compares 2 slices without preserving order
func ContentEqualPtr ¶
func ContentEqualPtr[T comparable](a, b []*T) bool
ContentEqualPtr compares 2 slices of pointers without caring about order
func CountValue ¶
func CountValue[T comparable](a []T, val T) int
CountValue counts number of occurrences of an item in the slice
func CountValuePred ¶
CountValuePred counts number of occurrences of an item in the slice
func Difference ¶
func Difference[T comparable](a []T, b []T) ([]T, []T)
Difference calculates the differences between two slices NOTE: this function does not return unique values
func DifferencePred ¶
func DifferencePred[T any, K comparable](a, b []T, keyFunc func(t T) K) ([]T, []T)
DifferencePred calculates the differences between two slices using special key function NOTE: this function does not return unique values
func EqualPredPtr ¶
EqualPredPtr compares 2 slices with preserving order
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 FastRemoveAt ¶
FastRemoveAt removes element at the specified index by swapping it with the last item in slice
func FastRemoveLastOf ¶
func FastRemoveLastOf[T comparable](ps *[]T, v T) bool
FastRemoveLastOf removes element value
func FilterILIKE ¶
func FilterIN ¶
func FilterIN[T comparable](s []T, v ...T) []T
func FilterLIKE ¶
func FilterNE ¶
func FilterNE[T comparable](s []T, v T) []T
func FilterNIN ¶
func FilterNIN[T comparable](s []T, v ...T) []T
func FilterPtr ¶
FilterPtr filters slice elements using pointer in callback. This function is faster than Filter() when used on slices of structs.
func FindLastPred ¶
FindLastPred finds value in slice from the end by predicate
func FindLastPredPtr ¶
FindLastPredPtr finds value in slice from the end by predicate
func FindPredPtr ¶
FindPredPtr finds value in slice by predicate
func FirstTrue ¶
func FirstTrue[T any](a0 T, args ...T) T
FirstTrue returns the first "true" value in the given arguments if found True value is not:
- zero value (0, "", nil, false)
- empty slice, array, map, channel
- non-nil pointer points to non-zero value
func Flatten ¶
func Flatten[T any](s ...[]T) []T
Flatten flattens 2-dimensional slices E.g. Flatten([1,2,3], [3,4,5]) -> [1,2,3,3,4,5]
func ForEachPtr ¶
func ForEachReverse ¶
func ForEachReversePtr ¶
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) Deprecated: this function may cause unexpected behavior upon misuses
For example: gofn.If(len(slice) > 0, slice[0], dafaultVal) will crash if slice is empty
func IndexOf ¶
func IndexOf[T comparable](a []T, t T) int
IndexOf gets index of item in slice Returns -1 if not found
func IndexOfPred ¶
IndexOfPred gets index of item in slice by predicate Returns -1 if not found
func IndexOfSlice ¶
func IndexOfSlice[T comparable](a, sub []T) int
IndexOfSlice gets index of sub-slice in slice Returns -1 if not found
func Intersection ¶
func Intersection[T comparable](a, b []T) []T
func IntersectionPred ¶
func IntersectionPred[T any, K comparable](a, b []T, keyFunc func(t T) K) []T
func IsSortedDesc ¶
IsSortedDesc checks if a slice is sorted in descending order
func IsUniquePred ¶
func IsUniquePred[T any, U comparable](s []T, keyFunc func(t T) U) bool
IsUniquePred checks a slice for uniqueness using key function
func LastIndexOf ¶
func LastIndexOf[T comparable](a []T, t T) int
LastIndexOf gets index of item from the end in slice Returns -1 if not found
func LastIndexOfPred ¶
LastIndexOfPred gets index of item from the end in slice Returns -1 if not found
func LastIndexOfSlice ¶
func LastIndexOfSlice[T comparable](a []T, sub []T) int
LastIndexOfSlice gets last index of sub-slice in slice Returns -1 if not found
func LinesTrimLeft ¶
LinesTrimLeft trim leading characters for every line in the given string
func LinesTrimLeftSpace ¶
LinesTrimLeftSpace trim leading spaces for every line in the given string
func LinesTrimRight ¶
LinesTrimRight trim trailing characters for every line in the given string
func LinesTrimRightSpace ¶
LinesTrimRightSpace trim trailing characters for every line in the given string
func LinesTrimSpace ¶
LinesTrimSpace trim leading and trailing spaces for every line in the given string
func MapContainKeys ¶
func MapContainKeys[K comparable, V any](m map[K]V, 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, 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, onlyKeys ...K) map[K]V
func MapCopyExcludeKeys ¶ added in v1.5.0
func MapCopyExcludeKeys[K comparable, V any](m map[K]V, excludedKeys ...K) map[K]V
func MapDifferenceKeys ¶
func MapDifferenceKeys[K comparable, V any](m1, m2 map[K]V) ([]K, []K)
func MapEqual ¶
func MapEqual[K comparable, V comparable](m1, m2 map[K]V) bool
MapEqual compares contents of 2 map
func MapEqualPred ¶
func MapEqualPred[K comparable, V any](m1, m2 map[K]V, equalFunc func(v1, v2 V) bool) bool
MapEqualPred compares contents of 2 map
func MapGet ¶
func MapGet[K comparable, V any](m map[K]V, 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](m1 map[K]V, ms ...map[K]V) []K
func MapPop ¶
func MapPop[K comparable, V any](m map[K]V, k K, defaultVal V) V
MapPop deletes and returns the value of the key if exists, returns the default one if not
func MapSetDefault ¶
func MapSetDefault[K comparable, V any](m map[K]V, k K, defaultVal V) V
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, mapFunc func(b 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, mapFunc func(b T) (K, V, error)) (map[K]V, error)
MapSliceToMapEx transforms a slice to a map with map function and error handling
func MapUnionKeys ¶
func MapUnionKeys[K comparable, V any](m1 map[K]V, ms ...map[K]V) []K
func MapUpdate ¶
func MapUpdate[K comparable, V any](m1, m2 map[K]V) map[K]V
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](m1, m2 map[K]V) map[K]V
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](m1, m2 map[K]V) map[K]V
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 New ¶
func New[T any](t T) *T
New returns pointer to the address of the input Helpful for unit testing when create a struct that has field requires pointer type
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 ProductAs ¶
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 RandStringEx ¶
RandStringEx generates a random string
func RemoveAll ¶
func RemoveAll[T comparable](ps *[]T, v T) int
RemoveAll removes all occurrences of value
func RemoveLastOf ¶
func RemoveLastOf[T comparable](ps *[]T, v T) bool
RemoveLastOf removes element value
func Replace ¶
func Replace[T comparable](s []T, value, replacement T) bool
Replace replaces a value in slice with another value
func ReplaceAll ¶
func ReplaceAll[T comparable](s []T, value, replacement T) int
ReplaceAll replaces a value in slice with another value
func ReverseCopy ¶
func ReverseCopy[T any](s []T) []T
func SliceByRange ¶ added in v1.6.0
func SliceByRange[T NumberEx](start, end, step T) []T
SliceByRange generates a slice by range start is inclusive, end is exclusive
func SortStableDesc ¶
SortStableDesc sorts slice values in descending order
func SortStableEx ¶
SortStableEx sorts slice values
func StringJoin ¶
StringJoin join elements from a slice of any type This function calls fmt.Sprintf("%v", elem) to format every element
func StringJoinEx ¶
StringJoinEx join elements from a slice of any type with custom format string
func StringJoinPred ¶
StringJoinPred join elements from a slice of any type with custom format function
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 ¶
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 ToIntfSlice ¶
ToIntfSlice convert a slice to a slice of interface
func ToNumberSlice ¶
func ToNumberSlice[U, T NumberEx](slice []T) []U
ToNumberSlice converts int-approximate slice to int slice
func ToSet ¶
func ToSet[T comparable](s []T) []T
func ToSetPred ¶
func ToSetPred[T any, K comparable](s []T, keyFunc func(t T) K) []T
func ToSlice ¶
func ToSlice[T any](s ...T) []T
ToSlice returns a slice for individual input arguments
func ToStringSlice ¶
func ToStringSlice[U, T ~string](slice []T) []U
ToStringSlice converts str-approximate slice to string slice
func Union ¶
func Union[T comparable](a, b []T) []T
func UnionPred ¶
func UnionPred[T any, K comparable](a, b []T, keyFunc func(t T) K) []T
Types ¶
type Tuple2 ¶
func MapEntries ¶
func MapEntries[K comparable, V any](m map[K]V) []*Tuple2[K, V]
MapEntries returns a slice of map entries as Tuple2 type