-
Notifications
You must be signed in to change notification settings - Fork 1
/
kind.go
51 lines (42 loc) · 1.18 KB
/
kind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package refutil
import "reflect"
// KindOneOf return true if type is one of the kind supplied
func KindOneOf(t Kinder, kinds ...reflect.Kind) bool {
searched := t.Kind()
for _, k := range kinds {
if k == searched {
return true
}
}
return false
}
// IsKind return true if type or value is specific kind
func IsKind(t Kinder, kind reflect.Kind) bool {
return t.Kind() == kind
}
// IsKind is sugar to simplify conditions
func (t Type) IsKind(k reflect.Kind) bool {
return IsKind(t, k)
}
// KindOneOf is method to compare type against multiple
// reflect.Type with logical OR
func (t Type) KindOneOf(k ...reflect.Kind) bool {
return KindOneOf(t, k...)
}
// IsKind is sugar to simplify conditions
func (t Value) IsKind(k reflect.Kind) bool {
return IsKind(t, k)
}
// KindOneOf is method to compare type against multiple
// reflect.Type with logical OR
func (t Value) KindOneOf(k ...reflect.Kind) bool {
return KindOneOf(t, k...)
}
// IsKind reports if data is specific kind
func (v Data) IsKind(k reflect.Kind) bool {
return v.Value().IsKind(k)
}
// KindOneOf reports if data is one if expected kinds
func (v Data) KindOneOf(k ...reflect.Kind) bool {
return v.Value().KindOneOf(k...)
}