reflect
Runtime type introspection utilities inspired by Go's reflect.
Reflect exposes function-style APIs to inspect values and types at runtime. It represents a Type and a Value as Harneet maps, so you can pass them around and inspect their content.
Overview
- Values are Harneet
core.Objects. Typeis a map with at least keys:name(string),kind(string). Struct types also includefields(array of field names).Valueis a map with keys:value(any),type(Type).
Functions
-
reflect.TypeOf(value any) TypeReturns aTypemap describing the value. -
reflect.ValueOf(value any) ValueReturns aValuemap wrapping the value with itsType. -
reflect.KindOf(value any) stringReturns the basic kind of a value:int,float,string,bool,array,map,struct,tuple,nil,error,object. -
reflect.TypeName(t Type) stringReturnst'sname. -
reflect.TypeKind(t Type) stringReturnst'skind. -
reflect.TypeString(t Type) stringReturns a readable type string (same asname). -
reflect.ValueType(v Value) TypeReturns theTypecontained inv. -
reflect.ValueInterface(v Value) anyReturns the underlying value fromv. -
reflect.ValueKind(v Value) stringReturns the kind of the underlying value fromv. -
reflect.ValueIsNil(v Value) boolTrue if the underlying value isNone. -
reflect.ValueIsValid(v Value) boolTrue if the underlying value is notNone.
Kinds
Possible results from KindOf/TypeKind: - int, float, string, bool - array, map, struct, tuple - nil, error, object
Note: - For custom stdlib objects (e.g., UUID), TypeOf(value)["name"] and reflect.TypeName(TypeOf(value)) return the specific type name (like UUID), while the kind is the generic category object.
Struct Field Metadata
For struct values, TypeOf(structValue) includes a fields entry with all field names.
Example:
| Struct TypeOf | |
|---|---|
Examples
See examples/reflect/basic_test.ha for a runnable demo: