Documentation
¶
Overview ¶
Package arrutil provides some util functions for array, slice
Index ¶
- Variables
- func AnyToSlice(sl any) (ls []any, err error)
- func AnyToString(arr any) string
- func AnyToStrings(arr any) []string
- func BinarySearch[T comdef.Compared](ls []T, target T) (int, bool)
- func BinarySearchFunc[T any](ls []T, target T, cmp Comparer[T]) (int, bool)
- func Chunk[T any](list []T, size int) [][]T
- func ChunkBy[T, R any](list []T, size int, mapFn func(el T) R) [][]R
- func Clip[T any](ls []T) []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 comdef.SortedType, V any](keys []K, values []V) map[K]V
- func CombineToSMap(keys, values []string) map[string]string
- func Compact[T comparable](ls []T) []T
- func CompactFunc[T any](ls []T, eq func(a, b T) bool) []T
- func Concat[T any](ls ...[]T) []T
- func Contains(arr, val any) bool
- func ContainsAll[T comdef.ScalarType](list, values []T) bool
- func ContainsFunc[T any](ls []T, fn comdef.MatchFunc[T]) bool
- func ConvType[T any, R any](arr []T, newElemTyp R) ([]R, error)
- func Count[T comparable](ls []T, v T) int
- func CountFunc[T any](ls []T, fn comdef.MatchFunc[T]) int
- func DeleteFunc[T any](ls []T, del func(T) bool) []T
- func DeleteRange[T any](ls []T, i, j int) []T
- 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 Equal[T comparable](a, b []T) bool
- func EqualFunc[T any](a, b []T, eq func(a, b T) bool) bool
- 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 ...comdef.MatchFunc[T]) []T
- func Find[T any](source []T, fn Predicate[T]) (v T, err error)
- func FindOrDefault[T any](source []T, fn Predicate[T], defaultValue T) T
- func FirstNonEmptyString(values ...string) string
- func FirstOr[T any](list []T, defVal ...T) T
- func FormatIndent(arr any, indent string) string
- func GetRandomOne[T any](arr []T) T
- func Grow[T any](ls []T, n int) []T
- func HasValue(arr, val any) bool
- func In[T comdef.ScalarType](value T, list []T) bool
- func InStrings[T ~string](elem T, ss []T) bool
- func IndexFunc[T any](ls []T, fn comdef.MatchFunc[T]) int
- func IndexOf[T comdef.NumberOrString](val T, list []T) int
- func Insert[T any](ls []T, i int, vs ...T) []T
- func Int64sHas(ints []int64, val int64) bool
- func Intersects[T any](first, second []T, fn Comparer[T]) []T
- func IntsHas[T comdef.Integer](ints []T, val T) bool
- func IntsToString[T comdef.Integer](ints []T) string
- func IsParent[T comdef.ScalarType](values, list []T) bool
- func IsSorted[T comdef.Compared](ls []T) bool
- func IsSortedFunc[T any](ls []T, cmp Comparer[T]) bool
- func IsSubList[T comdef.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, V any](list []T, mapFilter func(input T) (target V, ok bool)) []V
- func Map1[T, R any](list []T, mapFn func(t T) R) []R
- func Max[T comdef.Compared](ls []T) T
- func MaxFunc[T any](ls []T, cmp Comparer[T]) T
- func Min[T comdef.Compared](ls []T) T
- func MinFunc[T any](ls []T, cmp Comparer[T]) T
- func MustToInt64s(arr any) []int64
- func MustToStrings(arr any) []string
- func NotContains(arr, val any) bool
- func NotIn[T comdef.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 comdef.Compared](ls []T, val T) []T
- func Repeat[T any](v T, n int) []T
- func Replace[T any](ls []T, i, j int, vs ...T) []T
- func Reverse[T any](ls []T)
- func SliceHas[T comdef.ScalarType](slice []T, val T) bool
- func SliceToInt64s(arr []any) []int64
- func SliceToString(arr ...any) string
- func SliceToStrings(arr []any) []string
- func Sort[T comdef.Compared](ls []T)
- func SortFunc[T any](ls []T, cmp Comparer[T])
- func SortStableFunc[T any](ls []T, cmp Comparer[T])
- func StringEqualsComparer(a, b string) int
- func StringsAsInts(ss []string) []int
- func StringsContains(ss []string, s string) bool
- func StringsFilter(ss []string, filter ...comdef.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 StringsToAnys(ss []string) []any
- func StringsToInts(ss []string) (ints []int, err error)
- func StringsToSlice(ss []string) []any
- func StringsTryInts(ss []string) (ints []int, err error)
- func StringsUnique(ss []string) []string
- func TakeWhile[T any](data []T, fn Predicate[T]) []T
- func ToInt64s(arr any) (ret []int64, err error)
- func ToMap[T any, K comdef.ScalarType, V any](list []T, mapFn func(T) (K, V)) map[K]V
- func ToString[T any](arr []T) string
- func ToStrings(arr any) (ret []string, err 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 comdef.NumberOrString](list []T) []T
- func ValueEqualsComparer[T comdef.Compared](a, b T) int
- type ArrFormatter
- type Comparer
- type Ints
- type Predicate
- type SortedList
- func (ls SortedList[T]) Contains(el T) bool
- func (ls SortedList[T]) Filter(filter ...comdef.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
Constants ¶
This section is empty.
Variables ¶
var ErrElementNotFound = errors.New("element not found")
ErrElementNotFound is the error returned when the element is not found.
var ErrInvalidType = errors.New("the input param type is invalid")
ErrInvalidType error
Functions ¶
func AnyToSlice ¶ added in v0.6.9
AnyToSlice convert any(allow: array,slice) to []any
func AnyToString ¶ added in v0.5.2
AnyToString simple and quickly convert any array, slice to string
func AnyToStrings ¶ added in v0.6.2
AnyToStrings convert array or slice to []string
func BinarySearch ¶ added in v0.9.0
BinarySearch searches for target in the sorted slice and returns the position where it is or where it would be inserted, and whether target is in the slice.
func BinarySearchFunc ¶ added in v0.9.0
BinarySearchFunc is like BinarySearch, but compares the elements with cmp.
The slice must be sorted in increasing order by cmp.
func Chunk ¶ added in v0.7.4
Chunk split slice to chunks by size.
eg: [1,2,3,4,5,6,7,8,9,10] -> [[1,2,3,4], [5,6,7,8], [9,10]]
func ChunkBy ¶ added in v0.7.4
ChunkBy split slice to chunks by size, and with custom chunk function.
Example:
list := []map[string]any{
{"id": 1, "name": "one", "age": 23},
{"id": 2, "name": "two", "age": 23},
{"id": 3, "name": "three", "age": 23},
}
chunks := arrutil.ChunkBy(list, 2, func(el map[string]any) map[string]any {
return map[string]any{
"id": el["id"],
"name": el["name"],
}
})
Output: [
[{"id": 1, "name": "one"}, {"id": 2, "name": "two"}],
[{"id": 3, "name": "three"}]
]
func Clip ¶ added in v0.9.0
func Clip[T any](ls []T) []T
Clip removes the unused capacity of the given slice.
The result shares the same backing array, use it to drop references to elements that are no longer reachable through the slice.
func CloneSlice ¶ added in v0.5.3
func CloneSlice[T any](data []T) []T
CloneSlice Clone a slice.
NOTE: unlike slices.Clone a nil slice gives back an empty non-nil slice.
func Column ¶ added in v0.6.0
Column collect sub elements from list. alias of Map func
Example:
list := []map[string]any{
{"id": 1, "name": "one", "age": 23},
{"id": 2, "name": "two", "age": 23},
{"id": 3, "name": "three", "age": 23},
}
names := arrutil.Column(list, func(el map[string]any) string {
return el["name"].(string)
})
func CombineToMap ¶ added in v0.6.9
func CombineToMap[K comdef.SortedType, V any](keys []K, values []V) map[K]V
CombineToMap combine []K and []V slice to map[K]V.
If keys length is greater than values, the extra keys will be ignored.
func CombineToSMap ¶ added in v0.6.5
CombineToSMap combine two string-slice to map[string]string
func Compact ¶ added in v0.9.0
func Compact[T comparable](ls []T) []T
Compact replaces consecutive runs of equal elements with a single copy, in place.
The slice is modified and the elements after the returned length are zeroed.
func CompactFunc ¶ added in v0.9.0
CompactFunc is like Compact, but uses eq to compare the elements.
func Concat ¶ added in v0.9.0
func Concat[T any](ls ...[]T) []T
Concat returns a new slice with all the given slices concatenated.
A nil result is returned when every given slice is empty.
func Contains ¶ added in v0.3.6
Contains check slice/array(strings, intXs, uintXs) should be contained the given value(int(X),string).
TIP: Difference the In(), Contains() will try to convert value type, and Contains() support array type.
func ContainsAll ¶ added in v0.6.2
func ContainsAll[T comdef.ScalarType](list, values []T) bool
ContainsAll check given values is sub-list of sample list.
func ContainsFunc ¶ added in v0.9.0
ContainsFunc reports whether any element of the slice satisfies the given function.
func ConvType ¶ added in v0.6.2
ConvType convert type of slice elements to new type slice, by the given newElemTyp type.
Supports conversion between []string, []intX, []uintX, []floatX.
Usage:
ints, _ := arrutil.ConvType([]string{"12", "23"}, 1) // []int{12, 23}
func Count ¶ added in v0.9.0
func Count[T comparable](ls []T, v T) int
Count the occurrences of the given value in the slice.
func DeleteFunc ¶ added in v0.9.0
DeleteFunc removes the elements for which del returns true, in place.
The elements after the returned length are zeroed.
func DeleteRange ¶ added in v0.9.0
DeleteRange removes the elements ls[i:j] from the slice, in place.
It panics if the indexes are out of the range [0, len(ls)] or i > j. The elements after the returned length are zeroed.
func Diff ¶ added in v0.6.12
Diff Produces the set difference of two slice according to a comparer function. alias of Differences
func Differences ¶ added in v0.6.5
Differences 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"}, arrutil.StringEqualsComparer
func ElemTypeEqualsComparer ¶ added in v0.5.3
ElemTypeEqualsComparer Comparer for struct/value. It will compare the struct by their element type.
returns: 0 if same type, -1 if not.
func Equal ¶ added in v0.9.0
func Equal[T comparable](a, b []T) bool
Equal reports whether the two slices have the same elements in the same order.
A nil slice and an empty slice are considered equal.
func EqualFunc ¶ added in v0.9.0
EqualFunc is like Equal, but compares the elements with the given function.
func ExceptWhile ¶ added in v0.5.3
ExceptWhile 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 ¶ added in v0.5.3
Excepts 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"}, arrutil.StringEqualsComparer)
func Filter ¶ added in v0.6.11
Filter given slice, default will filter zero value.
Usage:
// output: [a, b]
ss := arrutil.Filter([]string{"a", "", "b", ""})
func Find ¶ added in v0.5.3
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 FindOrDefault ¶ added in v0.5.3
FindOrDefault 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 FirstNonEmptyString ¶ added in v0.7.6
FirstNonEmptyString get
func FirstOr ¶ added in v0.7.0
func FirstOr[T any](list []T, defVal ...T) T
FirstOr get first value of slice, if slice is empty, return the default value.
func FormatIndent ¶ added in v0.5.3
FormatIndent array data to string.
func GetRandomOne ¶ added in v0.3.8
func GetRandomOne[T any](arr []T) T
GetRandomOne get random element from an array/slice
func Grow ¶ added in v0.9.0
Grow increases the slice capacity to guarantee space for n more elements.
func HasValue ¶ added in v0.3.13
HasValue check array(strings, intXs, uintXs) should be contained the given value(int(X),string).
func In ¶ added in v0.6.2
func In[T comdef.ScalarType](value T, list []T) bool
In check the given value whether in the list
func IndexFunc ¶ added in v0.9.0
IndexFunc returns the index of the first element that satisfies the given function, or -1 if there is none.
func IndexOf ¶ added in v0.6.6
func IndexOf[T comdef.NumberOrString](val T, list []T) int
IndexOf value in given slice. returns -1 if not found
func Insert ¶ added in v0.9.0
Insert inserts the values vs into the slice at index i and returns the result.
It panics if i is out of the range [0, len(ls)]. Unlike slices.Insert it always returns a new slice, the given slice is never modified.
func Intersects ¶ added in v0.5.3
Intersects 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"}, arrutil.ValueEqualsComparer)
func IntsToString ¶ added in v0.6.11
IntsToString convert []T to string
func IsParent ¶ added in v0.6.2
func IsParent[T comdef.ScalarType](values, list []T) bool
IsParent check given values is parent-list of samples.
func IsSorted ¶ added in v0.9.0
IsSorted reports whether the given slice is sorted in increasing order.
func IsSortedFunc ¶ added in v0.9.0
IsSortedFunc reports whether the given slice is sorted by the given comparison function.
func IsSubList ¶ added in v0.6.2
func IsSubList[T comdef.ScalarType](values, list []T) bool
IsSubList check given values is sub-list of sample list.
func JoinStrings ¶ added in v0.4.2
JoinStrings alias of strings.Join
func JoinTyped ¶ added in v0.6.12
JoinTyped 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 ¶ added in v0.6.0
Map a list to new list with map filter function.
eg: mapping [object0{},object1{},...] to flatten list [object0.someKey, object1.someKey, ...]
func Map1 ¶ added in v0.7.2
func Map1[T, R any](list []T, mapFn func(t T) R) []R
Map1 a list to new list with map function.
eg: mapping [object0{},object1{},...] to flatten list [object0.someKey, object1.someKey, ...]
func MaxFunc ¶ added in v0.9.0
MaxFunc returns the maximum value of the slice by the given comparison function. It panics on an empty slice.
func MinFunc ¶ added in v0.9.0
MinFunc returns the minimum value of the slice by the given comparison function. It panics on an empty slice.
func MustToInt64s ¶ added in v0.3.13
MustToInt64s convert any(allow: array,slice) to []int64
func MustToStrings ¶ added in v0.3.13
MustToStrings convert array or slice to []string
func NotContains ¶ added in v0.3.6
NotContains check array(strings, ints, uints) should be not contains the given value.
func NotIn ¶ added in v0.6.2
func NotIn[T comdef.ScalarType](value T, list []T) bool
NotIn check the given value whether not in the list
func QuietStrings ¶ added in v0.6.2
QuietStrings safe convert []any to []string
func RandomOne ¶ added in v0.5.7
func RandomOne[T any](arr []T) T
RandomOne get random element from an array/slice
func ReflectEqualsComparer ¶ added in v0.6.12
ReflectEqualsComparer Comparer for struct ptr. It will compare by reflect.Value
returns: 0 if equal, -1 if a != b
func Remove ¶ added in v0.6.11
Remove give element from slice []T.
eg: []string{"site", "user", "info", "0"} -> []string{"site", "user", "info"}
func Repeat ¶ added in v0.9.0
Repeat returns a new slice with the given value repeated n times.
It panics if n is negative.
func Replace ¶ added in v0.9.0
Replace replaces the elements ls[i:j] with the given values and returns the result.
It panics if the indexes are out of the range [0, len(ls)] or i > j. Unlike slices.Replace it always returns a new slice, the given slice is never modified.
func Reverse ¶
func Reverse[T any](ls []T)
Reverse any T slice in place.
eg: []string{"site", "user", "info", "0"} -> []string{"0", "info", "user", "site"}
func SliceHas ¶ added in v0.6.11
func SliceHas[T comdef.ScalarType](slice []T, val T) bool
SliceHas check the slice contains the given value. alias of slices.Contains
func SliceToInt64s ¶ added in v0.3.13
SliceToInt64s convert []any to []int64
func SliceToString ¶ added in v0.4.5
SliceToString convert []any to string
func SliceToStrings ¶ added in v0.3.13
SliceToStrings safe convert []any to []string
func Sort ¶ added in v0.9.0
Sort the given slice in place. It panics if the element type is not ordered.
func SortFunc ¶ added in v0.9.0
SortFunc sorts the slice in place by the given comparison function.
It panics if cmp is not a valid comparison function for the element type.
func SortStableFunc ¶ added in v0.9.0
SortStableFunc sorts the slice in place by the given comparison function, keeping the original order of equal elements.
func StringEqualsComparer ¶ added in v0.5.3
StringEqualsComparer Comparer for string. It will compare the string by their value.
returns: 0 if equal, -1 if a != b
func StringsAsInts ¶ added in v0.6.2
StringsAsInts convert and ignore error
func StringsContains ¶ added in v0.6.13
StringsContains check string slice contains string
func StringsFilter ¶ added in v0.5.7
func StringsFilter(ss []string, filter ...comdef.StringMatchFunc) []string
StringsFilter given strings, default will filter emtpy string.
Usage:
// output: [a, b]
ss := arrutil.StringsFilter([]string{"a", "", "b", ""})
func StringsHas ¶ added in v0.3.6
StringsHas check the []string contains the given element
func StringsJoin ¶ added in v0.4.2
StringsJoin alias of strings.Join
func StringsMap ¶ added in v0.5.11
StringsMap handle each string item, map to new strings
func StringsRemove ¶ added in v0.1.4
StringsRemove value form a string slice
func StringsToAnys ¶ added in v0.6.13
StringsToAnys convert []string to []any
func StringsToInts ¶ added in v0.2.2
StringsToInts string slice to int slice
func StringsToSlice ¶ added in v0.4.5
StringsToSlice convert []string to []any. alias of StringsToAnys()
func StringsTryInts ¶ added in v0.6.2
StringsTryInts string slice to int slice
func StringsUnique ¶ added in v0.6.13
StringsUnique unique string slice
func TakeWhile ¶ added in v0.5.3
TakeWhile 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 ToMap ¶ added in v0.7.2
func ToMap[T any, K comdef.ScalarType, V any](list []T, mapFn func(T) (K, V)) map[K]V
ToMap convert a list to new map.
Example:
type User struct {
Name string
Age int
}
users := []User{{"Tom", 18}, {"Jack", 20}}
mp := arrutil.ToMap(users, func(u User) (string, int) {
return u.Name, u.Age
})
// mp = map[string]int{"Tom":18, "Jack":20}
func TrimStrings ¶ added in v0.2.2
TrimStrings trim string slice item.
Usage:
// output: [a, b, c]
ss := arrutil.TrimStrings([]string{",a", "b.", ",.c,"}, ",.")
func TwowaySearch ¶ added in v0.5.3
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 ¶ added in v0.5.3
Union 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"}, arrutil.ValueEqualsComparer)
func Unique ¶ added in v0.5.13
func Unique[T comdef.NumberOrString](list []T) []T
Unique value in the given slice data.
func ValueEqualsComparer ¶ added in v0.6.12
ValueEqualsComparer Comparer for comdef.Compared type. It will compare by their value.
returns: 0 if equal, -1 if a != b
Types ¶
type ArrFormatter ¶ added in v0.5.3
type ArrFormatter struct {
comdef.BaseFormatter
// Prefix string for each element
Prefix string
// Indent string for format each element
Indent string
// ClosePrefix on before end char: ]
ClosePrefix string
}
ArrFormatter struct
func (*ArrFormatter) Format ¶ added in v0.5.3
func (f *ArrFormatter) Format() string
Format to string
func (*ArrFormatter) FormatTo ¶ added in v0.5.3
func (f *ArrFormatter) FormatTo(w io.Writer)
FormatTo to custom buffer
func (*ArrFormatter) String ¶ added in v0.5.3
func (f *ArrFormatter) String() string
Format to string
func (*ArrFormatter) WithFn ¶ added in v0.5.3
func (f *ArrFormatter) WithFn(fn func(f *ArrFormatter)) *ArrFormatter
WithFn for config self
func (*ArrFormatter) WithIndent ¶ added in v0.5.3
func (f *ArrFormatter) WithIndent(indent string) *ArrFormatter
WithIndent string
type Ints ¶ added in v0.3.9
Ints type
type Predicate ¶ added in v0.5.3
Predicate Function to predicate a struct/value satisfies a condition.
type SortedList ¶ added in v0.6.11
SortedList definition for compared type
func (SortedList[T]) Contains ¶ added in v0.6.11
func (ls SortedList[T]) Contains(el T) bool
Contains given element
func (SortedList[T]) Filter ¶ added in v0.6.11
func (ls SortedList[T]) Filter(filter ...comdef.MatchFunc[T]) SortedList[T]
Filter the slice, default will filter zero value.
func (SortedList[T]) First ¶ added in v0.6.11
func (ls SortedList[T]) First(defVal ...T) T
First element value.
func (SortedList[T]) Has ¶ added in v0.6.11
func (ls SortedList[T]) Has(el T) bool
Has given element
func (SortedList[T]) IsEmpty ¶ added in v0.6.11
func (ls SortedList[T]) IsEmpty() bool
IsEmpty check
func (SortedList[T]) Last ¶ added in v0.6.11
func (ls SortedList[T]) Last(defVal ...T) T
Last element value.
func (SortedList[T]) Less ¶ added in v0.6.11
func (ls SortedList[T]) Less(i, j int) bool
Less compare two elements
func (SortedList[T]) Remove ¶ added in v0.6.11
func (ls SortedList[T]) Remove(el T) SortedList[T]
Remove given element
func (SortedList[T]) String ¶ added in v0.6.11
func (ls SortedList[T]) String() string
String to string
func (SortedList[T]) Swap ¶ added in v0.6.11
func (ls SortedList[T]) Swap(i, j int)
Swap elements by indexes