view modules/inifile/lib/puppet/util/external_iterator.rb @ 386:3fce34f642f1

Add a PHP module to handle platform differences
author IBBoard <dev@ibboard.co.uk>
date Mon, 03 Jan 2022 17:09:39 +0000
parents
children adf6fe9bbc17
line wrap: on
line source

# frozen_string_literal: true

module Puppet::Util
  #
  # 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