slutil

package
v0.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FilterEmptyStr = FilterEmptyStrFunc
)

Functions

func Concat added in v0.3.8

func Concat[T any](a []T, b ...[]T) []T

func CopyFilter

func CopyFilter[T any](l []T, f func(T) bool) []T

Filter slice value.

The original slice is not modified only copied.

func Distinct

func Distinct(l []string) []string

Filter duplicate values

func DistinctFunc

func DistinctFunc() func([]string) []string

Filter duplicate values

func FastDistinct

func FastDistinct(l []string) []string

Filter duplicate values, faster but values are sorted, and the slice values are filtered in place.

func Filter

func Filter[T any](l []T, f func(T) bool) []T

Filter slice values in place.

Be cautious that both slices are backed by the same array.

func FilterEmptyStrFunc added in v0.3.0

func FilterEmptyStrFunc() func([]string) []string

func FilterFunc

func FilterFunc[T any](f func(T) bool) func([]T) []T

Filter slice value.

The original slice is not modified only copied.

func MapFunc

func MapFunc[T any, V any](mapFunc func(t T) V) func([]T) []V

Map slice item to another.

func MapTo

func MapTo[T any, V any](ts []T, mapFunc func(t T) V) []V

Map slice item to another.

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 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 NewSyncSlice

func NewSyncSlice[T any](initCap int) *syncSlice[T]

func Prepend added in v0.3.4

func Prepend[T any](v []T, ts ...T) []T

func QuoteStrSlice

func QuoteStrSlice(sl []string) []string

func SliceCopy

func SliceCopy[T any](v []T) []T

func SliceFilterFirst

func SliceFilterFirst[T any](items []T, f func(T) bool) (T, bool)

Select one from the slice that matches the condition.

func SliceFirst

func SliceFirst[T any](v []T) (t T, ok bool)

func SliceGetOne

func SliceGetOne[T any](items []*T) *T

Select random one from the slice

func SliceRemove

func SliceRemove[T any](v []T, idx ...int) []T

func SplitSubSlices

func SplitSubSlices[T any](sl []T, limit int, f func(sub []T) error) error

func Transform

func Transform[T any, V any](sl []T, transform func([]T) []V, updates ...func([]V) []V) []V

Transform value to another type then perform optional value updates.

See FilterFunc, MapFunc, FilterEmptyStrFunc, DistinctFunc.

func Update

func Update[T any](sl []T, fs ...func([]T) []T) []T

Update slice values.

See FilterFunc, FilterEmptyStrFunc, DistinctFunc.

func UpdateSliceValue

func UpdateSliceValue[T any](s []T, upd func(t T) T)

func UpdateTransform added in v0.3.0

func UpdateTransform[T any, V any](sl []T, transform func([]T) []V, updates ...func([]T) []T) []V

Update slice values then transform value to another type.

See FilterFunc, MapFunc, FilterEmptyStrFunc, DistinctFunc.

func VarArgAny added in v0.3.1

func VarArgAny[T any](v []T, defVal func() T) (t T)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL