forked from gomem/gomem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement_numeric.gen.go.tmpl
More file actions
189 lines (165 loc) · 5.05 KB
/
element_numeric.gen.go.tmpl
File metadata and controls
189 lines (165 loc) · 5.05 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright 2019 Nick Poorman
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dataframe
import (
"errors"
"fmt"
"github.com/apache/arrow/go/v10/arrow"
"github.com/apache/arrow/go/v10/arrow/decimal128"
"github.com/apache/arrow/go/v10/arrow/float16"
)
{{range .In}}
// {{.Name}}Element has logic to apply to this type.
type {{.Name}}Element struct {
v interface{}
}
// New{{.Name}}Element creates a new {{.Name}}Element logic wrapper
// from the given value provided as v.
func New{{.Name}}Element(v interface{}) *{{.Name}}Element {
return &{{.Name}}Element{
v: v,
}
}
// compare takes the left and right elements and applies the comparator function to them.
func (e {{.Name}}Element) compare(r Element, f func(left, right {{.Type}}) bool) (bool, error) {
rE, ok := r.(*{{.Name}}Element)
if !ok {
return false, fmt.Errorf("cannot cast %v to {{.Name}}Element", r)
}
// When their nil status isn't the same, we can't compare them.
// Explicit both nil should be handled elsewhere.
if e.IsNil() != rE.IsNil() {
return false, nil
}
lv, lok := e.v.({{.Type}})
if !lok {
return false, fmt.Errorf("cannot assert %v is a {{.Type}}", e.v)
}
rv, rok := rE.v.({{.Type}})
if !rok {
return false, fmt.Errorf("cannot assert %v is a {{.Type}}", rE.v)
}
return f(lv, rv), nil
}
// Comparation methods
// Eq returns true if the left {{.Name}}Element is equal to the right {{.Name}}Element.
// When both are nil Eq returns false because nil actualy signifies "unknown"
// and you can't compare two things when you don't know what they are.
func (e {{.Name}}Element) Eq(r Element) (bool, error) {
if e.IsNil() && r.IsNil() {
return false, nil
}
return e.compare(r, func(left, right {{.Type}}) bool {
{{- if .Compare.Eq }}
return {{.Compare.Eq}}
{{- else}}
return left == right
{{- end}}
})
}
// EqStrict returns true if the left {{.Name}}Element is equal to the right {{.Name}}Element.
// When both are nil EqStrict returns true.
func (e {{.Name}}Element) EqStrict(r Element) (bool, error) {
if e.IsNil() && r.IsNil() {
return true, nil
}
return e.compare(r, func(left, right {{.Type}}) bool {
{{- if .Compare.Eq }}
return {{.Compare.Eq}}
{{- else}}
return left == right
{{- end}}
})
}
// Neq returns true if the left {{.Name}}Element
// is not equal to the right {{.Name}}Element.
func (e {{.Name}}Element) Neq(r Element) (bool, error) {
v, ok := e.Eq(r)
return !v, ok
}
// Less returns true if the left {{.Name}}Element
// is less than the right {{.Name}}Element.
func (e {{.Name}}Element) Less(r Element) (bool, error) {
{{- if not .Compare.Less}}
return false, errors.New("operator < not defined on {{.Name}}")
{{- else}}
return e.compare(r, func(left, right {{.Type}}) bool {
{{- if .Compare.Less }}
return {{.Compare.Less}}
{{- else}}
return left < right
{{- end}}
})
{{- end}}
}
// LessEq returns true if the left {{.Name}}Element
// is less than or equal to the right {{.Name}}Element.
func (e {{.Name}}Element) LessEq(r Element) (bool, error) {
{{- if not .Compare.LessEq}}
return false, errors.New("operator <= not defined on {{.Name}}")
{{- else}}
return e.compare(r, func(left, right {{.Type}}) bool {
{{- if .Compare.LessEq }}
return {{.Compare.LessEq}}
{{- else}}
return left <= right
{{- end}}
})
{{- end}}
}
// Greater returns true if the left {{.Name}}Element
// is greter than the right {{.Name}}Element.
func (e {{.Name}}Element) Greater(r Element) (bool, error) {
{{- if not .Compare.Greater}}
return false, errors.New("operator > not defined on {{.Name}}")
{{- else}}
return e.compare(r, func(left, right {{.Type}}) bool {
{{- if .Compare.Greater }}
return {{.Compare.Greater}}
{{- else}}
return left > right
{{- end}}
})
{{- end}}
}
// GreaterEq returns true if the left {{.Name}}Element
// is greter than or equal to the right {{.Name}}Element.
func (e {{.Name}}Element) GreaterEq(r Element) (bool, error) {
{{- if not .Compare.GreaterEq}}
return false, errors.New("operator >= not defined on {{.Name}}")
{{- else}}
return e.compare(r, func(left, right {{.Type}}) bool {
{{- if .Compare.GreaterEq }}
return {{.Compare.GreaterEq}}
{{- else}}
return left >= right
{{- end}}
})
{{- end}}
}
// Accessor/conversion methods
// Copy returns a copy of this {{.Name}}Element.
func (e {{.Name}}Element) Copy() Element {
return e
}
// String prints the value of this element as a string.
func (e {{.Name}}Element) String() string {
return fmt.Sprintf("%v", e.v)
}
// Information methods
// IsNil returns true when the underlying value is nil.
func (e {{.Name}}Element) IsNil() bool {
return e.v == nil
}
{{end}}