-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathbuilder.go
98 lines (85 loc) · 1.76 KB
/
builder.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package value
type (
Builder struct{}
builderList struct {
items []Value
}
builderTypedList[T any] struct {
parent *builderList
add func(T) Value
}
)
func (b Builder) List() *builderList {
return &builderList{}
}
func (b *builderList) Uint8() *builderTypedList[uint8] {
return &builderTypedList[uint8]{
parent: b,
add: func(v uint8) Value {
return Uint8Value(v)
},
}
}
func (b *builderList) Uint16() *builderTypedList[uint16] {
return &builderTypedList[uint16]{
parent: b,
add: func(v uint16) Value {
return Uint16Value(v)
},
}
}
func (b *builderList) Uint32() *builderTypedList[uint32] {
return &builderTypedList[uint32]{
parent: b,
add: func(v uint32) Value {
return Uint32Value(v)
},
}
}
func (b *builderList) Uint64() *builderTypedList[uint64] {
return &builderTypedList[uint64]{
parent: b,
add: func(v uint64) Value {
return Uint64Value(v)
},
}
}
func (b *builderList) Int8() *builderTypedList[int8] {
return &builderTypedList[int8]{
parent: b,
add: func(v int8) Value {
return Int8Value(v)
},
}
}
func (b *builderList) Int16() *builderTypedList[int16] {
return &builderTypedList[int16]{
parent: b,
add: func(v int16) Value {
return Int16Value(v)
},
}
}
func (b *builderList) Int32() *builderTypedList[int32] {
return &builderTypedList[int32]{
parent: b,
add: func(v int32) Value {
return Int32Value(v)
},
}
}
func (b *builderList) Int64() *builderTypedList[int64] {
return &builderTypedList[int64]{
parent: b,
add: func(v int64) Value {
return Int64Value(v)
},
}
}
func (b *builderTypedList[T]) Add(v T) *builderTypedList[T] {
b.parent.items = append(b.parent.items, b.add(v))
return b
}
func (b *builderTypedList[T]) Build() Value {
return ListValue(b.parent.items...)
}