IsType reports whether the reflect.Type is of the specified function type.
(t reflect.Type, ft funcType)
| 36 | |
| 37 | // IsType reports whether the reflect.Type is of the specified function type. |
| 38 | func 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 | |
| 68 | var lastIdentRx = regexp.MustCompile(`[_\p{L}][_\p{L}\p{N}]*$`) |
| 69 |
no outgoing calls
no test coverage detected