...
1
2
3
4
5
6
7
8 package impl
9
10 import "reflect"
11
12 type mapIter struct {
13 v reflect.Value
14 keys []reflect.Value
15 }
16
17
18
19 func mapRange(v reflect.Value) *mapIter {
20 return &mapIter{v: v}
21 }
22
23 func (i *mapIter) Next() bool {
24 if i.keys == nil {
25 i.keys = i.v.MapKeys()
26 } else {
27 i.keys = i.keys[1:]
28 }
29 return len(i.keys) > 0
30 }
31
32 func (i *mapIter) Key() reflect.Value {
33 return i.keys[0]
34 }
35
36 func (i *mapIter) Value() reflect.Value {
37 return i.v.MapIndex(i.keys[0])
38 }
39
View as plain text