Documentation
¶
Index ¶
- Variables
- func AppendValues[T any](slice []T, into ...*T)
- func CountValues[ItemT comparable, ValueT Number](s []ItemT) map[ItemT]ValueT
- func Deref[T any](ptr *T) T
- func DerefOr[T any](ptr *T, orElse T) T
- func DynamicParseStruct[T any](tagName string, matcher func(string) string) (T, error)
- func MapKeysSlice[ItemT comparable, ValueT Number](m map[ItemT]ValueT) []ItemT
- func MatchAll[ItemT comparable](s []ItemT, value ItemT) bool
- func MatchAllFunc[ItemT comparable](s []ItemT, cond func(ItemT) bool) bool
- func MatchAny[ItemT comparable](slice []ItemT, value ItemT) *ItemT
- func MatchAnyFunc[ItemT any](slice []ItemT, match func(ItemT) bool) *ItemT
- func Max[T Number](a, b T) T
- func MergeReplace[T any](base []T, toAdd []T, equal func(a, b T) bool) []T
- func Ptr[T any](value T) *T
- func PtrNilOnEmpty[T any](value T) *T
- func RoundFloat(f float64, precision int) float64
- func SliceFilterFunc[ItemT any](from []ItemT, filter func(ItemT) bool) []ItemT
- func SliceTransform[FromT, ToT any](from []FromT, transformer func(FromT) ToT) []ToT
- func SlicesMatch[ItemT any](s1, s2 []ItemT, match func(ItemT, ItemT) bool) bool
- func SortEqual[ItemT cmp.Ordered](a, b []ItemT) bool
- func SortEqualFunc[ItemT any](a, b []ItemT, less func(ItemT, ItemT) int) bool
- func Sum[T any, ResT Number](a []T, fn func(T) ResT) ResT
- func Unique[ItemT comparable](s []ItemT) []ItemT
- type Number
- type Tag
Constants ¶
This section is empty.
Variables ¶
var DefaultKeyChar byte = '?'
var (
ErrAnyCouldNotFind = errors.New("unable to find any matching item")
)
Functions ¶
func AppendValues ¶
func AppendValues[T any](slice []T, into ...*T)
AppendValues is a generic function for inserting values into a slice ex: MapVars(res, "I", "need", "no", "sympathy") => []string{"I", "need", "no", "sympathy"}
func CountValues ¶ added in v1.9.0
func CountValues[ItemT comparable, ValueT Number](s []ItemT) map[ItemT]ValueT
func Deref ¶
func Deref[T any](ptr *T) T
Deref is a generic one-liner for safely dereferencing a pointer ex: Deref(&test{}) => test{} ex: Deref[test](nil) => test{}
func DerefOr ¶
func DerefOr[T any](ptr *T, orElse T) T
Deref is a generic one-liner for safely dereferencing a pointer, and choosing a default behavior in case dereferencing is not possible ex: Deref(test{"a"}, test{"b"}) => test{"a"} ex: Deref(nil, test{"b"}) => test{"b"}
func DynamicParseStruct ¶ added in v1.0.2
func MapKeysSlice ¶ added in v1.9.0
func MapKeysSlice[ItemT comparable, ValueT Number](m map[ItemT]ValueT) []ItemT
func MatchAll ¶
func MatchAll[ItemT comparable](s []ItemT, value ItemT) bool
MatchAll is a generic function verifying each item matches a value ex1: MatchAll([]string{"go", "go"}, "go") => true ex1: MatchAll([]string{"johnny", "b.", "goode"}, "goode") => false
func MatchAllFunc ¶
func MatchAllFunc[ItemT comparable](s []ItemT, cond func(ItemT) bool) bool
MatchAllFunc is a generic function verifying each item matches a predicate ex1: MatchAllFunc([]int{2, 4, 6}, func(item int) bool {return item%2 == 0}) => true ex2: MatchAllFunc([]int{2, 4, 5}, func(item int) bool {return item%2 == 0}) => false
func MatchAny ¶
func MatchAny[ItemT comparable](slice []ItemT, value ItemT) *ItemT
MatchAny is a generic function trying to find at least 1 element matching a value ex1: MatchAny([]string{"got", "me", "on", "my", "knees"}, "layla") => false ex2: MatchAny([]string{"like", "a", "fool"}, "fool") => true
func MatchAnyFunc ¶
MatchAnyFunc is a generic function trying to find at least 1 element matching a predicate ex1: MatchAnyFunc([]int{1, 2, 5}, func(item int) bool {return item % 5 == 0}) => true ex2: MatchAnyFunc([]int{1, 2, 6}, func(item int) bool {return item % 5 == 0}) => false
func MergeReplace ¶ added in v1.11.0
func Ptr ¶
func Ptr[T any](value T) *T
Ptr is a generic one-liner for making a pointer ex: Ptr("Im just a poor boy")
func PtrNilOnEmpty ¶
func PtrNilOnEmpty[T any](value T) *T
PtrNilOnEmpty is a generic one-liner for making a pointer, or nil if empty ex: Ptr("") => nil
func RoundFloat ¶ added in v1.5.0
func SliceFilterFunc ¶ added in v1.3.0
func SliceTransform ¶ added in v1.2.0
func SliceTransform[FromT, ToT any](from []FromT, transformer func(FromT) ToT) []ToT
func SlicesMatch ¶ added in v1.4.0
func SortEqualFunc ¶ added in v1.10.0
func Unique ¶ added in v1.9.0
func Unique[ItemT comparable](s []ItemT) []ItemT