Skip to content

Commit dd9f94b

Browse files
authored
Add doc.go and fix some documentation issues in generation template (#11)
1 parent 853454b commit dd9f94b

File tree

12 files changed

+97
-60
lines changed

12 files changed

+97
-60
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Go](https://github.com/barweiss/go-tuple/actions/workflows/go.yml/badge.svg)](https://github.com/barweiss/go-tuple/actions/workflows/go.yml)
44
[![Coverage Status](https://coveralls.io/repos/github/barweiss/go-tuple/badge.svg)](https://coveralls.io/github/barweiss/go-tuple)
5+
[![Go Reference](https://pkg.go.dev/badge/github.com/barweiss/go-tuple.svg)](https://pkg.go.dev/github.com/barweiss/go-tuple)
56

67
Go 1.18 tuple implementation.
78

doc.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// package tuple defines tuple types that can hold multiple values of varying types. Currently, tuples with up to 9 values are supported.
2+
//
3+
// Tuple methods:
4+
//
5+
// - Len returns the number of values held by the tuple.
6+
// - Values returns the values held by the tuple.
7+
// - Array returns an array of the tuple values.
8+
// - Slice returns a slice of the tuple values.
9+
// - String returns the string representation of the tuple.
10+
// - GoString returns a Go-syntax representation of the tuple.
11+
//
12+
// Tuple creation functions:
13+
//
14+
// - New<N> creates a new tuple holding N generic values.
15+
// - FromArray<N> returns a tuple from an array of length N.
16+
// If any of the values can not be converted to the generic type, an error is returned.
17+
// - FromArray<N>X returns a tuple from an array of length N.
18+
// If any of the values can not be converted to the generic type, the function panics.
19+
// - FromSlice<N> returns a tuple from a slice of length N.
20+
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, an error is returned.
21+
// - FromSlice<N>X returns a tuple from a slice of length N.
22+
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, the function panics.
23+
//
24+
// Tuple comparison functions:
25+
//
26+
// - Equal<N> returns whether the host tuple is equal to the other tuple.
27+
// - Compare<N> returns whether the host tuple is semantically less than, equal to, or greater than the guest tuple.
28+
// - LessThan<N> returns whether the host tuple is semantically less than the guest tuple.
29+
// - LessOrEqual<N> returns whether the host tuple is semantically less than or equal to the guest tuple.
30+
// - GreaterThan<N> returns whether the host tuple is semantically greater than the guest tuple.
31+
// - GreaterOrEqual<N> returns whether the host tuple is semantically greater than or equal to the guest tuple.
32+
//
33+
// Tuple comparison functions may have an "C" or "E" suffix as overload with additional supported type constraints.
34+
// Comparison functions ending with "C" accept the "Comparable" constraint.
35+
// Comparison functions ending with "E" accept the "Equalable contraint.
36+
package tuple

scripts/gen/tuple.tpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,42 +188,42 @@ func LessThan{{.Len}}C[{{genericTypesDeclGenericConstraint .Indexes "Comparable"
188188
return Compare{{.Len}}C(host, guest).LT()
189189
}
190190

191-
// LessOrEqual{{.Len}} returns whether the host tuple is semantically less than the guest tuple.
191+
// LessOrEqual{{.Len}} returns whether the host tuple is semantically less than or equal to the guest tuple.
192192
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
193193
// To compare tuples that hold custom comparable values, use the LessOrEqual{{.Len}}C function.
194194
func LessOrEqual{{.Len}}[{{genericTypesDecl .Indexes "constraints.Ordered"}}](host, guest T{{.Len}}[{{.GenericTypesForward}}]) bool {
195195
return Compare{{.Len}}(host, guest).LE()
196196
}
197197

198-
// LessOrEqual{{.Len}}C returns whether the host tuple is semantically less than the guest tuple.
198+
// LessOrEqual{{.Len}}C returns whether the host tuple is semantically less than or equal to the guest tuple.
199199
// All tuple elements of the host and guest parameters must match the Comparable constraint.
200200
// To compare tuples that hold built-in "Ordered" values, use the LessOrEqual{{.Len}} function.
201201
func LessOrEqual{{.Len}}C[{{genericTypesDeclGenericConstraint .Indexes "Comparable"}}](host, guest T{{.Len}}[{{.GenericTypesForward}}]) bool {
202202
return Compare{{.Len}}C(host, guest).LE()
203203
}
204204

205-
// GreaterThan{{.Len}} returns whether the host tuple is semantically less than the guest tuple.
205+
// GreaterThan{{.Len}} returns whether the host tuple is semantically greater than the guest tuple.
206206
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
207207
// To compare tuples that hold custom comparable values, use the GreaterThan{{.Len}}C function.
208208
func GreaterThan{{.Len}}[{{genericTypesDecl .Indexes "constraints.Ordered"}}](host, guest T{{.Len}}[{{.GenericTypesForward}}]) bool {
209209
return Compare{{.Len}}(host, guest).GT()
210210
}
211211

212-
// GreaterThan{{.Len}}C returns whether the host tuple is semantically less than the guest tuple.
212+
// GreaterThan{{.Len}}C returns whether the host tuple is semantically greater than the guest tuple.
213213
// All tuple elements of the host and guest parameters must match the Comparable constraint.
214214
// To compare tuples that hold built-in "Ordered" values, use the GreaterThan{{.Len}} function.
215215
func GreaterThan{{.Len}}C[{{genericTypesDeclGenericConstraint .Indexes "Comparable"}}](host, guest T{{.Len}}[{{.GenericTypesForward}}]) bool {
216216
return Compare{{.Len}}C(host, guest).GT()
217217
}
218218

219-
// GreaterOrEqual{{.Len}} returns whether the host tuple is semantically less than the guest tuple.
219+
// GreaterOrEqual{{.Len}} returns whether the host tuple is semantically greater than or equal to the guest tuple.
220220
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
221221
// To compare tuples that hold custom comparable values, use the GreaterOrEqual{{.Len}}C function.
222222
func GreaterOrEqual{{.Len}}[{{genericTypesDecl .Indexes "constraints.Ordered"}}](host, guest T{{.Len}}[{{.GenericTypesForward}}]) bool {
223223
return Compare{{.Len}}(host, guest).GE()
224224
}
225225

226-
// GreaterOrEqual{{.Len}}C returns whether the host tuple is semantically less than the guest tuple.
226+
// GreaterOrEqual{{.Len}}C returns whether the host tuple is semantically greater than or equal to the guest tuple.
227227
// All tuple elements of the host and guest parameters must match the Comparable constraint.
228228
// To compare tuples that hold built-in "Ordered" values, use the GreaterOrEqual{{.Len}} function.
229229
func GreaterOrEqual{{.Len}}C[{{genericTypesDeclGenericConstraint .Indexes "Comparable"}}](host, guest T{{.Len}}[{{.GenericTypesForward}}]) bool {

tuple1.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,42 +153,42 @@ func LessThan1C[Ty1 Comparable[Ty1]](host, guest T1[Ty1]) bool {
153153
return Compare1C(host, guest).LT()
154154
}
155155

156-
// LessOrEqual1 returns whether the host tuple is semantically less than the guest tuple.
156+
// LessOrEqual1 returns whether the host tuple is semantically less than or equal to the guest tuple.
157157
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
158158
// To compare tuples that hold custom comparable values, use the LessOrEqual1C function.
159159
func LessOrEqual1[Ty1 constraints.Ordered](host, guest T1[Ty1]) bool {
160160
return Compare1(host, guest).LE()
161161
}
162162

163-
// LessOrEqual1C returns whether the host tuple is semantically less than the guest tuple.
163+
// LessOrEqual1C returns whether the host tuple is semantically less than or equal to the guest tuple.
164164
// All tuple elements of the host and guest parameters must match the Comparable constraint.
165165
// To compare tuples that hold built-in "Ordered" values, use the LessOrEqual1 function.
166166
func LessOrEqual1C[Ty1 Comparable[Ty1]](host, guest T1[Ty1]) bool {
167167
return Compare1C(host, guest).LE()
168168
}
169169

170-
// GreaterThan1 returns whether the host tuple is semantically less than the guest tuple.
170+
// GreaterThan1 returns whether the host tuple is semantically greater than the guest tuple.
171171
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
172172
// To compare tuples that hold custom comparable values, use the GreaterThan1C function.
173173
func GreaterThan1[Ty1 constraints.Ordered](host, guest T1[Ty1]) bool {
174174
return Compare1(host, guest).GT()
175175
}
176176

177-
// GreaterThan1C returns whether the host tuple is semantically less than the guest tuple.
177+
// GreaterThan1C returns whether the host tuple is semantically greater than the guest tuple.
178178
// All tuple elements of the host and guest parameters must match the Comparable constraint.
179179
// To compare tuples that hold built-in "Ordered" values, use the GreaterThan1 function.
180180
func GreaterThan1C[Ty1 Comparable[Ty1]](host, guest T1[Ty1]) bool {
181181
return Compare1C(host, guest).GT()
182182
}
183183

184-
// GreaterOrEqual1 returns whether the host tuple is semantically less than the guest tuple.
184+
// GreaterOrEqual1 returns whether the host tuple is semantically greater than or equal to the guest tuple.
185185
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
186186
// To compare tuples that hold custom comparable values, use the GreaterOrEqual1C function.
187187
func GreaterOrEqual1[Ty1 constraints.Ordered](host, guest T1[Ty1]) bool {
188188
return Compare1(host, guest).GE()
189189
}
190190

191-
// GreaterOrEqual1C returns whether the host tuple is semantically less than the guest tuple.
191+
// GreaterOrEqual1C returns whether the host tuple is semantically greater than or equal to the guest tuple.
192192
// All tuple elements of the host and guest parameters must match the Comparable constraint.
193193
// To compare tuples that hold built-in "Ordered" values, use the GreaterOrEqual1 function.
194194
func GreaterOrEqual1C[Ty1 Comparable[Ty1]](host, guest T1[Ty1]) bool {

tuple2.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,42 +169,42 @@ func LessThan2C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2]](host, guest T2[Ty1, Ty
169169
return Compare2C(host, guest).LT()
170170
}
171171

172-
// LessOrEqual2 returns whether the host tuple is semantically less than the guest tuple.
172+
// LessOrEqual2 returns whether the host tuple is semantically less than or equal to the guest tuple.
173173
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
174174
// To compare tuples that hold custom comparable values, use the LessOrEqual2C function.
175175
func LessOrEqual2[Ty1, Ty2 constraints.Ordered](host, guest T2[Ty1, Ty2]) bool {
176176
return Compare2(host, guest).LE()
177177
}
178178

179-
// LessOrEqual2C returns whether the host tuple is semantically less than the guest tuple.
179+
// LessOrEqual2C returns whether the host tuple is semantically less than or equal to the guest tuple.
180180
// All tuple elements of the host and guest parameters must match the Comparable constraint.
181181
// To compare tuples that hold built-in "Ordered" values, use the LessOrEqual2 function.
182182
func LessOrEqual2C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2]](host, guest T2[Ty1, Ty2]) bool {
183183
return Compare2C(host, guest).LE()
184184
}
185185

186-
// GreaterThan2 returns whether the host tuple is semantically less than the guest tuple.
186+
// GreaterThan2 returns whether the host tuple is semantically greater than the guest tuple.
187187
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
188188
// To compare tuples that hold custom comparable values, use the GreaterThan2C function.
189189
func GreaterThan2[Ty1, Ty2 constraints.Ordered](host, guest T2[Ty1, Ty2]) bool {
190190
return Compare2(host, guest).GT()
191191
}
192192

193-
// GreaterThan2C returns whether the host tuple is semantically less than the guest tuple.
193+
// GreaterThan2C returns whether the host tuple is semantically greater than the guest tuple.
194194
// All tuple elements of the host and guest parameters must match the Comparable constraint.
195195
// To compare tuples that hold built-in "Ordered" values, use the GreaterThan2 function.
196196
func GreaterThan2C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2]](host, guest T2[Ty1, Ty2]) bool {
197197
return Compare2C(host, guest).GT()
198198
}
199199

200-
// GreaterOrEqual2 returns whether the host tuple is semantically less than the guest tuple.
200+
// GreaterOrEqual2 returns whether the host tuple is semantically greater than or equal to the guest tuple.
201201
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
202202
// To compare tuples that hold custom comparable values, use the GreaterOrEqual2C function.
203203
func GreaterOrEqual2[Ty1, Ty2 constraints.Ordered](host, guest T2[Ty1, Ty2]) bool {
204204
return Compare2(host, guest).GE()
205205
}
206206

207-
// GreaterOrEqual2C returns whether the host tuple is semantically less than the guest tuple.
207+
// GreaterOrEqual2C returns whether the host tuple is semantically greater than or equal to the guest tuple.
208208
// All tuple elements of the host and guest parameters must match the Comparable constraint.
209209
// To compare tuples that hold built-in "Ordered" values, use the GreaterOrEqual2 function.
210210
func GreaterOrEqual2C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2]](host, guest T2[Ty1, Ty2]) bool {

tuple3.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,42 +185,42 @@ func LessThan3C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2], Ty3 Comparable[Ty3]](h
185185
return Compare3C(host, guest).LT()
186186
}
187187

188-
// LessOrEqual3 returns whether the host tuple is semantically less than the guest tuple.
188+
// LessOrEqual3 returns whether the host tuple is semantically less than or equal to the guest tuple.
189189
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
190190
// To compare tuples that hold custom comparable values, use the LessOrEqual3C function.
191191
func LessOrEqual3[Ty1, Ty2, Ty3 constraints.Ordered](host, guest T3[Ty1, Ty2, Ty3]) bool {
192192
return Compare3(host, guest).LE()
193193
}
194194

195-
// LessOrEqual3C returns whether the host tuple is semantically less than the guest tuple.
195+
// LessOrEqual3C returns whether the host tuple is semantically less than or equal to the guest tuple.
196196
// All tuple elements of the host and guest parameters must match the Comparable constraint.
197197
// To compare tuples that hold built-in "Ordered" values, use the LessOrEqual3 function.
198198
func LessOrEqual3C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2], Ty3 Comparable[Ty3]](host, guest T3[Ty1, Ty2, Ty3]) bool {
199199
return Compare3C(host, guest).LE()
200200
}
201201

