memz

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchSlice

func BatchSlice[T any](s []T, batchSize int) [][]T

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

func FilterSlice[T any](s []T, f func(t T) bool) []T

FilterSlice makes a shallow copy of a slice including only elements for which the predicate returns true.

func GetSortedMapKeys

func GetSortedMapKeys[K cmp.Ordered, V any](m map[K]V, less func(K, K) bool) []K

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 Max

func Max[T cmp.Ordered](v1, v2 T) T

Max returns the highest between v1 and v2.

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 Min

func Min[T cmp.Ordered](v1, v2 T) T

Min returns the lowest between v1 and v2.

func PredicateIsZeroValue

func PredicateIsZeroValue[T comparable](v T) bool

PredicateIsZeroValue returns true if v is the zero-value of its type.

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to the given value.

func PtrIfTrue

func PtrIfTrue[T any](cond bool, v T) *T

PtrIfTrue returns a pointer to the given value of cond is true, nil otherwise.

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

func SafeSliceIndexDef[T any](s []T, i int, d T) T

SafeSliceIndexDef indexes a slice, supports negative indexes (from end), and returns a default value instead of panic.

func SafeSliceIndexPtr

func SafeSliceIndexPtr[T any](s []T, i int) *T

SafeSliceIndexPtr indexes a slice, supports negative indexes (from end), and returns pointer to value instead of panic.

func SafeSliceIndexZero

func SafeSliceIndexZero[T any](s []T, i int) T

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

func TransformSlice[I any, O any](s []I, f func(i I) O) []O

TransformSlice returns a new slice built by passing all elements through the given function.

func TransformSprintf

func TransformSprintf[V any](v V) string

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.

Jump to

Keyboard shortcuts

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