-
Notifications
You must be signed in to change notification settings - Fork 1
/
sort.go
38 lines (30 loc) · 942 Bytes
/
sort.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
package form
// SortLookupCodeByLabel is a sort function that works with the sort.Slice
// function.
func SortLookupCodeByLabel(a LookupCode, b LookupCode) bool {
return a.Label < b.Label
}
// SortLookupCodeByGroupThenLabel is a sort function that works with the
// sort.Slice function.
func SortLookupCodeByGroupThenLabel(a LookupCode, b LookupCode) bool {
if a.Group < b.Group {
return true
}
if a.Group > b.Group {
return false
}
if a.Label < b.Label {
return true
}
return false
}
// LookupCodeMaker is an interface that wraps the LookupCode method
type LookupCodeMaker interface {
// LookupCode returns the data from current object in the form of a form.LookupCode
LookupCode() LookupCode
}
// AsLookupCode is a helper function that converts any object that implements
// the LookupCodeMaker interface into a form.LookupCode
func AsLookupCode[T LookupCodeMaker](maker T) LookupCode {
return maker.LookupCode()
}