github.com/wfusion/gofusion@v1.1.14/common/utils/clone/mapiter.go (about) 1 // Copyright 2019 Huan Du. All rights reserved. 2 // Licensed under the MIT license that can be found in the LICENSE file. 3 4 // +build !go1.12 5 6 package clone 7 8 import ( 9 "reflect" 10 ) 11 12 type iter struct { 13 m reflect.Value 14 k reflect.Value 15 keys []reflect.Value 16 } 17 18 func mapIter(m reflect.Value) *iter { 19 return &iter{ 20 m: m, 21 keys: m.MapKeys(), 22 } 23 } 24 25 func (it *iter) Next() bool { 26 if len(it.keys) == 0 { 27 return false 28 } 29 30 it.k = it.keys[0] 31 it.keys = it.keys[1:] 32 return true 33 } 34 35 func (it *iter) Key() reflect.Value { 36 return it.k 37 } 38 39 func (it *iter) Value() reflect.Value { 40 return it.m.MapIndex(it.k) 41 }