-
Notifications
You must be signed in to change notification settings - Fork 0
/
range.go
40 lines (34 loc) · 925 Bytes
/
range.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
package grange
import "time"
type Integer interface {
int | int64 | int32 | int16
}
type Float interface {
float32 | float64
}
type Number interface {
Integer | Float
}
type NumberTime interface {
Number | time.Time
}
type RangeValue[K NumberTime] struct {
Value K
IsExclusive bool
}
type Range[K NumberTime] [2]RangeValue[K]
type RangeTypes interface {
RangeNumber[int] | RangeNumber[int16] | RangeNumber[int32] | RangeNumber[int64] | RangeNumber[float32] | RangeNumber[float64] | RangeTime
}
type RangeInterface[K RangeTypes] interface {
Intersection(K) *K
Difference(K) []K
IsEmpty() bool
ToPostgresString() (string, string, string) // return lowerBound, upperBound, inclusivity/exclusivity of bounds for postgres
}
func Intersection[K RangeTypes](t RangeInterface[K], t1 K) *K {
return t.Intersection(t1)
}
func Difference[K RangeTypes](t RangeInterface[K], t1 K) []K {
return t.Difference(t1)
}