You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is currently no way, via the reflection interface, to do a
conditional set. Such a set would have the semantics of the two-result
type assertion in the language itself, but would allow the use of such
semantics on types passed around as variables.
Proposed semantics:
func (v *InterfaceValue) ConditionalSet(x Value) (ok bool)
{
if x implements v or x is the zero interface value {
set v to x;
returns true;
} else {
set v to zero interface value;
return false;
}
}
This would allow reflection-based checks on whether a value implements an
interface, and also (by construction of zero Value instances) whether any
reflect.Type implements a particular reflect.InterfaceType without having
to iterate the methods and evaluate the logic manually.