202-
// GreaterThan3 returns whether the host tuple is semantically less than the guest tuple.
202+
// GreaterThan3 returns whether the host tuple is semantically greater than the guest tuple.
203203
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
204204
// To compare tuples that hold custom comparable values, use the GreaterThan3C function.
205205
func GreaterThan3[Ty1, Ty2, Ty3 constraints.Ordered](host, guest T3[Ty1, Ty2, Ty3]) bool {
206206
return Compare3(host, guest).GT()
207207
}
208208

209-
// GreaterThan3C returns whether the host tuple is semantically less than the guest tuple.
209+
// GreaterThan3C returns whether the host tuple is semantically greater than the guest tuple.
210210
// All tuple elements of the host and guest parameters must match the Comparable constraint.
211211
// To compare tuples that hold built-in "Ordered" values, use the GreaterThan3 function.
212212
func GreaterThan3C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2], Ty3 Comparable[Ty3]](host, guest T3[Ty1, Ty2, Ty3]) bool {
213213
return Compare3C(host, guest).GT()
214214
}
215215

216-
// GreaterOrEqual3 returns whether the host tuple is semantically less than the guest tuple.
216+
// GreaterOrEqual3 returns whether the host tuple is semantically greater than or equal to the guest tuple.
217217
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
218218
// To compare tuples that hold custom comparable values, use the GreaterOrEqual3C function.
219219
func GreaterOrEqual3[Ty1, Ty2, Ty3 constraints.Ordered](host, guest T3[Ty1, Ty2, Ty3]) bool {
220220
return Compare3(host, guest).GE()
221221
}
222222

