Documentation ¶
Index ¶
- func Between[T constraints.Ordered](value, lowerBound, upperBound T) bool
- func Clone[M ~map[K]V, K comparable, V any](m M) M
- func Combine[T, R, S any](first func(T) R, second func(R) S) func(T) S
- func Contains[T comparable, S ~[]T](slice S, elem T) bool
- func ContainsAll[T comparable, S ~[]T](slice S, elems []T) bool
- func ContainsAllKeys[M ~map[K]V, K comparable, V any](m M, keys []K) bool
- func ContainsAny[T comparable, S ~[]T](slice S, elems []T) bool
- func ContainsAnyKey[M ~map[K]V, K comparable, V any](m M, keys []K) bool
- func ContainsKey[M ~map[K]V, K comparable, V any](m M, key K) bool
- func CopyFunc[T any](val T) func() T
- func Equal[T comparable](a, b T) bool
- func Fill[T any, S ~[]T](slice S, initial T) []T
- func FillBy[T any, S ~[]T](slice S, f func(index int) T) []T
- func ForEach[T any](slice []T, f func(T) bool) bool
- func ForEachKV[M ~map[K]V, K comparable, V any](m M, f func(K, V) bool) bool
- func ForEachPtr[T any](slice []T, f func(*T) bool) bool
- func ForRange[T constraints.Integer | constraints.Float](start, end, step T, f func(T) bool) bool
- func FromPtr[T any](x *T) T
- func FromPtrOr[T any](x *T, fallback T) T
- func IndexFunc[T any, S ~[]T](slice S) func(int) T
- func IsZero[T comparable](value T) bool
- func Keys[M ~map[K]V, K comparable, V any](m M) []K
- func LargerThan[T constraints.Ordered](a, b T) bool
- func LessThan[T constraints.Ordered](a, b T) bool
- func Map[T any, R any, S ~[]T](slice S, iteratee func(item T) R) []R
- func MapPtr[T any, R any, S ~[]T](slice S, iteratee func(item *T) R) []R
- func Max[T constraints.Ordered](origin T, slice ...T) T
- func Max2[T constraints.Ordered](a, b T) T
- func Merge[M ~map[K]V, K comparable, V any](maps ...M) M
- func Min[T constraints.Ordered](origin T, slice ...T) T
- func Min2[T constraints.Ordered](a, b T) T
- func Must[T any](value T, err error) T
- func MustTrue[T any](value T, ok bool) T
- func Pack[T any](elems ...T) []T
- func Reduce[T any, R any](slice []T, initial R, accumulator func(agg R, item T) R) R
- func ReflectIF[T any](value any, cond bool) (T, bool)
- func ReflectOR[T any](value any, fallback T) T
- func Repeat[T any](len int, initial T) []T
- func RepeatBy[T any](len int, f func(index int) T) []T
- func Reverse[T any, S ~[]T](slice S)
- func SliceToMap[K comparable, V any, S ~[]K](slice S, f func(K) V) map[K]V
- func Sort[T constraints.Ordered, S ~[]T](slice S)
- func SortBy[T any, S ~[]T](slice S, less func(a, b T) bool)
- func SortedKeys[M ~map[K]V, K constraints.Ordered, V any](m M) []K
- func Sum[T constraints.Ordered](origin T, slice ...T) T
- func Sum2[T constraints.Ordered](a, b T) T
- func Swap[T any, R any](first T, second R) (R, T)
- func Ternary[T any](cond bool, t T, f T) T
- func ToPtr[T any](x T) *T
- func ToSnakeCase(str string) string
- func Values[M ~map[K]V, K comparable, V any](m M) []V
- func WithArg[T, R any](f func() R) func(T) R
- func WithResult[T, R any](f func(T), r R) func(T) R
- func Zero[T any]() T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Between ¶
func Between[T constraints.Ordered](value, lowerBound, upperBound T) bool
Between returns if value is in [lowerBound, upperBound].
func Combine ¶
func Combine[T, R, S any](first func(T) R, second func(R) S) func(T) S
Combine two functions as one.
func Contains ¶
func Contains[T comparable, S ~[]T](slice S, elem T) bool
Contains reports whether elem is present in slice.
func ContainsAll ¶
func ContainsAll[T comparable, S ~[]T](slice S, elems []T) bool
ContainsAll reports whether all elems are present in slice.
func ContainsAllKeys ¶
func ContainsAllKeys[M ~map[K]V, K comparable, V any](m M, keys []K) bool
ContainsAllKeys returns whether all keys are present in map.
func ContainsAny ¶
func ContainsAny[T comparable, S ~[]T](slice S, elems []T) bool
ContainsAny reports whether anyone is present in slice.
func ContainsAnyKey ¶
func ContainsAnyKey[M ~map[K]V, K comparable, V any](m M, keys []K) bool
ContainsAnyKey returns whether any key is present in map.
func ContainsKey ¶
func ContainsKey[M ~map[K]V, K comparable, V any](m M, key K) bool
ContainsKey returns whether key is present in map.
func ForEachKV ¶
func ForEachKV[M ~map[K]V, K comparable, V any](m M, f func(K, V) bool) bool
ForEachKV apply f to each KV pair of map until f returns false.
func ForEachPtr ¶
ForEachPtr apply f to each element of slice until f returns false.
func ForRange ¶
func ForRange[T constraints.Integer | constraints.Float](start, end, step T, f func(T) bool) bool
ForRange apply f to each number in a sequence construct with step in range [start, end).
func FromPtrOr ¶
func FromPtrOr[T any](x *T, fallback T) T
FromPtrOr returns the pointer value or the fallback value.
func IndexFunc ¶
IndexFunc convert slice to a function which input is index and output is slice[index].
func LargerThan ¶
func LargerThan[T constraints.Ordered](a, b T) bool
LargerThan returns if a is larger than b
func LessThan ¶
func LessThan[T constraints.Ordered](a, b T) bool
LessThan returns if a is less than b
func MapPtr ¶
MapPtr manipulates a slice and transforms each element's pointer of it to a slice of another type.
func Max ¶
func Max[T constraints.Ordered](origin T, slice ...T) T
Max returns the maximum value between origin and each element of slice
func Max2 ¶
func Max2[T constraints.Ordered](a, b T) T
Max2 returns the maximum value between a and b
func Merge ¶
func Merge[M ~map[K]V, K comparable, V any](maps ...M) M
Merge merges multiple maps from left to right.
func Min ¶
func Min[T constraints.Ordered](origin T, slice ...T) T
Min returns the minimum value between origin and each element of slice
func Min2 ¶
func Min2[T constraints.Ordered](a, b T) T
Min2 returns the minimum value between a and b
func Reduce ¶
Reduce reduces slice to an accumulated result of running each element in slice by accumulator.
func SliceToMap ¶
func SliceToMap[K comparable, V any, S ~[]K](slice S, f func(K) V) map[K]V
SliceToMap convert slice to map.
func Sort ¶
func Sort[T constraints.Ordered, S ~[]T](slice S)
Sort sorts a slice of any ordered type in ascending order.
func SortedKeys ¶
func SortedKeys[M ~map[K]V, K constraints.Ordered, V any](m M) []K
SortedKeys returns all keys of map in order.
func Sum ¶
func Sum[T constraints.Ordered](origin T, slice ...T) T
Sum returns the summation between origin and each element of slice
func ToSnakeCase ¶
ToSnakeCase transfer str to snake case. Such as MyStr => my_str
func Values ¶
func Values[M ~map[K]V, K comparable, V any](m M) []V
Values returns all values of map.
func WithResult ¶
func WithResult[T, R any](f func(T), r R) func(T) R
WithResult combines func f and result r.
Types ¶
This section is empty.