github.com/hernad/nomad@v1.6.112/helper/iterator/iterator.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package iterator
     5  
     6  // Iterator represents an object that can iterate over a set of values one at a
     7  // time.
     8  type Iterator interface {
     9  	// Next returns the next element or nil if there are none left.
    10  	Next() any
    11  }
    12  
    13  // Len consumes the iterator and returns the number of elements found.
    14  //
    15  // IMPORTANT: this method consumes the iterator, so it should not be used after
    16  // Len() returns.
    17  func Len(iter Iterator) int {
    18  	count := 0
    19  	for raw := iter.Next(); raw != nil; raw = iter.Next() {
    20  		count++
    21  	}
    22  	return count
    23  }