223-
// GreaterOrEqual3C returns whether the host tuple is semantically less than the guest tuple.
223+
// GreaterOrEqual3C returns whether the host tuple is semantically greater than or equal to the guest tuple.
224224
// All tuple elements of the host and guest parameters must match the Comparable constraint.
225225
// To compare tuples that hold built-in "Ordered" values, use the GreaterOrEqual3 function.
226226
func GreaterOrEqual3C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2], Ty3 Comparable[Ty3]](host, guest T3[Ty1, Ty2, Ty3]) bool {

tuple4.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,42 +201,42 @@ func LessThan4C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2], Ty3 Comparable[Ty3], T
201201
return Compare4C(host, guest).LT()
202202
}
203203

204-
// LessOrEqual4 returns whether the host tuple is semantically less than the guest tuple.
204+
// LessOrEqual4 returns whether the host tuple is semantically less than or equal to the guest tuple.
205205
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
206206
// To compare tuples that hold custom comparable values, use the LessOrEqual4C function.
207207
func LessOrEqual4[Ty1, Ty2, Ty3, Ty4 constraints.Ordered](host, guest T4[Ty1, Ty2, Ty3, Ty4]) bool {
208208
return Compare4(host, guest).LE()
209209
}
210210

211-
// LessOrEqual4C returns whether the host tuple is semantically less than the guest tuple.
211+
// LessOrEqual4C returns whether the host tuple is semantically less than or equal to the guest tuple.
212212
// All tuple elements of the host and guest parameters must match the Comparable constraint.
213213
// To compare tuples that hold built-in "Ordered" values, use the LessOrEqual4 function.
214214
func LessOrEqual4C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2], Ty3 Comparable[Ty3], Ty4 Comparable[Ty4]](host, guest T4[Ty1, Ty2, Ty3, Ty4]) bool {
215215
return Compare4C(host, guest).LE()
216216
}
217217

