MCPcopy Create free account
hub / github.com/google/go-cmp / IsType

Function IsType

cmp/internal/function/func.go:38–66  ·  view source on GitHub ↗

IsType reports whether the reflect.Type is of the specified function type.

(t reflect.Type, ft funcType)

Source from the content-addressed store, hash-verified

36
37// IsType reports whether the reflect.Type is of the specified function type.
38func IsType(t reflect.Type, ft funcType) bool {
39 if t == nil || t.Kind() != reflect.Func || t.IsVariadic() {
40 return false
41 }
42 ni, no := t.NumIn(), t.NumOut()
43 switch ft {
44 case tbFunc: // func(T) bool
45 if ni == 1 && no == 1 && t.Out(0) == boolType {
46 return true
47 }
48 case ttbFunc: // func(T, T) bool
49 if ni == 2 && no == 1 && t.In(0) == t.In(1) && t.Out(0) == boolType {
50 return true
51 }
52 case trbFunc: // func(T, R) bool
53 if ni == 2 && no == 1 && t.Out(0) == boolType {
54 return true
55 }
56 case tibFunc: // func(T, I) bool
57 if ni == 2 && no == 1 && t.In(0).AssignableTo(t.In(1)) && t.Out(0) == boolType {
58 return true
59 }
60 case trFunc: // func(T) R
61 if ni == 1 && no == 1 {
62 return true
63 }
64 }
65 return false
66}
67
68var lastIdentRx = regexp.MustCompile(`[_\p{L}][_\p{L}\p{N}]*$`)
69

Callers 8

tryMethodMethod · 0.92
FilterValuesFunction · 0.92
TransformerFunction · 0.92
ComparerFunction · 0.92
SortSlicesFunction · 0.92
SortMapsFunction · 0.92
IgnoreSliceElementsFunction · 0.92
IgnoreMapEntriesFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected