dt

package module
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 7 Imported by: 3

README

data types and pointer manipulation

  • slices
  • safe one-line pointer making
  • safe one-line pointer dereferencing

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyChar byte = '?'
View Source
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 DynamicParseStruct[T any](tagName string, matcher func(string) string) (T, error)

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

func MatchAnyFunc[ItemT any](slice []ItemT, match func(ItemT) bool) *ItemT

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 Max added in v1.9.0

func Max[T Number](a, b T) T

func MergeReplace added in v1.11.0

func MergeReplace[T any](base []T, toAdd []T, equal func(a, b T) bool) []T

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 RoundFloat(f float64, precision int) float64

func SliceFilterFunc added in v1.3.0

func SliceFilterFunc[ItemT any](from []ItemT, filter func(ItemT) bool) []ItemT

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 SlicesMatch[ItemT any](s1, s2 []ItemT, match func(ItemT, ItemT) bool) bool

func SortEqual added in v1.8.0

func SortEqual[ItemT cmp.Ordered](a, b []ItemT) bool

func SortEqualFunc added in v1.10.0

func SortEqualFunc[ItemT any](a, b []ItemT, less func(ItemT, ItemT) int) bool

func Sum added in v1.9.0

func Sum[T any, ResT Number](a []T, fn func(T) ResT) ResT

func Unique added in v1.9.0

func Unique[ItemT comparable](s []ItemT) []ItemT

Types

type Number added in v1.9.0

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64
}

type Tag added in v1.0.2

type Tag struct {
	// contains filtered or unexported fields
}

func NewTag added in v1.0.2

func NewTag(rawTag string) Tag

Jump to

Keyboard shortcuts

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