-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtypes.go
40 lines (33 loc) · 1.03 KB
/
types.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 collections
// Generic interface that all collections must implement.
type Collection[T CollectionElement] interface {
// Returns the type of the given collection.
Type() CollectionType
// Returns the size of the given collection.
Size() int
// Returns the description of the given collection.
String() string
}
// A Generic interface that must be implemented by collection elements.
// By default, all primitive types and structs containing primitive types implement this interface.
type CollectionElement interface {
Equatable
}
// Typed constant that helps in determining the collection type.
type CollectionType int
const (
TypeList CollectionType = 0
TypeSet CollectionType = 1
TypeHashmap CollectionType = 2
)
// Interface with comparable constraint (== & != operator supportable).
type Equatable interface {
comparable
}
// A Generic number interface that supports all basic number types.
type Number interface {
int64 | float64 | int32 | int16 | int8 | int | float32
}
type GenericType interface {
Number | string
}