Documentation
¶
Overview ¶
Slice utility pkg.
Index ¶
- Variables
- func Concat[T any](a []T, b ...[]T) []T
- func Copy[T any](v []T) []T
- func CopyFilter[T any](l []T, f func(T) (incl bool)) []T
- func CopyFilterUpdate[T any](l []T, filterUpdate func(T) (t T, incl bool)) []T
- func Distinct(l []string) []string
- func DistinctFunc() func([]string) []string
- func FastDistinct(l []string) []string
- func Filter[T any](l []T, f func(T) (incl bool)) []T
- func FilterEmptyStrFunc() func([]string) []string
- func FilterFunc[T any](f func(T) bool) func([]T) []T
- func FilterIdx[T any](l []T, f func(int, T) (incl bool)) []T
- func First[T any](v []T) (t T, ok bool)
- func FirstMatch[T any](items []T, f func(T) bool) (T, bool)
- func Flatten[T any](t [][]T) []T
- func MapFunc[T any, V any](mapFunc func(t T) V) func([]T) []V
- func MapTo[T any, V any](ts []T, mapFunc func(t T) V) []V
- func MapToErr[T any, V any](ts []T, mapFunc func(t T) (V, error)) ([]V, error)
- func MapToIdx[T any, V any](ts []T, mapFunc func(i int, t T) V) []V
- func MatchAny[T any](l []T, filter func(v T) (incl bool)) (t T, ok bool)
- func MergeMap[K comparable, V any](vs []V, keyFunc func(v V) K) map[K]V
- func MergeMapAs[T any, K comparable, V any](ts []T, keyFunc func(t T) K, valueFunc func(t T) V) map[K]V
- func MergeMapKV[T interface{ ... }, K comparable, V any](ts []T) map[K]V
- func MergeMapKVAny[T interface{ ... }, K comparable, V any](ts []T) map[K]any
- func MergeMapSlice[K comparable, V any](vs []V, keyFunc func(v V) K) map[K][]V
- func MergeVarargs[T any](fst T, args ...T) []T
- func PadTable(table [][]string, colCnt int)deprecated
- func Prepend[T any](v []T, ts ...T) []T
- func QuoteStrSlice(sl []string) []string
- func RandOne[T any](items []*T) *T
- func Remove[T any](v []T, idx ...int) []T
- func Sort[T ltsType](l []T)
- func SortLess[T any, V ltsType](l []T, f func(T) V, i, j int) bool
- func SortLessRev[T any, V ltsType](l []T, f func(T) V, i, j int) bool
- func SortMapped[T any, V ltsType](l []T, f func(T) V)
- func SortMappedRev[T any, V ltsType](l []T, f func(T) V)
- func SortRev[T ltsType](l []T)
- func SplitSubSlices[T any](sl []T, limit int, f func(sub []T) error) error
- func TableColAt(table [][]string, idx int) []stringdeprecated
- func Transform[T any, V any](sl []T, transform func([]T) []V, updates ...func([]V) []V) []V
- func Update[T any](sl []T, fs ...func([]T) []T) []T
- func UpdateSliceValue[T any](s []T, upd func(t T) T)
- func UpdateTransform[T any, V any](sl []T, transform func([]T) []V, updates ...func([]T) []T) []V
- func VarArgAny[T any](v []T, defVal func() T) (t T)
- type SyncSlice
Constants ¶
This section is empty.
Variables ¶
View Source
var (
FilterEmptyStr = FilterEmptyStrFunc
)
Functions ¶
func CopyFilterUpdate ¶ added in v0.4.11
func FastDistinct ¶
Filter duplicate values, faster but values are sorted, and the slice values are filtered in place.
func Filter ¶
Filter slice values in place.
Be cautious that both slices are backed by the same array.
func FilterEmptyStrFunc ¶ added in v0.3.0
func FilterIdx ¶ added in v0.3.10
Filter slice values in place.
Be cautious that both slices are backed by the same array.
func FirstMatch ¶ added in v0.4.0
Select one from the slice that matches the condition.
func MergeMap ¶
func MergeMap[K comparable, V any](vs []V, keyFunc func(v V) K) map[K]V
Merge slice of items to a map.
func MergeMapAs ¶
func MergeMapAs[T any, K comparable, V any](ts []T, keyFunc func(t T) K, valueFunc func(t T) V) map[K]V
Merge slice of items to a map.
func MergeMapKV ¶ added in v0.4.9
func MergeMapKV[T interface{ MapKV() (K, V) }, K comparable, V any](ts []T) map[K]V
func MergeMapKVAny ¶ added in v0.4.11
func MergeMapKVAny[T interface{ MapKV() (K, V) }, K comparable, V any](ts []T) map[K]any
func MergeMapSlice ¶
func MergeMapSlice[K comparable, V any](vs []V, keyFunc func(v V) K) map[K][]V
Merge slice of items to a map.
func MergeVarargs ¶ added in v0.3.4
func MergeVarargs[T any](fst T, args ...T) []T
func QuoteStrSlice ¶
func SortLessRev ¶ added in v0.4.10
func SortMapped ¶ added in v0.4.10
func SortMapped[T any, V ltsType](l []T, f func(T) V)
func SortMappedRev ¶ added in v0.4.10
func SortMappedRev[T any, V ltsType](l []T, f func(T) V)
func TableColAt
deprecated
added in
v0.4.0
func UpdateSliceValue ¶
func UpdateSliceValue[T any](s []T, upd func(t T) T)
func UpdateTransform ¶ added in v0.3.0
Update slice values then transform value to another type.
Types ¶
type SyncSlice ¶ added in v0.4.3
type SyncSlice[T any] struct { // contains filtered or unexported fields }
func NewSyncSlice ¶
func (*SyncSlice[T]) ForEachErr ¶ added in v0.4.3
Click to show internal directories.
Click to hide internal directories.