github.com/m4gshm/gollections@v0.0.10/break/kv/iface.go (about)

     1  // Package kv provides key/value types, functions
     2  package kv
     3  
     4  import "github.com/m4gshm/gollections/c"
     5  
     6  // Iterator provides iterate over key/value pairs, where an iteration can be interrupted by an error
     7  type Iterator[K, V any] interface {
     8  	// Next returns the next key/value pair.
     9  	// The ok result indicates whether the element was returned by the iterator.
    10  	// If ok == false, then the iteration must be completed.
    11  	Next() (key K, value V, ok bool, err error)
    12  	c.TrackLoop[K, V]
    13  }
    14  
    15  // IterFor extends an iterator type by a 'Start' function implementation
    16  type IterFor[K, V any, I Iterator[K, V]] interface {
    17  	// Start is used with for loop construct.
    18  	// Returns the iterator itself, the first key/value pair, ok == false if the iteration must be completed, and an error.
    19  	//
    20  	// 	var i IterFor = ...
    21  	//	for i, k, v, ok, err := i.Start(); ok || err != nil; k, v, ok, err = i.Next() {
    22  	//		if err != nil {
    23  	//			return err
    24  	//		}
    25  	//	}
    26  	Start() (iterator I, key K, value V, ok bool, err error)
    27  }