Documentation ¶
Index ¶
- func BatchSlice[T any](s []T, batchSize int) [][]T
- func ConcatSlices[T any](ss ...[]T) []T
- func FilterMap[K comparable, V any](m map[K]V, f func(k K, v V) bool) map[K]V
- func FilterSlice[T any](s []T, f func(t T) bool) []T
- func GetSortedMapKeys[K cmp.Ordered, V any](m map[K]V, less func(K, K) bool) []K
- func MapPtr[K comparable, V any](m map[K]V) map[K]*V
- func MapPtrZeroToNil[K comparable, V comparable](m map[K]V) map[K]*V
- func MapValNilToDef[K comparable, V any](m map[K]*V, d V) map[K]V
- func MapValNilToZero[K comparable, V any](m map[K]*V) map[K]V
- func Max[T cmp.Ordered](v1, v2 T) T
- func MergeMaps[K comparable, V any](mm ...map[K]V) map[K]V
- func Min[T cmp.Ordered](v1, v2 T) T
- func PredicateIsZeroValue[T comparable](v T) bool
- func Ptr[T any](v T) *T
- func PtrIfTrue[T any](cond bool, v T) *T
- func PtrZeroToNil[T comparable](v T) *T
- func PtrZeroToNilIfTrue[T comparable](cond bool, v T) *T
- func SafeSliceIndexDef[T any](s []T, i int, d T) T
- func SafeSliceIndexPtr[T any](s []T, i int) *T
- func SafeSliceIndexZero[T any](s []T, i int) T
- func ShallowCopyMap[K comparable, V any](m map[K]V) map[K]V
- func ShallowCopySlice[T any](s []T) []T
- func SlicePtr[T any](s []T) []*T
- func SlicePtrZeroToNil[T comparable](s []T) []*T
- func SliceValNilToDef[T any](s []*T, d T) []T
- func SliceValNilToZero[T any](s []*T) []T
- func TransformMapValues[K comparable, V1 any, V2 any](m map[K]V1, f func(i V1) V2) map[K]V2
- func TransformSlice[I any, O any](s []I, f func(i I) O) []O
- func TransformSprintf[V any](v V) string
- func ValNilToDef[T any](v *T, d T) T
- func ValNilToZero[T any](v *T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchSlice ¶
BatchSlice splits a slice in batches.
func ConcatSlices ¶
func ConcatSlices[T any](ss ...[]T) []T
ConcatSlices returns a new slice built by appending all values from the given slices in order.
func FilterMap ¶
func FilterMap[K comparable, V any](m map[K]V, f func(k K, v V) bool) map[K]V
FilterMap copies a map including only (k, v) pairs for which the predicate returns true.
func FilterSlice ¶
FilterSlice makes a shallow copy of a slice including only elements for which the predicate returns true.
func GetSortedMapKeys ¶
GetSortedMapKeys returns a slice built by appending all keys in the map and sorting them.
func MapPtr ¶
func MapPtr[K comparable, V any](m map[K]V) map[K]*V
MapPtr returns a copy of the given map with each value passed through Ptr.
func MapPtrZeroToNil ¶
func MapPtrZeroToNil[K comparable, V comparable](m map[K]V) map[K]*V
MapPtrZeroToNil returns a copy of the given map with each value passed through PtrZeroToNil.
func MapValNilToDef ¶
func MapValNilToDef[K comparable, V any](m map[K]*V, d V) map[K]V
MapValNilToDef returns a copy of the given map with each value passed through ValNilToDef.
func MapValNilToZero ¶
func MapValNilToZero[K comparable, V any](m map[K]*V) map[K]V
MapValNilToZero returns a copy of the given map with each value passed through ValNilToZero.
func MergeMaps ¶
func MergeMaps[K comparable, V any](mm ...map[K]V) map[K]V
MergeMaps returns a new map built by setting all key/value pairs from the given maps in order.
func PredicateIsZeroValue ¶
func PredicateIsZeroValue[T comparable](v T) bool
PredicateIsZeroValue returns true if v is the zero-value of its type.
func PtrZeroToNil ¶
func PtrZeroToNil[T comparable](v T) *T
PtrZeroToNil returns a pointer to the given value if different from the zero-value, nil otherwise.
func PtrZeroToNilIfTrue ¶
func PtrZeroToNilIfTrue[T comparable](cond bool, v T) *T
PtrZeroToNilIfTrue returns a pointer to the given value if different from the zero-value and cond is true, nil otherwise.
func SafeSliceIndexDef ¶
SafeSliceIndexDef indexes a slice, supports negative indexes (from end), and returns a default value instead of panic.
func SafeSliceIndexPtr ¶
SafeSliceIndexPtr indexes a slice, supports negative indexes (from end), and returns pointer to value instead of panic.
func SafeSliceIndexZero ¶
SafeSliceIndexZero indexes a slice, supports negative indexes (from end), and returns a zero-value instead of panic.
func ShallowCopyMap ¶
func ShallowCopyMap[K comparable, V any](m map[K]V) map[K]V
ShallowCopyMap makes a shallow copy of a map.
func ShallowCopySlice ¶
func ShallowCopySlice[T any](s []T) []T
ShallowCopySlice makes a shallow copy of a slice.
func SlicePtr ¶
func SlicePtr[T any](s []T) []*T
SlicePtr returns a copy of the given slice with each element passed through Ptr.
func SlicePtrZeroToNil ¶
func SlicePtrZeroToNil[T comparable](s []T) []*T
SlicePtrZeroToNil returns a copy of the given slice with each element passed through PtrZeroToNil.
func SliceValNilToDef ¶
func SliceValNilToDef[T any](s []*T, d T) []T
SliceValNilToDef returns a copy of the given slice with each element passed through ValNilToDef.
func SliceValNilToZero ¶
func SliceValNilToZero[T any](s []*T) []T
SliceValNilToZero returns a copy of the given slice with each element passed through ValNilToZero.
func TransformMapValues ¶
func TransformMapValues[K comparable, V1 any, V2 any](m map[K]V1, f func(i V1) V2) map[K]V2
TransformMapValues returns a new map built by passing all values through the given function, while the keys remain stable.
func TransformSlice ¶
TransformSlice returns a new slice built by passing all elements through the given function.
func TransformSprintf ¶
TransformSprintf stringifies values using fmt.Sprintf("%v").
func ValNilToDef ¶
func ValNilToDef[T any](v *T, d T) T
ValNilToDef returns the value of the given pointer if found, the given default value otherwise.
func ValNilToZero ¶
func ValNilToZero[T any](v *T) T
ValNilToZero returns the value of the given pointer if found, a zero-value of the same type otherwise.
Types ¶
This section is empty.