218-
// GreaterThan4 returns whether the host tuple is semantically less than the guest tuple.
218+
// GreaterThan4 returns whether the host tuple is semantically greater than the guest tuple.
219219
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
220220
// To compare tuples that hold custom comparable values, use the GreaterThan4C function.
221221
func GreaterThan4[Ty1, Ty2, Ty3, Ty4 constraints.Ordered](host, guest T4[Ty1, Ty2, Ty3, Ty4]) bool {
222222
return Compare4(host, guest).GT()
223223
}
224224

225-
// GreaterThan4C returns whether the host tuple is semantically less than the guest tuple.
225+
// GreaterThan4C returns whether the host tuple is semantically greater than the guest tuple.
226226
// All tuple elements of the host and guest parameters must match the Comparable constraint.
227227
// To compare tuples that hold built-in "Ordered" values, use the GreaterThan4 function.
228228
func GreaterThan4C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2], Ty3 Comparable[Ty3], Ty4 Comparable[Ty4]](host, guest T4[Ty1, Ty2, Ty3, Ty4]) bool {
229229
return Compare4C(host, guest).GT()
230230
}
231231

232-
// GreaterOrEqual4 returns whether the host tuple is semantically less than the guest tuple.
232+
// GreaterOrEqual4 returns whether the host tuple is semantically greater than or equal to the guest tuple.
233233
// All tuple elements of the host and guest parameters must match the "Ordered" constraint.
234234
// To compare tuples that hold custom comparable values, use the GreaterOrEqual4C function.
235235
func GreaterOrEqual4[Ty1, Ty2, Ty3, Ty4 constraints.Ordered](host, guest T4[Ty1, Ty2, Ty3, Ty4]) bool {
236236
return Compare4(host, guest).GE()
237237
}
238238

239-
// GreaterOrEqual4C returns whether the host tuple is semantically less than the guest tuple.
239+
// GreaterOrEqual4C returns whether the host tuple is semantically greater than or equal to the guest tuple.
240240
// All tuple elements of the host and guest parameters must match the Comparable constraint.
241241
// To compare tuples that hold built-in "Ordered" values, use the GreaterOrEqual4 function.
242242
func GreaterOrEqual4C[Ty1 Comparable[Ty1], Ty2 Comparable[Ty2], Ty3 Comparable[Ty3], Ty4 Comparable[Ty4]](host, guest T4[Ty1, Ty2, Ty3, Ty4]) bool {

0 commit comments

Comments
 (0)