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

Method IsCompatible

expr/types.go:403–416  ·  view source on GitHub ↗

IsCompatible returns true if val is compatible with p.

(val any)

Source from the content-addressed store, hash-verified

401
402// IsCompatible returns true if val is compatible with p.
403func (a *Array) IsCompatible(val any) bool {
404 k := reflect.TypeOf(val).Kind()
405 if k != reflect.Array && k != reflect.Slice {
406 return false
407 }
408 v := reflect.ValueOf(val)
409 for i := 0; i < v.Len(); i++ {
410 compat := (a.ElemType.Type != nil) && a.ElemType.Type.IsCompatible(v.Index(i).Interface())
411 if !compat {
412 return false
413 }
414 }
415 return true
416}
417
418// Example generates a pseudo-random array value using the given random
419// generator.

Callers 1

TestArrayIsCompatibleFunction · 0.95

Calls 2

KindMethod · 0.65
IsCompatibleMethod · 0.65

Tested by 1

TestArrayIsCompatibleFunction · 0.76