Documentation ¶
Overview ¶
Package reflectx contains a set of reflection utilities and well-known types.
Index ¶
- Variables
- func CallNoPanic(fn Func, args []interface{}) (ret []interface{}, err error)
- func FindTaggedField(t reflect.Type, values ...string) (reflect.StructField, bool)
- func FunctionName(fn interface{}) string
- func HasTag(f reflect.StructField, values ...string) bool
- func HasTaggedField(t reflect.Type, values ...string) bool
- func Interface(list []reflect.Value) []interface{}
- func IsComplex(t reflect.Type) bool
- func IsFloat(t reflect.Type) bool
- func IsInteger(t reflect.Type) bool
- func IsNumber(t reflect.Type) bool
- func LoadFunction(ptr uintptr, t reflect.Type) interface{}
- func MakeSlice(t reflect.Type, values ...reflect.Value) reflect.Value
- func RegisterFunc(t reflect.Type, maker func(interface{}) Func)
- func RegisterStructWrapper(t reflect.Type, wrapper func(interface{}) map[string]Func)
- func SetFieldValue(s reflect.Value, f reflect.StructField, value reflect.Value)
- func SetTaggedFieldValue(v reflect.Value, tag string, value reflect.Value)
- func ShallowClone(v interface{}) interface{}
- func SkipPtr(t reflect.Type) reflect.Type
- func UnderlyingType(value reflect.Value) reflect.Value
- func UnmarshalJSON(t reflect.Type, str string) (interface{}, error)
- func UpdateMap(base, updates interface{})
- func ValueOf(list []interface{}) []reflect.Value
- func WrapMethods(fn interface{}) (map[string]Func, bool)
- type Func
- type Func0x0
- type Func0x1
- type Func0x2
- type Func0x3
- type Func1x0
- type Func1x1
- type Func1x2
- type Func1x3
- type Func2x0
- type Func2x1
- type Func2x2
- type Func2x3
- type Func3x0
- type Func3x1
- type Func3x2
- type Func3x3
- type Func4x0
- type Func4x1
- type Func4x2
- type Func4x3
- type Func5x0
- type Func5x1
- type Func5x2
- type Func5x3
- type Func6x0
- type Func6x1
- type Func6x2
- type Func6x3
- type Func7x0
- type Func7x1
- type Func7x2
- type Func7x3
Constants ¶
This section is empty.
Variables ¶
var ( Bool = reflect.TypeOf((*bool)(nil)).Elem() Int = reflect.TypeOf((*int)(nil)).Elem() Int8 = reflect.TypeOf((*int8)(nil)).Elem() Int16 = reflect.TypeOf((*int16)(nil)).Elem() Int32 = reflect.TypeOf((*int32)(nil)).Elem() Int64 = reflect.TypeOf((*int64)(nil)).Elem() Uint = reflect.TypeOf((*uint)(nil)).Elem() Uint8 = reflect.TypeOf((*uint8)(nil)).Elem() Uint16 = reflect.TypeOf((*uint16)(nil)).Elem() Uint32 = reflect.TypeOf((*uint32)(nil)).Elem() Uint64 = reflect.TypeOf((*uint64)(nil)).Elem() Float32 = reflect.TypeOf((*float32)(nil)).Elem() Float64 = reflect.TypeOf((*float64)(nil)).Elem() String = reflect.TypeOf((*string)(nil)).Elem() Error = reflect.TypeOf((*error)(nil)).Elem() Context = reflect.TypeOf((*context.Context)(nil)).Elem() Type = reflect.TypeOf((*reflect.Type)(nil)).Elem() ByteSlice = reflect.TypeOf((*[]byte)(nil)).Elem() )
Well-known reflected types. Convenience definitions.
Functions ¶
func CallNoPanic ¶
CallNoPanic calls the given Func and catches any panic.
func FindTaggedField ¶
FindTaggedField returns the field tagged with any of the given tag values, if any. The tags are all under the "beam" StructTag key.
func FunctionName ¶
func FunctionName(fn interface{}) string
FunctionName returns the symbol name of a function. It panics if the given value is not a function.
func HasTag ¶
func HasTag(f reflect.StructField, values ...string) bool
HasTag returns true iff the given field contains one of the given tags under the "beam" key.
func HasTaggedField ¶
HasTaggedField returns true iff the given struct has a field with any of the given tag values.
func Interface ¶
Interface performs a per-element Interface call.
func IsComplex ¶
IsComplex returns true iff the given type is complex64 or complex128.
func IsFloat ¶
IsFloat returns true iff the given type is float32 or float64.
func IsInteger ¶
IsInteger returns true iff the given type is an integer, such as uint16, int, or int64.
func IsNumber ¶
IsNumber returns true iff the given type is an integer, float, or complex.
func LoadFunction ¶
LoadFunction loads a function from a pointer and type. Assumes the pointer points to a valid function implementation.
func MakeSlice ¶
MakeSlice creates a slice of type []T with the given elements.
func RegisterFunc ¶
RegisterFunc registers an custom Func factory for the given type, such as "func(int)bool". If multiple Func factories are registered for the same type, the last registration wins.
func RegisterStructWrapper ¶
RegisterStructWrapper takes in the reflect.Type of a structural DoFn, and a wrapping function that will take an instance of that struct type and produce a map of method names to of closured Funcs that call the method on the instance of the struct.
The goal is to avoid the implicit reflective method invocation penalty that occurs when passing a method through the reflect package.
func SetFieldValue ¶
SetFieldValue sets s.f = value. Panics if not valid.
func SetTaggedFieldValue ¶
SetTaggedFieldValue sets s.f = value, where f has the tag "beam:tag". Panics if not valid.
func ShallowClone ¶
func ShallowClone(v interface{}) interface{}
ShallowClone creates a shallow copy of the given value. Most useful for slices and maps.
func SkipPtr ¶
SkipPtr returns the target of a Ptr type, if a Ptr. Otherwise itself.
func UnderlyingType ¶
UnderlyingType drops value's type by converting it to an interface and then returning ValueOf() the untyped value.
func UnmarshalJSON ¶
UnmarshalJSON decodes a json string as then given type. It is suitable for when the type is not statically known.
func UpdateMap ¶
func UpdateMap(base, updates interface{})
UpdateMap merges two maps of type map[K]*V, with the second overwriting values into the first (and mutating it). If the overwriting value is nil, the key is deleted.
func ValueOf ¶
ValueOf performs a per-element reflect.ValueOf.
Types ¶
type Func ¶
type Func interface { // Name returns the name of the function. Name() string // Type returns the type. Type() reflect.Type // Call invokes the implicit fn with arguments. Call(args []interface{}) []interface{} }
Func represents a callable untyped function. This indirection allows us to avoid reflection call overhead for certain types as well as faster dynamic function implementations.
type Func1x3 ¶
type Func1x3 interface { Func Call1x3(interface{}) (interface{}, interface{}, interface{}) }
type Func2x2 ¶
type Func2x2 interface { Func Call2x2(interface{}, interface{}) (interface{}, interface{}) }
type Func2x3 ¶
type Func2x3 interface { Func Call2x3(interface{}, interface{}) (interface{}, interface{}, interface{}) }
type Func3x1 ¶
type Func3x1 interface { Func Call3x1(interface{}, interface{}, interface{}) interface{} }
type Func3x2 ¶
type Func3x2 interface { Func Call3x2(interface{}, interface{}, interface{}) (interface{}, interface{}) }
type Func3x3 ¶
type Func3x3 interface { Func Call3x3(interface{}, interface{}, interface{}) (interface{}, interface{}, interface{}) }
type Func4x0 ¶
type Func4x0 interface { Func Call4x0(interface{}, interface{}, interface{}, interface{}) }
type Func4x1 ¶
type Func4x1 interface { Func Call4x1(interface{}, interface{}, interface{}, interface{}) interface{} }
type Func4x2 ¶
type Func4x2 interface { Func Call4x2(interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}) }
type Func4x3 ¶
type Func4x3 interface { Func Call4x3(interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}, interface{}) }
type Func5x0 ¶
type Func5x0 interface { Func Call5x0(interface{}, interface{}, interface{}, interface{}, interface{}) }
type Func5x1 ¶
type Func5x1 interface { Func Call5x1(interface{}, interface{}, interface{}, interface{}, interface{}) interface{} }
type Func5x2 ¶
type Func5x2 interface { Func Call5x2(interface{}, interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}) }
type Func5x3 ¶
type Func5x3 interface { Func Call5x3(interface{}, interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}, interface{}) }
type Func6x0 ¶
type Func6x0 interface { Func Call6x0(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) }
type Func6x1 ¶
type Func6x1 interface { Func Call6x1(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) interface{} }
type Func6x2 ¶
type Func6x2 interface { Func Call6x2(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}) }
type Func6x3 ¶
type Func6x3 interface { Func Call6x3(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}, interface{}) }
type Func7x0 ¶
type Func7x0 interface { Func Call7x0(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) }
type Func7x1 ¶
type Func7x1 interface { Func Call7x1(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) interface{} }