#Part 2

class CartesianProduct
  include Enumerable
  
  def initialize(p1, p2) 
    @first = p1
    @second = p2
  end
  
  def each
    @first.each do |part1|
      @second.each do |part2|
        yield[part1, part2]
      end
    end
  end
end

c = CartesianProduct.new([:a,:b], [4,5])
c.each { |elt| puts elt.inspect }
# [:a, 4]
# [:a, 5]
# [:b, 4]
# [:b, 5]

c = CartesianProduct.new([:a,:b], [])
c.each { |elt| puts elt.inspect }
# (nothing printed since Cartesian product
# of anything with an empty collection is empty)