Standard library / reflect

reflect.Value.MapRange()

Creates an iterator that traverses map entries without constructing a slice of all keys. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) MapRange() *MapIter

Return Value

*MapIter

Creates an iterator that traverses map entries without constructing a slice of all keys.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  m := reflect.ValueOf(map[string]int{"a": 7})  it := m.MapRange()  total := int64(0)  for it.Next() {    total += it.Value().Int()  }  fmt.Println(total)}
Go Reference