@@ -6,6 +6,17 @@ package reflect
6
6
7
7
import "iter"
8
8
9
+ func rangeNum [T int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr , N int64 | uint64 ](v N ) iter.Seq [Value ] {
10
+ return func (yield func (v Value ) bool ) {
11
+ // cannot use range T(v) because no core type.
12
+ for i := T (0 ); i < T (v ); i ++ {
13
+ if ! yield (ValueOf (i )) {
14
+ return
15
+ }
16
+ }
17
+ }
18
+ }
19
+
9
20
// Seq returns an iter.Seq[Value] that loops over the elements of v.
10
21
// If v's kind is Func, it must be a function that has no results and
11
22
// that takes a single argument of type func(T) bool for some type T.
@@ -22,22 +33,28 @@ func (v Value) Seq() iter.Seq[Value] {
22
33
}
23
34
}
24
35
switch v .Kind () {
25
- case Int , Int8 , Int16 , Int32 , Int64 :
26
- return func (yield func (Value ) bool ) {
27
- for i := range v .Int () {
28
- if ! yield (ValueOf (i )) {
29
- return
30
- }
31
- }
32
- }
33
- case Uint , Uint8 , Uint16 , Uint32 , Uint64 , Uintptr :
34
- return func (yield func (Value ) bool ) {
35
- for i := range v .Uint () {
36
- if ! yield (ValueOf (i )) {
37
- return
38
- }
39
- }
40
- }
36
+ case Int :
37
+ return rangeNum [int ](v .Int ())
38
+ case Int8 :
39
+ return rangeNum [int8 ](v .Int ())
40
+ case Int16 :
41
+ return rangeNum [int16 ](v .Int ())
42
+ case Int32 :
43
+ return rangeNum [int32 ](v .Int ())
44
+ case Int64 :
45
+ return rangeNum [int64 ](v .Int ())
46
+ case Uint :
47
+ return rangeNum [uint ](v .Uint ())
48
+ case Uint8 :
49
+ return rangeNum [uint8 ](v .Uint ())
50
+ case Uint16 :
51
+ return rangeNum [uint16 ](v .Uint ())
52
+ case Uint32 :
53
+ return rangeNum [uint32 ](v .Uint ())
54
+ case Uint64 :
55
+ return rangeNum [uint64 ](v .Uint ())
56
+ case Uintptr :
57
+ return rangeNum [uintptr ](v .Uint ())
41
58
case Pointer :
42
59
if v .Elem ().kind () != Array {
43
60
break
0 commit comments