generics

package
v2.0.0-...-98cc131 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T any](o interface{}) T

func AsE

func AsE[T any](o interface{}, err error) (T, error)

func Cast

func Cast[S any](o any) (S, error)

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 CastPointer

func CastPointer[T any](p any, err error) (T, error)

CastPointer 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 Conditional

func Conditional[T any](cond bool, a, b T) T

func ConvertSlice

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 MapKeyArray

func MapKeyArray[K comparable, V any](m map[K]V) []K

func MapValues

func MapValues[K comparable, V any](m map[K]V) []V

func Nil

func Nil[T any]() T

func Pointer

func Pointer[T any](t T) *T

func TryCast

func TryCast[T any](p any) (T, bool)

TryCast tries a type cast usable for variable with a parametric type.

func Value

func Value[T any](t *T) T

Types

type Set

type Set[K comparable] map[K]struct{}

func KeySet

func KeySet[K comparable, V any](m map[K]V) Set[K]

func MapKeys

func MapKeys[K comparable, V any](m map[K]V) Set[K]

func NewSet

func NewSet[K comparable](keys ...K) Set[K]

func (Set[K]) Add

func (s Set[K]) Add(keys ...K) Set[K]

func (Set[K]) AsArray

func (s Set[K]) AsArray() []K

func (Set[K]) Contains

func (s Set[K]) Contains(keys ...K) bool

func (Set[K]) Delete

func (s Set[K]) Delete(keys ...K) Set[K]

Jump to

Keyboard shortcuts

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