github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/cols/synclist/iterator.go (about)

     1  package synclist
     2  
     3  // Iterator is an iterator over the elements in a List.
     4  type Iterator[T any] struct {
     5  	curr *Node[T]
     6  }
     7  
     8  // Valid returns true if the iterator is positioned at a valid element.
     9  func (it *Iterator[T]) Valid() bool {
    10  	return it.curr != nil
    11  }
    12  
    13  // Move moves the iterator to the next element.
    14  func (it *Iterator[T]) Move() {
    15  	if it.curr == nil {
    16  		return
    17  	}
    18  
    19  	it.curr = it.curr.next
    20  }
    21  
    22  // Get returns the element at the current position.
    23  func (it *Iterator[T]) Get() T {
    24  	return it.curr.Value
    25  }