Standard library / iter
iter.Pull2()
Converts a pair sequence to next and stop functions. next yields two values and a validity flag. Stop on early exit; do not call next or stop concurrently. Expected stdout: '0 x true\n0 "" false\n'.
Formal Syntax & Structure
go syntaxgo
func Pull2[K, V any](seq Seq2[K, V]) (next func() (K, V, bool), stop func())Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| seq | Seq2[K, V] | Iterator function producing the input sequence. |
Return Value
(next func() (K, V, bool), stop func())
next retrieves two values and validity; stop terminates the iterator.
Working Example
Example Snippetgo
package main
import ( "fmt" "iter" "slices")
func main() { next, stop := iter.Pull2(slices.All([]string{"x"})) defer stop() i, v, ok := next() fmt.Println(i, v, ok) i, v, ok = next() fmt.Printf("%d %q %t\n", i, v, ok)}