Documentation
¶
Index ¶
- func AnySlice[T any](values []T) []any
- func AssertSlice[T any](values []any) []T
- func Contains[T comparable](values []T, v T) bool
- func CopyMap[K comparable, V any](values map[K]V) map[K]V
- func CopySlice[T any](values []T) []T
- func Filter[T any](values []T, f func(T, int) bool) []T
- func Flat2[T any](values [][]T) []T
- func Flat3[T any](values [][][]T) []T
- func Go[S any, T any](funcs ...Go1Func[S, T]) func(context.Context, []S) ([]T, error)
- func Go0[T any](funcs ...Go0Func[T]) func(context.Context) ([]T, error)
- func Go1[S any, T any](funcs ...Go1Func[S, T]) func(context.Context, []S) ([]T, error)
- func Go2[S1 any, S2 any, T any](funcs ...Go2Func[S1, S2, T]) func(context.Context, []S1, []S2) ([]T, error)
- func Go3[S1 any, S2 any, S3 any, T any](funcs ...Go3Func[S1, S2, S3, T]) func(context.Context, []S1, []S2, []S3) ([]T, error)
- func GroupBy[T any, K comparable](values []T, f func(T, int) K) map[K][]T
- func IndexOf[T comparable](values []T, v T) int
- func IndexOfBy[T comparable](values []T, f func(T, int) bool) int
- func Keys[K comparable, V any](values map[K]V) []K
- func LastIndexOf[T comparable](values []T, v T) int
- func LastIndexOfBy[T comparable](values []T, f func(T, int) bool) int
- func Map[F any, T any](values []F, f func(F, int) T) []T
- func MapEntries[K comparable, V any, T any](values map[K]V, f func(K, V) T) []T
- func MapKeys[K comparable, V any, T any](values map[K]V, f func(K) T) []T
- func MapValues[K comparable, V any, T any](values map[K]V, f func(V) T) []T
- func Max[T Numberic](values []T) T
- func MaxBy[T any](values []T, less func(T, T) bool) T
- func MaxKey[K Numberic, V any](values map[K]V) K
- func MaxKeyBy[K comparable, V any](values map[K]V, less func(K, K) bool) K
- func MaxValue[K comparable, V Numberic](values map[K]V) V
- func MaxValueBy[K comparable, V any](values map[K]V, less func(V, V) bool) V
- func Min[T Numberic](values []T) T
- func MinBy[T any](values []T, less func(T, T) bool) T
- func MinKey[K Numberic, V any](values map[K]V) K
- func MinKeyBy[K comparable, V any](values map[K]V, less func(K, K) bool) K
- func MinValue[K comparable, V Numberic](values map[K]V) V
- func MinValueBy[K comparable, V any](values map[K]V, less func(V, V) bool) V
- func Must[T any](v T, err error) T
- func Must0(err error)
- func Must1[T any](v T, err error) T
- func Must2[T1 any, T2 any](v1 T1, v2 T2, err error) (T1, T2)
- func Must3[T1 any, T2 any, T3 any](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)
- func Must4[T1 any, T2 any, T3 any, T4 any](v1 T1, v2 T2, v3 T3, v4 T4, err error) (T1, T2, T3, T4)
- func Partition[T any](values []T, size int) [][]T
- func Ptr[T any](v T) *T
- func PutAll[K comparable, V any](target map[K]V, elements map[K]V) map[K]V
- func Reduce[F any, T any](values []F, f func(T, F, int) T) T
- func Repeat[T any](v T, n int) []T
- func Reverse[T any](values []T) []T
- func ReverseS(s string) string
- func Slice2Map[K comparable, V any](values []V, f func(V, int) K) map[K]V
- func Ternary[T any](cond bool, v1 T, v2 T) T
- func TernaryF[T any](cond bool, f1 func() T, f2 func() T) T
- func Uniq[T comparable](values []T) []T
- func UniqBy[V any, T comparable](values []V, f func(V) T) []V
- func ValueOf[T any](ptr *T) T
- func Values[K comparable, V any](values map[K]V) []V
- type Go0Func
- type Go1Func
- type Go2Func
- type Go3Func
- type JMap
- type Numberic
- type SyncMap
- func (m *SyncMap[K, V]) Delete(key K)
- func (m *SyncMap[K, V]) Load(key K) (V, bool)
- func (m *SyncMap[K, V]) LoadAndDelete(key K) (V, bool)
- func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (V, bool)
- func (m *SyncMap[K, V]) Range(f func(key K, value V) bool)
- func (m *SyncMap[K, V]) Snapshot() map[K]V
- func (m *SyncMap[K, V]) Store(key K, value V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertSlice ¶ added in v0.3.1
AssertSlice assert interface list to target type, panic if elements of values are not T.
func Contains ¶
func Contains[T comparable](values []T, v T) bool
Contains check v is contained by values.
func CopyMap ¶ added in v0.3.5
func CopyMap[K comparable, V any](values map[K]V) map[K]V
CopyMap returns a copy of the map.
func Flat2 ¶
func Flat2[T any](values [][]T) []T
Flat2 flatten 2-dimensional array to 1-dimensional array.
func Flat3 ¶
func Flat3[T any](values [][][]T) []T
Flat3 flatten 3-dimensional array to 1-dimensional array.
func GroupBy ¶
func GroupBy[T any, K comparable](values []T, f func(T, int) K) map[K][]T
GroupBy is a group by operator, like guava's group by.
func IndexOf ¶
func IndexOf[T comparable](values []T, v T) int
IndexOf find the index of v in values, return -1 if element not found.
func IndexOfBy ¶
func IndexOfBy[T comparable](values []T, f func(T, int) bool) int
IndexOfBy find the index of v in values, return -1 if element not found.
func Keys ¶
func Keys[K comparable, V any](values map[K]V) []K
Keys returns the keys of the map, order is not guaranteed.
func LastIndexOf ¶
func LastIndexOf[T comparable](values []T, v T) int
LastIndexOf find the last index of v in values, return -1 if element not found.
func LastIndexOfBy ¶
func LastIndexOfBy[T comparable](values []T, f func(T, int) bool) int
LastIndexOfBy find the last index of v in values, return -1 if element not found.
func MapEntries ¶
func MapEntries[K comparable, V any, T any](values map[K]V, f func(K, V) T) []T
MapEntries returns the f(entries) of the map, order is not guaranteed.
func MapKeys ¶
func MapKeys[K comparable, V any, T any](values map[K]V, f func(K) T) []T
MapKeys returns the f(key)s of the map, order is not guaranteed.
func MapValues ¶
func MapValues[K comparable, V any, T any](values map[K]V, f func(V) T) []T
MapValues returns the f(value)s of the map, order is not guaranteed.
func MaxBy ¶
MaxBy returns the maximum value in the given slice, using the provided less function to compare values.
func MaxKeyBy ¶
func MaxKeyBy[K comparable, V any](values map[K]V, less func(K, K) bool) K
MaxKeyBy returns the maximum key of the map based on less method.
func MaxValue ¶
func MaxValue[K comparable, V Numberic](values map[K]V) V
MaxValue returns the maximum value of the map.
func MaxValueBy ¶
func MaxValueBy[K comparable, V any](values map[K]V, less func(V, V) bool) V
MaxValueBy returns the maximum value of the map based on less method.
func MinBy ¶
MinBy returns the minimum value in the given slice, using the provided less function to compare values.
func MinKeyBy ¶
func MinKeyBy[K comparable, V any](values map[K]V, less func(K, K) bool) K
MinKeyBy returns the minimum key of the map based on less method.
func MinValue ¶
func MinValue[K comparable, V Numberic](values map[K]V) V
MinValue returns the minimum value of the map.
func MinValueBy ¶
func MinValueBy[K comparable, V any](values map[K]V, less func(V, V) bool) V
MinValueBy returns the minimum value of the map based on less method.
func Ptr ¶
func Ptr[T any](v T) *T
Ptr returns the pointer of the given value, Ptr will panic if v is nil.
func PutAll ¶
func PutAll[K comparable, V any](target map[K]V, elements map[K]V) map[K]V
PutAll add all elements to exist map, if the key is already exists, the value will be overridden.
func Slice2Map ¶
func Slice2Map[K comparable, V any](values []V, f func(V, int) K) map[K]V
Slice2Map transfer slice to a map base on given func.
func UniqBy ¶ added in v0.3.1
func UniqBy[V any, T comparable](values []V, f func(V) T) []V
UniqBy remove duplicated elements from values, based on given func.
func Values ¶
func Values[K comparable, V any](values map[K]V) []V
Values returns the values of the map, order is not guaranteed.
Types ¶
type JMap ¶ added in v0.3.8
func (JMap) MarshalJSON ¶ added in v0.3.8
func (*JMap) UnmarshalJSON ¶ added in v0.3.8
type Numberic ¶
type Numberic interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
}
Numberic is a numeric type, which can use ><= operators.
type SyncMap ¶ added in v0.3.2
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewSyncMap ¶ added in v0.3.2
func NewSyncMap[K comparable, V any]() SyncMap[K, V]