-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
59 lines (48 loc) · 1.52 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Copyright (c) 2022-present, Serhat Şevki Dinçer.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Package types defines constraint type sets for Go Generics.
package types
// Complex is the set of complex number types.
type Complex interface {
~complex64 | ~complex128
}
// Float is the set of IEEE-754 floating-point types.
type Float interface {
~float32 | ~float64
}
// Signed is the set of signed integer types.
type Signed interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}
// Unsigned is the set of unsigned integer types.
type Unsigned interface {
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
// Integer is the set of integer types.
type Integer interface {
Signed | Unsigned
}
// Stringy is the set of string-like types.
type Stringy interface {
~string | ~[]byte
}
// HaveCap is the set of types that have dynamic capacity accessed with cap().
type HaveCap[T any] interface {
~[]T | ~chan T | ~<-chan T | ~chan<- T
}
// HaveLen is the set of types that have dynamic length accessed with len().
type HaveLen[T any, K comparable] interface {
HaveCap[T] | ~string | ~map[K]T
}
// HaveLess is the set of types that implement Less(T) method
type HaveLess[T any] interface {
Less(T) bool // strict comparison like < or >
}
// HaveLessPtr is the set of pointer types that implement (*T).Less(*T) method
type HaveLessPtr[T any, P *T] interface {
*T
HaveLess[P]
}