Standard library / iter

iter.Seq2

A push iterator yielding pairs such as key/value or index/value. Stops when yield returns false. Expected stdout: '0 a\n1 b\n'.

Formal Syntax & Structure

go syntaxgo
type Seq2[K, V any] func(yield func(K, V) bool)

Working Example

Example Snippetgo
package main
import (  "fmt"  "iter")
func main() {  var seq iter.Seq2[int, string] = func(yield func(int, string) bool) {    for i, s := range []string{"a", "b"} {      if !yield(i, s) {        return      }    }  }  for i, s := range seq {    fmt.Println(i, s)  }}
Go Reference