-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
59 lines (50 loc) · 806 Bytes
/
type.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
52
53
54
55
56
57
58
59
// Content managed by Project Forge, see [projectforge.md] for details.
package types
import (
"fmt"
)
type Type interface {
Key() string
Sortable() bool
Scalar() bool
fmt.Stringer
From(v any) any
Default(key string) any
}
type Types []Type
func TypeAs[T Type](t Type) T {
l, ok := t.(T)
if ok {
return l
}
w, ok := t.(*Wrapped)
if !ok {
var ret T
return ret
}
l, ok = w.T.(T)
if !ok {
var ret T
return ret
}
return l
}
func IsString(t Type) bool {
return t.Key() == KeyString
}
func IsBool(t Type) bool {
return t.Key() == KeyBool
}
func IsInt(t Type) bool {
return t.Key() == KeyInt
}
func IsList(t Type) bool {
return t.Key() == KeyList
}
func IsStringList(t Type) bool {
l := TypeAs[*List](t)
if l == nil {
return false
}
return l.V.T.Key() == KeyString
}