
module Enumerable

  # Iterators ovr each element pairing.
  #
  #   [:a,:b,:c,:d].each_pair { |a,b|  puts "#{a} -> #{b}" }
  #
  # _produces_
  #
  #   a -> b
  #   c -> d
  #
  def each_pair #:yield:
    e1 = nil
    each_with_index do |e,i|
      if i % 2 == 0
        e1 = e
        next
      else
        yield(e1,e)
      end
    end
  end

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCEnumerable < Test::Unit::TestCase

    def test_each_pair
      r = []
      a = [1,2,3,4]
      a.each_pair{ |a,b| r << [a,b] }
      assert_equal( [[1,2],[3,4]], r )
    end

  end

=end
