reflect

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package reflect contains a collection of helpful generic functions that support reflection. It is currently not part of the public interface and must be consider as highly instable.

Index

Constants

View Source
const (
	// Func alias for `reflect.Func`.
	Func = reflect.Func
)

Aliases for constant values.

Variables

View Source
var (
	// TypeOf alias for `reflect.TypeOf`.
	TypeOf = reflect.TypeOf
	// ValueOf alias for `reflect.ValueOf`.
	ValueOf = reflect.ValueOf
)

Aliases for function values.

Functions

func AnyFuncOf

func AnyFuncOf(args int, variadic bool) reflect.Type

AnyFuncOf returns a function with given number of arguments accepting any type.

func ArgOf

func ArgOf(v reflect.Value) any

ArgOf returns the argument of the given value.

func ArgsOf

func ArgsOf(values ...reflect.Value) []any

ArgsOf returns the arguments slice for the given values.

func BaseFuncOf

func BaseFuncOf(mtype reflect.Type, in, out int) reflect.Type

BaseFuncOf allows to extract a base function from an interface function containing no receiver and suppressing the return values - if necessary. The given `in` and `out` values allow to restrict the included input and output arguments. Use `1` to remove the first argument, or `NumIn/NumOut` to remove all arguments.

func FieldArgOf

func FieldArgOf(v reflect.Value, i int) any

FieldArgOf returns the argument of the `i`th field of the given value.

func FindArgOf

func FindArgOf[P any](param P, deflt any, names ...string) any

FindArgOf find the first argument with one of the given field names matching the type matching the default argument type.

func MakeFuncOf

func MakeFuncOf(
	mtype reflect.Type, call func([]reflect.Value) []reflect.Value,
) any

MakeFuncOf returns a newly created function with given reflective function.

func NewErrInvalidType

func NewErrInvalidType(index int, expect, actual reflect.Type) error

NewErrInvalidType creates a new error reporting an invalid type during value slice creation.

func ValuesIn

func ValuesIn(ftype reflect.Type, args ...any) []reflect.Value

ValuesIn returns the reflection values matching the input arguments of the given function.

func ValuesOut

func ValuesOut(ftype reflect.Type, lenient bool, args ...any) []reflect.Value

ValuesOut returns the reflection values matching the output arguments of the given function. If lenient is set, non existing output arguments are filled with zero values to support incomplete argument lists.

Types

type Type

type Type = reflect.Type

Type alias for `reflect.Type`.

type Value

type Value = reflect.Value

Value alias for `reflect.Value`.

Jump to

Keyboard shortcuts

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