1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build !go1.12
6
7package impl
8
9import "reflect"
10
11type mapIter struct {
12	v    reflect.Value
13	keys []reflect.Value
14}
15
16// mapRange provides a less-efficient equivalent to
17// the Go 1.12 reflect.Value.MapRange method.
18func mapRange(v reflect.Value) *mapIter {
19	return &mapIter{v: v}
20}
21
22func (i *mapIter) Next() bool {
23	if i.keys == nil {
24		i.keys = i.v.MapKeys()
25	} else {
26		i.keys = i.keys[1:]
27	}
28	return len(i.keys) > 0
29}
30
31func (i *mapIter) Key() reflect.Value {
32	return i.keys[0]
33}
34
35func (i *mapIter) Value() reflect.Value {
36	return i.v.MapIndex(i.keys[0])
37}
38