Import path:
gitlab.soludian.com/soludian/fountain/libs/base/arr_util
arr_util
import "gitlab.soludian.com/soludian/fountain/libs/base/arr_util"Index
- Variables
- func AnyToSlice(sl any) (ls []any, err error)
- func AnyToString(arr any) string
- func AnyToStrings(arr any) []string
- func AssertInterfaces[T any](is []any) ([]T, error)
- func AssertInterfacesP[T any](is []any) []T
- func CloneSlice[T any](data []T) []T
- func Column[T any, V any](list []T, mapFn func(obj T) (val V, find bool)) []V
- func CombineToMap[K com_def.SortedType, V any](keys []K, values []V) map[K]V
- func CombineToSMap(keys, values []string) map[string]string
- func Contains(arr, val any) bool
- func ContainsAll[T com_def.ScalarType](list, values []T) bool
- func ConvType[T any, R any](arr []T, newElemTyp R) ([]R, error)
- func Diff[T any](first, second []T, fn Comparer[T]) []T
- func Differences[T any](first, second []T, fn Comparer[T]) []T
- func ElemTypeEqualsComparer[T any](a, b T) int
- func ElementExecuteFunc[T any](lObj []T, fn func(T) T) []T
- func ExceptWhile[T any](data []T, fn Predicate[T]) []T
- func Excepts[T any](first, second []T, fn Comparer[T]) []T
- func Filter[T any](ls []T, filter ...com_def.MatchFunc[T]) []T
- func Find[T any](source []T, fn Predicate[T]) (v T, err error)
- func FindIdentityMissingInList[Obj any, IdTyp com_def.Compared](ids []IdTyp, lObj []Obj, getIdentity func(Obj) IdTyp) []IdTyp
- func FindOrDefault[T any](source []T, fn Predicate[T], defaultValue T) T
- func FormatIndent(arr any, indent string) string
- func GetRandomOne[T any](arr []T) T
- func HasValue(arr, val any) bool
- func In[T com_def.ScalarType](value T, list []T) bool
- func InStrings[T ~string](elem T, ss []T) bool
- func IndexOf[T comparable](val T, list []T) int
- func Int64sHas(ints []int64, val int64) bool
- func InterfaceSlice[T any](slice []T) []any
- func Intersects[T any](first, second []T, fn Comparer[T]) []T
- func IntsHas[T com_def.Integer](ints []T, val T) bool
- func IntsToString[T com_def.Integer](ints []T) string
- func IsParent[T com_def.ScalarType](values, list []T) bool
- func IsSubList[T com_def.ScalarType](values, list []T) bool
- func JoinSlice(sep string, arr ...any) string
- func JoinStrings(sep string, ss ...string) string
- func JoinTyped[T any](sep string, arr ...T) string
- func Map[T any, V any](list []T, mapFn MapFn[T, V]) []V
- func MustToInt64s(arr any) []int64
- func MustToStrings(arr any) []string
- func NotContains(arr, val any) bool
- func NotIn[T com_def.ScalarType](value T, list []T) bool
- func QuietStrings(arr []any) []string
- func RandomOne[T any](arr []T) T
- func ReflectEqualsComparer[T any](a, b T) int
- func Remove[T comparable](ls []T, val T) []T
- func Reverse[T any](ls []T)
- func Shuffle[T any](arr []T) []T
- func SliceHas[T com_def.ScalarType](slice []T, val T) bool
- func SliceToInt64s(arr []any) []int64
- func SliceToString(arr ...any) string
- func SliceToStrings(arr []any) []string
- func StringEqualsComparer(a, b string) int
- func StringsAsInts(ss []string) []int
- func StringsFilter(ss []string, filter ...com_def.StringMatchFunc) []string
- func StringsHas[T ~string](ss []T, val T) bool
- func StringsJoin(sep string, ss ...string) string
- func StringsMap(ss []string, mapFn func(s string) string) []string
- func StringsRemove(ss []string, s string) []string
- func StringsToInts(ss []string) (ints []int, err error)
- func StringsToSlice(ss []string) []any
- func StringsTryInts(ss []string) (ints []int, err error)
- func TakeWhile[T any](data []T, fn Predicate[T]) []T
- func ToInt64s(arr any) (ret []int64, err error)
- func ToString[T any](arr []T) string
- func ToStrings(arr any) (ret []string, err error)
- func Transform[A any, B any](as []A, transFunc func(A) B) []B
- func TransformErr[A any, B any](as []A, transFunc func(A) (B, error)) ([]B, error)
- func TrimStrings(ss []string, cutSet ...string) []string
- func TwoWaySearch[T any](data []T, item T, fn Comparer[T]) (int, error)
- func Union[T any](first, second []T, fn Comparer[T]) []T
- func Unique[T comparable](list []T) []T
- func ValueEqualsComparer[T comparable](a, b T) int
- type ArrFormatter
- type Comparer
- type Ints
- type MapFn
- type Predicate
- type SortedList
- func (ls SortedList[T]) Contains(el T) bool
- func (ls SortedList[T]) Filter(filter ...com_def.MatchFunc[T]) SortedList[T]
- func (ls SortedList[T]) First(defVal ...T) T
- func (ls SortedList[T]) Has(el T) bool
- func (ls SortedList[T]) IsEmpty() bool
- func (ls SortedList[T]) Last(defVal ...T) T
- func (ls SortedList[T]) Len() int
- func (ls SortedList[T]) Less(i, j int) bool
- func (ls SortedList[T]) Remove(el T) SortedList[T]
- func (ls SortedList[T]) Sort()
- func (ls SortedList[T]) String() string
- func (ls SortedList[T]) Swap(i, j int)
- type Strings
Variables
ErrElementNotFound is the error returned when the element is not found.
var ErrElementNotFound = errors.New("element not found")var ErrInvalidType = errors.New("the input param type is invalid")func AnyToSlice
func AnyToSlice(sl any) (ls []any, err error)AnyToSlice convert any(allow: array,slice) to []any
func AnyToString
func AnyToString(arr any) stringAnyToString simple and quickly convert any array, slice to string
func AnyToStrings
func AnyToStrings(arr any) []stringAnyToStrings convert array or slice to []string
func AssertInterfaces
func AssertInterfaces[T any](is []any) ([]T, error)AssertInterfaces asserts all members of the passed slice of interfaces to the requested type and returns a slice of that type. A nil slice along with an error is returned if one of the entries cannot be asserted to the destination type.
Example
interfaceSlice := []any{"Hello", "World!"}
stringSlice, err := AssertInterfaces[string](interfaceSlice)
if err != nil {
log.Fatal(err)
}
s := strings.Join(stringSlice, ", ")
fmt.Println(s)
interfaceSlice = []any{1, 1.1, "foobar"}
intSlice, err := AssertInterfaces[int](interfaceSlice)
if err != nil {
fmt.Println(err)
}
fmt.Println(intSlice)
// Output: Hello, World!
// cannot assert float64 of value 1.1 to int at index 1
// []Output
Hello, World!
cannot assert float64 of value 1.1 to int at index 1
[]func AssertInterfacesP
func AssertInterfacesP[T any](is []any) []TAssertInterfacesP is like AssertInterfaces, only that it does not check for successful assertion and lets the runtime panic if assertion fails. Useful for inlining in cases where you are 100% sure of the concrete type of the passed slice.
Example
interfaceSlice := []any{"Hello", "World!"}
s := strings.Join(AssertInterfacesP[string](interfaceSlice), ", ")
fmt.Println(s)
// Output: Hello, World!Output
Hello, World!func CloneSlice
func CloneSlice[T any](data []T) []TCloneSlice Clone a slice.
data: the slice to clone.
returns: the cloned slice.func Column
func Column[T any, V any](list []T, mapFn func(obj T) (val V, find bool)) []VColumn alias of Map func
func CombineToMap
func CombineToMap[K com_def.SortedType, V any](keys []K, values []V) map[K]VCombineToMap combine []K and []V slice to map[K]V.
If keys length is greater than values, the extra keys will be ignored.
func CombineToSMap
func CombineToSMap(keys, values []string) map[string]stringCombineToSMap combine two string-slice to map[string]string
func Contains
func Contains(arr, val any) boolContains kiểm tra slice/array(strings, intXs, uintXs) có chứa giá trị cho trước (int(X),string).
TIP: Khác với In(), Contains() sẽ cố gắng chuyển đổi kiểu giá trị, và Contains() hỗ trợ kiểu array. Hàm In mang lại hiệu suất tốt.
func ContainsAll
func ContainsAll[T com_def.ScalarType](list, values []T) boolContainsAll check given values is sub-list of sample list.
func ConvType
func ConvType[T any, R any](arr []T, newElemTyp R) ([]R, error)ConvType convert type of slice elements to new type slice, by the given newElemTyp type.
Supports conversion between []string, []intX, []uintX, []floatX.
Usage:
ints, _ := ConvType([]string{"12", "23"}, 1) // []int{12, 23}func Diff
func Diff[T any](first, second []T, fn Comparer[T]) []TDiff Produces the set difference of two slice according to a comparer function. alias of Differences
func Differences
func Differences[T any](first, second []T, fn Comparer[T]) []TDifferences Produces the set difference of two slice according to a comparer function.
- first: the first slice. MUST BE A SLICE.
- second: the second slice. MUST BE A SLICE.
- fn: the comparer function.
- returns: the difference of the two slices.
Example:
Output: []string{"c"}
Differences([]string{"a", "b", "c"}, []string{"a", "b"}, StringEqualsComparerfunc ElemTypeEqualsComparer
func ElemTypeEqualsComparer[T any](a, b T) intElemTypeEqualsComparer Comparer for struct/value. It will compare the struct by their element type.
returns: 0 if same type, -1 if not.
func ElementExecuteFunc
func ElementExecuteFunc[T any](lObj []T, fn func(T) T) []TElementExecuteFunc applies a provided function to each element in a given slice.
- lObj: the input slice containing elements of type Obj.
- fn: the function to be applied to each element in lObj.
- returns: a new slice containing the results of applying fn to each element in lObj.
Usage:
lObjs := []Obj{obj1, obj2, obj3, ...}
result := ElementExecuteFunc(lObjs, func(o Obj) Obj {
// Your custom logic to be applied to each element.
// ...
return modifiedObj
})
// 'result' now contains the modified elements based on the applied function.Note: The provided function 'fn' should take an element of type 'Obj' as input and return a value of the same type 'Obj'.
func ExceptWhile
func ExceptWhile[T any](data []T, fn Predicate[T]) []TExceptWhile Produce the set of a slice except with a predicate function, Produce original slice when predicate function not match.
- data: the slice. MUST BE A SLICE.
- fn: the predicate function.
- returns: the set of the slice.
Example:
Output: []string{"a", "b"}
sl := ExceptWhile([]string{"a", "b", "c"}, func(s string) bool {
return s == "c"
})func Excepts
func Excepts[T any](first, second []T, fn Comparer[T]) []TExcepts Produces the set difference of two slice according to a comparer function.
- first: the first slice. MUST BE A SLICE.
- second: the second slice. MUST BE A SLICE.
- fn: the comparer function.
- returns: the difference of the two slices.
Example:
Output: []string{"c"}
Excepts([]string{"a", "b", "c"}, []string{"a", "b"}, StringEqualsComparer)func Filter
func Filter[T any](ls []T, filter ...com_def.MatchFunc[T]) []TFilter given slice, default will filter zero value.
Usage:
output: [a, b]
ss := Filter([]string{"a", "", "b", ""})func Find
func Find[T any](source []T, fn Predicate[T]) (v T, err error)Find Produces the value of a slice according to a predicate function.
- source: the slice. MUST BE A SLICE.
- fn: the predicate function.
- returns: the struct/value of the slice.
Example:
Output: "c"
val := Find([]string{"a", "b", "c"}, func(s string) bool {
return s == "c"
})func FindIdentityMissingInList
func FindIdentityMissingInList[Obj any, IdTyp com_def.Compared](ids []IdTyp, lObj []Obj, getIdentity func(Obj) IdTyp) []IdTypFinds all missing Identities in list lObj when get by ids Find all Obj by using list ids, need find all id missing in result
- first: the first slice. MUST BE A SLICE.
- second: the second slice. MUST BE A SLICE.
- fn: the getIdentity function.
- returns: the missing ids in list lObj.
Usage:
ids := []int{1, 2, 3, 4}
res := getObjByIds(ids)
missingIds := FindIdentityMissingInList(ids, res, func(md any) int {return md.ID})func FindOrDefault
func FindOrDefault[T any](source []T, fn Predicate[T], defaultValue T) TFindOrDefault Produce the value f a slice to a predicate function, Produce default value when predicate function not found.
- source: the slice. MUST BE A SLICE.
- fn: the predicate function.
- defaultValue: the default value.
- returns: the value of the slice.
Example:
Output: "d"
val := FindOrDefault([]string{"a", "b", "c"}, func(s string) bool {
return s == "d"
}, "d")func FormatIndent
func FormatIndent(arr any, indent string) stringFormatIndent array data to string.
func GetRandomOne
func GetRandomOne[T any](arr []T) TGetRandomOne get random element from an array/slice
func HasValue
func HasValue(arr, val any) boolHasValue check array(strings, intXs, uintXs) should be contained the given value(int(X),string).
func In
func In[T com_def.ScalarType](value T, list []T) boolIn check the given value whether in the list
func InStrings
func InStrings[T ~string](elem T, ss []T) boolInStrings check elem in the ss. alias of StringsHas()
func IndexOf
func IndexOf[T comparable](val T, list []T) intIndexOf value in given slice.
func Int64sHas
func Int64sHas(ints []int64, val int64) boolInt64sHas check the []int64 contains the given value
func InterfaceSlice
func InterfaceSlice[T any](slice []T) []anyInterfaceSlice transforms a slice of any type to a slice of any. This can be useful when you have a slice of concrete types that has to be passed to a function that takes a (variadic) slice of any.
Example
stringSlice := []string{"Hello", ", ", "World", "!"}
// fmt.Print(stringSlice...): cannot use stringSlice (variable of type []string) as type []any in argument to fmt.Print
fmt.Print(InterfaceSlice(stringSlice)...)
// Output: Hello, World!Output
Hello, World!func Intersects
func Intersects[T any](first, second []T, fn Comparer[T]) []TIntersects Produces to intersect of two slice according to a comparer function.
- first: the first slice. MUST BE A SLICE.
- second: the second slice. MUST BE A SLICE.
- fn: the comparer function.
- returns: to intersect of the two slices.
Example:
Output: []string{"a", "b"}
Intersects([]string{"a", "b", "c"}, []string{"a", "b"}, ValueEqualsComparer)func IntsHas
func IntsHas[T com_def.Integer](ints []T, val T) boolIntsHas check the []com_def.Integer contains the given value
func IntsToString
func IntsToString[T com_def.Integer](ints []T) stringIntsToString convert []T to string
func IsParent
func IsParent[T com_def.ScalarType](values, list []T) boolIsParent check given values is parent-list of samples.
func IsSubList
func IsSubList[T com_def.ScalarType](values, list []T) boolIsSubList check given values is sub-list of sample list.
func JoinSlice
func JoinSlice(sep string, arr ...any) stringJoinSlice join []any slice to string.
func JoinStrings
func JoinStrings(sep string, ss ...string) stringJoinStrings alias of strings.Join
func JoinTyped
func JoinTyped[T any](sep string, arr ...T) stringJoinTyped join typed []T slice to string.
Usage:
JoinTyped(",", 1,2,3) // "1,2,3"
JoinTyped(",", "a","b","c") // "a,b,c"
JoinTyped[any](",", "a",1,"c") // "a,1,c"func Map
func Map[T any, V any](list []T, mapFn MapFn[T, V]) []VMap a list to new list
eg: mapping [object0{},object1{},...] to flatten list [object0.someKey, object1.someKey, ...]
func MustToInt64s
func MustToInt64s(arr any) []int64MustToInt64s convert any(allow: array,slice) to []int64
func MustToStrings
func MustToStrings(arr any) []stringMustToStrings convert array or slice to []string
func NotContains
func NotContains(arr, val any) boolNotContains check array(strings, ints, uints) should be not contains the given value.
func NotIn
func NotIn[T com_def.ScalarType](value T, list []T) boolNotIn check the given value whether not in the list
func QuietStrings
func QuietStrings(arr []any) []stringQuietStrings safe convert []any to []string
func RandomOne
func RandomOne[T any](arr []T) TRandomOne get random element from an array/slice
func ReflectEqualsComparer
func ReflectEqualsComparer[T any](a, b T) intReflectEqualsComparer Comparer for struct ptr. It will compare by reflect.Value
returns: 0 if equal, -1 if a != b
func Remove
func Remove[T comparable](ls []T, val T) []TRemove give element from slice []T.
eg: []string{"site", "user", "info", "0"} -> []string{"site", "user", "info"}
func Reverse
func Reverse[T any](ls []T)Reverse any T slice.
eg: []string{"site", "user", "info", "0"} -> []string{"0", "info", "user", "site"}
func Shuffle
func Shuffle[T any](arr []T) []Tfunc SliceHas
func SliceHas[T com_def.ScalarType](slice []T, val T) boolSliceHas check the slice contains the given value
func SliceToInt64s
func SliceToInt64s(arr []any) []int64SliceToInt64s convert []any to []int64
func SliceToString
func SliceToString(arr ...any) stringSliceToString convert []any to string
func SliceToStrings
func SliceToStrings(arr []any) []stringSliceToStrings safe convert []any to []string
func StringEqualsComparer
func StringEqualsComparer(a, b string) intStringEqualsComparer Comparer for string. It will compare the string by their value.
returns: 0 if equal, -1 if a != b
func StringsAsInts
func StringsAsInts(ss []string) []intStringsAsInts convert and ignore error
func StringsFilter
func StringsFilter(ss []string, filter ...com_def.StringMatchFunc) []stringStringsFilter given strings, default will filter emtpy string.
Usage:
output: [a, b]
ss := StringsFilter([]string{"a", "", "b", ""})func StringsHas
func StringsHas[T ~string](ss []T, val T) boolStringsHas check the []string contains the given element
func StringsJoin
func StringsJoin(sep string, ss ...string) stringStringsJoin alias of strings.Join
func StringsMap
func StringsMap(ss []string, mapFn func(s string) string) []stringStringsMap handle each string item, map to new strings
func StringsRemove
func StringsRemove(ss []string, s string) []stringStringsRemove value form a string slice
func StringsToInts
func StringsToInts(ss []string) (ints []int, err error)StringsToInts string slice to int slice
func StringsToSlice
func StringsToSlice(ss []string) []anyStringsToSlice convert []string to []any
func StringsTryInts
func StringsTryInts(ss []string) (ints []int, err error)StringsTryInts string slice to int slice
func TakeWhile
func TakeWhile[T any](data []T, fn Predicate[T]) []TTakeWhile Produce the set of a slice according to a predicate function, Produce empty slice when predicate function not matched.
- data: the slice. MUST BE A SLICE.
- fn: the predicate function.
- returns: the set of the slice.
Example:
Output: []string{"a", "b"}
sl := TakeWhile([]string{"a", "b", "c"}, func(s string) bool {
return s != "c"
})func ToInt64s
func ToInt64s(arr any) (ret []int64, err error)ToInt64s convert any(allow: array,slice) to []int64
func ToString
func ToString[T any](arr []T) stringToString simple and quickly convert []T to string
func ToStrings
func ToStrings(arr any) (ret []string, err error)ToStrings convert any(allow: array,slice) to []string
func Transform
func Transform[A any, B any](as []A, transFunc func(A) B) []BTransform a slice of type 'A' to a slice of type 'B', by calling transFunc for each entry.
Useful when working with slices of different, but similar, struct types and you don't want to write the 'for' loops over and over again.
Example (Itoa)
in := []int{1, 2, 3, 4, 5}
out := Transform(in, strconv.Itoa)
fmt.Printf("out is of type %T and contains %v", out, out)
// Output: out is of type []string and contains [1 2 3 4 5]Output
out is of type []string and contains [1 2 3 4 5]Example (Struct)
type A struct {
ID int32
S []string
}
type B struct {
ID int64
S string
}
// define a tranformer function
transFunc := func(a A) B {
return B{
ID: int64(a.ID),
S: strings.Join(a.S, ", "),
}
}
in := []A{
{
ID: 1,
S: []string{"Hello", "World!"},
},
{
ID: 2,
S: []string{"foo", "bar"},
},
{
ID: 3,
S: []string{"spanac"},
},
}
// create the transformed slice
out := Transform(in, transFunc)
fmt.Printf("out is of type %T and contains %v", out, out)
// Output: out is of type []arr_util.B and contains [{1 Hello, World!} {2 foo, bar} {3 spanac}]Output
out is of type []arr_util.B and contains [{1 Hello, World!} {2 foo, bar} {3 spanac}]func TransformErr
func TransformErr[A any, B any](as []A, transFunc func(A) (B, error)) ([]B, error)TransformErr is similar to Transform, but it uses a transFunc that can return an error.
TransformErr will fail on the first error returned and returns a wrapped error with index information, along with a partial slice from previous successful operations.
Example (Atoi)
in := []string{"1", "2", "3", "4", "5"}
out, err := TransformErr(in, strconv.Atoi)
if err != nil {
panic(err)
}
fmt.Printf("out is of type %T and contains %v\n", out, out)
// this will cause an error
in = []string{"1", "2", "foo", "4", "5"}
out, err = TransformErr(in, strconv.Atoi)
if err != nil {
fmt.Println(err)
}
fmt.Printf("out is of type %T and contains %v\n", out, out)
// Output: out is of type []int and contains [1 2 3 4 5]
// transform index 2: strconv.Atoi: parsing "foo": invalid syntax
// out is of type []int and contains [1 2]Output
out is of type []int and contains [1 2 3 4 5]
transform index 2: strconv.Atoi: parsing "foo": invalid syntax
out is of type []int and contains [1 2]func TrimStrings
func TrimStrings(ss []string, cutSet ...string) []stringTrimStrings trim string slice item.
Usage:
output: [a, b, c]
ss := TrimStrings([]string{",a", "b.", ",.c,"}, ",.")func TwoWaySearch
func TwoWaySearch[T any](data []T, item T, fn Comparer[T]) (int, error)TwoWaySearch find specialized element in a slice forward and backward in the same time, should be more quickly.
- data: the slice to search in. MUST BE A SLICE.
- item: the element to search.
- fn: the comparer function.
- return: the index of the element, or -1 if not found.
func Union
func Union[T any](first, second []T, fn Comparer[T]) []TUnion Produces the set union of two slice according to a comparer function
- first: the first slice. MUST BE A SLICE.
- second: the second slice. MUST BE A SLICE.
- fn: the comparer function.
- returns: the union of the two slices.
Example:
Output: []string{"a", "b", "c"}
sl := Union([]string{"a", "b", "c"}, []string{"a", "b"}, ValueEqualsComparer)func Unique
func Unique[T comparable](list []T) []TUnique value in the given slice data.
func ValueEqualsComparer
func ValueEqualsComparer[T comparable](a, b T) intValueEqualsComparer Comparer for com_def.Compared type. It will compare by their value.
returns: 0 if equal, -1 if a != b
type ArrFormatter
ArrFormatter struct
type ArrFormatter struct {
com_def.BaseFormatter
// Prefix string for each element
Prefix string
// Indent string for format each element
Indent string
// ClosePrefix on before end char: ]
ClosePrefix string
}func NewFormatter
func NewFormatter(arr any) *ArrFormatterNewFormatter instance
func (*ArrFormatter) Format
func (f *ArrFormatter) Format() stringFormat to string
func (*ArrFormatter) FormatTo
func (f *ArrFormatter) FormatTo(w io.Writer)FormatTo to custom buffer
func (*ArrFormatter) String
func (f *ArrFormatter) String() stringFormat to string
func (*ArrFormatter) WithFn
func (f *ArrFormatter) WithFn(fn func(f *ArrFormatter)) *ArrFormatterWithFn for config self
func (*ArrFormatter) WithIndent
func (f *ArrFormatter) WithIndent(indent string) *ArrFormatterWithIndent string
type Comparer
Comparer Function to compare two elements.
type Comparer[T any] func(a, b T) inttype Ints
Ints type
type Ints[T com_def.Integer] []Tfunc (Ints[T]) First
func (is Ints[T]) First(defVal ...T) TFirst element value.
func (Ints[T]) Has
func (is Ints[T]) Has(i T) boolHas given element
func (Ints[T]) Last
func (is Ints[T]) Last(defVal ...T) TLast element value.
func (Ints[T]) Len
func (is Ints[T]) Len() intLen get length
func (Ints[T]) Less
func (is Ints[T]) Less(i, j int) boolLess compare two elements
func (Ints[T]) Sort
func (is Ints[T]) Sort()Sort the int slice
func (Ints[T]) String
func (is Ints[T]) String() stringString to string
func (Ints[T]) Swap
func (is Ints[T]) Swap(i, j int)Swap elements by indexes
type MapFn
MapFn map handle function type.
type MapFn[T any, V any] func(input T) (target V, find bool)type Predicate
Predicate Function to predicate a struct/value satisfies a condition.
type Predicate[T any] func(v T) booltype SortedList
SortedList definition for compared type
type SortedList[T com_def.Compared] []Tfunc (SortedList[T]) Contains
func (ls SortedList[T]) Contains(el T) boolContains given element
func (SortedList[T]) Filter
func (ls SortedList[T]) Filter(filter ...com_def.MatchFunc[T]) SortedList[T]Filter the slice, default will filter zero value.
func (SortedList[T]) First
func (ls SortedList[T]) First(defVal ...T) TFirst element value.
func (SortedList[T]) Has
func (ls SortedList[T]) Has(el T) boolHas given element
func (SortedList[T]) IsEmpty
func (ls SortedList[T]) IsEmpty() boolIsEmpty check
func (SortedList[T]) Last
func (ls SortedList[T]) Last(defVal ...T) TLast element value.
func (SortedList[T]) Len
func (ls SortedList[T]) Len() intLen get length
func (SortedList[T]) Less
func (ls SortedList[T]) Less(i, j int) boolLess compare two elements
func (SortedList[T]) Remove
func (ls SortedList[T]) Remove(el T) SortedList[T]Remove given element
func (SortedList[T]) Sort
func (ls SortedList[T]) Sort()Sort the slice
func (SortedList[T]) String
func (ls SortedList[T]) String() stringString to string
func (SortedList[T]) Swap
func (ls SortedList[T]) Swap(i, j int)Swap elements by indexes
type Strings
Strings type
type Strings []stringfunc (Strings) Contains
func (ss Strings) Contains(sub string) boolContains given element
func (Strings) First
func (ss Strings) First(defVal ...string) stringFirst element value.
func (Strings) Has
func (ss Strings) Has(sub string) boolHas given element
func (Strings) Join
func (ss Strings) Join(sep string) stringJoin to string
func (Strings) Last
func (ss Strings) Last(defVal ...string) stringLast element value.
func (Strings) Sort
func (ss Strings) Sort()Sort the string slice
func (Strings) String
func (ss Strings) String() stringString to string
Generated by gomarkdoc