IsCompatible returns true if o describes the (Go) type of val.
(val any)
| 559 | |
| 560 | // IsCompatible returns true if o describes the (Go) type of val. |
| 561 | func (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. |
| 578 | func (m *Map) Example(r *ExampleGenerator) any { |