UnpackUntilKind unpacks the reflect value until it matches the given kind.
(k reflect.Kind)
| 252 | |
| 253 | // UnpackUntilKind unpacks the reflect value until it matches the given kind. |
| 254 | func (v *Value) UnpackUntilKind(k reflect.Kind) (*Value, error) { |
| 255 | res := v.value |
| 256 | for { |
| 257 | if res.Kind() == k { |
| 258 | return NewValue(res), nil |
| 259 | } |
| 260 | if res.Kind() == reflect.Interface || res.Kind() == reflect.Pointer && !res.IsNil() { |
| 261 | res = res.Elem() |
| 262 | continue |
| 263 | } |
| 264 | return nil, fmt.Errorf("could not unpack to kind: %s", k) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // UnpackUntilKinds unpacks the reflect value until it matches the given kind. |
| 269 | func (v *Value) UnpackUntilKinds(kinds ...reflect.Kind) (*Value, error) { |