Documentation ¶
Overview ¶
Deprecated: use appropriate sub packages in github.com/mandelsoft/goutils
Index ¶
- func AppendedSlice[E any](slice []E, elems ...E) []E
- func As[T any](o interface{}) T
- func AsE[T any](o interface{}, err error) (T, error)
- func AsI[T any](p any) T
- func Cast[S any](o any) (S, error)
- func Conditional[T any](cond bool, a, b T) T
- func ConvertSlice[S, T any](in ...S) []T
- func ConvertSliceTo[T, S any](in []S) []T
- func ConvertSliceWith[S, T, I any](c func(I) T, in []S) []T
- func KeyList[K Comparable[K], V any](m map[K]V) []K
- func MapKeyArray[K comparable, V any](m map[K]V) []K
- func MapValues[K comparable, V any](m map[K]V) []V
- func Pointer[T any](t T) *T
- func TryCast[T any](p any) (T, bool)
- func TypeOf[T any]() reflect.Type
- func Value[T any](t *T) T
- type Comparable
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendedSlice ¶ added in v0.4.0
func AppendedSlice[E any](slice []E, elems ...E) []E
func As ¶ added in v0.3.0
func As[T any](o interface{}) T
As casts an element typed by a type parameter to a subtype, given by the type parameter T.
func AsE ¶ added in v0.3.0
AsE casts a pointer/error result to an interface/error result. In Go this cannot be done directly, because returning a nil pinter for an interface return type, would result is a typed nil value for the interface, and not nil, if the pointer is nil. Unfortunately, the relation of the pointer (even the fact, that a pointer is expected)to the interface (even the fact, that an interface is expected) cannot be expressed with Go generics.
func AsI ¶ added in v0.4.1
AsI converts a struct pointer to an appropriate interface type given as type parameter. In Go this cannot be done directly, because returning a nil pinter for an interface return type, would result is a typed nil value for the interface, and not nil, if the pointer is nil. Unfortunately, the relation of the pointer (even the fact, that a pointer is expected)to the interface (even the fact, that an interface is expected) cannot be expressed with Go generics.
func Cast ¶ added in v0.3.0
Cast casts one type parameter to another type parameter, which have a sub type relation. This cannot be described by type parameter constraints in Go, because constraints may not be type parameters again.
func Conditional ¶
func ConvertSlice ¶ added in v0.3.0
func ConvertSlice[S, T any](in ...S) []T
ConvertSlice Converts the element typ of a slice. hereby, Type S must be a subtype of type T.
func ConvertSliceTo ¶ added in v0.4.1
func ConvertSliceTo[T, S any](in []S) []T
ConvertSliceTo Converts the element typ of a slice. hereby, Type S must be a subtype of type T. typically, S can be omitted when used, because it can be derived from the argument.
func ConvertSliceWith ¶ added in v0.4.1
func ConvertSliceWith[S, T, I any](c func(I) T, in []S) []T
ConvertSliceWith converts the element type of a slice using a converter function. Unfortunately this cannot be expressed in a type-safe way in Go. I MUST follow the type constraint I super S, which cannot be expressed in Go.
func KeyList ¶ added in v0.4.1
func KeyList[K Comparable[K], V any](m map[K]V) []K
func MapKeyArray ¶ added in v0.3.0
func MapKeyArray[K comparable, V any](m map[K]V) []K
func MapValues ¶ added in v0.3.0
func MapValues[K comparable, V any](m map[K]V) []V
func TryCast ¶ added in v0.3.0
TryCast tries a type cast usable for variable with a parametric type.
Types ¶
type Comparable ¶ added in v0.4.1
type Comparable[K any] interface { comparable Compare(o K) int }
type Set ¶
type Set[K comparable] map[K]struct{}
func KeySet ¶ added in v0.2.0
func KeySet[K comparable, V any](m map[K]V) Set[K]
func MapKeys ¶ added in v0.3.0
func MapKeys[K comparable, V any](m map[K]V) Set[K]
func NewSet ¶
func NewSet[K comparable](keys ...K) Set[K]