github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/iter/iterable.go (about)

     1  package iter
     2  
     3  // An Iterator is used to iterate through elements.
     4  // It fits well with the for-loop syntax.
     5  type Iterator[T any] interface {
     6  	// Valid returns true if the end has not been reached.
     7  	Valid() bool
     8  	// Move fetches the next element.
     9  	Move()
    10  	// Get returns the current element.
    11  	Get() T
    12  }
    13  
    14  // An Iterable is a finite or infinite collection of elements.
    15  // It can be iterated through using an Iterator.
    16  type Iterable[T any] interface {
    17  	// Iterator creates and returns a new Iterator.
    18  	Iterator() Iterator[T]
    19  }
    20  
    21  // A FiniteIterable is a finite collection of elements.
    22  // It can be iterated through using an Iterator.
    23  // Useful for passing to data structures constructors.
    24  type FiniteIterable[T any] interface {
    25  	Iterable[T]
    26  	// Size returns the number of elements in the collection.
    27  	Size() int
    28  }