genericsutil

package
v0.85.0-pre.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package genericsutil provides helpers for implementing type erasure patterns

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertOrZero

func AssertOrZero[T any](v any) T

Returns v cast as type T if possible, otherwise returns the zero value of T

func IsNone

func IsNone(v any) bool

Returns true if v is either an empty struct or a pointer to an empty struct

func OrDefault

func OrDefault[F comparable](field F, defaultVal F) F

Returns field if it is not the zero value for its type, otherwise returns defaultVal

func Zero

func Zero[T any]() T

Returns the zero value of type T

Types

type AnyZeroHelper

type AnyZeroHelper interface {
	I() any    // returns direct I zero val
	O() any    // returns direct O zero val
	IPtr() any // returns `new(I)` (pointer to I)
	OPtr() any // returns `new(O)` (pointer to O)
}

type None

type None = struct{}

Simple alias for an empty struct

type ZeroHelper

type ZeroHelper[I any, O any] struct{}

func (ZeroHelper[I, O]) I

func (ZeroHelper[I, O]) I() any

func (ZeroHelper[I, O]) IPtr

func (ZeroHelper[I, O]) IPtr() any

func (ZeroHelper[I, O]) O

func (ZeroHelper[I, O]) O() any

func (ZeroHelper[I, O]) OPtr

func (ZeroHelper[I, O]) OPtr() any

Jump to

Keyboard shortcuts

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