Standard library / reflect

reflect.MapIter.Reset()

Reuses an iterator for another map; an invalid Value detaches it from the previous map. Expected stdout: 'b\n'.

Formal Syntax & Structure

go syntaxgo
func (iter *MapIter) Reset(v Value)

Parameters & Attributes

NameTypeDescription
vValueValue to inspect or dereference.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  m := reflect.ValueOf(map[string]int{"a": 7})  it := m.MapRange()  it.Next()  it.Reset(reflect.ValueOf(map[string]int{"b": 8}))  it.Next()  fmt.Println(it.Key().String())}
Go Reference