view modules/inifile/lib/puppet/util/external_iterator.rb @ 478:adf6fe9bbc17

Update Puppet modules to latest versions
author IBBoard <dev@ibboard.co.uk>
date Thu, 29 Aug 2024 18:47:29 +0100
parents 3fce34f642f1
children
line wrap: on
line source

# frozen_string_literal: true

module Puppet::Util # rubocop:disable Style/ClassAndModuleChildren
  #
  # external_iterator.rb
  #
  class ExternalIterator
    def initialize(coll)
      @coll = coll
      @cur_index = -1
    end

    def next
      @cur_index += 1
      item_at(@cur_index)
    end

    def peek
      item_at(@cur_index + 1)
    end

    private

    def item_at(index)
      if @coll.length > index
        [@coll[index], index]
      else
        [nil, nil]
      end
    end
  end
end