MCPcopy Create free account
hub / github.com/goadesign/goa / IsCompatible

Method IsCompatible

expr/types.go:561–575  ·  view source on GitHub ↗

IsCompatible returns true if o describes the (Go) type of val.

(val any)

Source from the content-addressed store, hash-verified

559
560// IsCompatible returns true if o describes the (Go) type of val.
561func (m *Map) IsCompatible(val any) bool {
562 k := reflect.TypeOf(val).Kind()
563 if k != reflect.Map {
564 return false
565 }
566 v := reflect.ValueOf(val)
567 for _, key := range v.MapKeys() {
568 keyCompat := m.KeyType.Type == nil || m.KeyType.Type.IsCompatible(key.Interface())
569 elemCompat := m.ElemType.Type == nil || m.ElemType.Type.IsCompatible(v.MapIndex(key).Interface())
570 if !keyCompat || !elemCompat {
571 return false
572 }
573 }
574 return true
575}
576
577// Example returns a random example value.
578func (m *Map) Example(r *ExampleGenerator) any {

Callers 1

TestMapIsCompatibleFunction · 0.95

Calls 2

KindMethod · 0.65
IsCompatibleMethod · 0.65

Tested by 1

TestMapIsCompatibleFunction · 0.76