
class Proc

  # Operator for Proc#compose and Integer#times_collect/of.
  #
  #  a = lambda { |x| x + 4 }
  #  b = lambda { |y| y / 2 }
  #
  #  (a * b).call(4)  #=> 6
  #  (b * a).call(4)  #=> 4
  #
  def *(x)
    if Integer===x
      # collect times
      a = []; x.times{|i| a << call(i)}; a
    else
      # compose procs
      proc{|*a| self[x[*a]]}
    end
  end

end


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

  require 'test/unit'

  class TCProc < Test::Unit::TestCase

    def test_compose_op
      a = lambda { |x| x + 4 }
      b = lambda { |y| y / 2 }
      assert_equal( 6, (a * b).call(4) )
      assert_equal( 4, (b * a).call(4) )
    end

    def test_times_collect_op
      a = lambda { |x| x + 4 }
      assert_equal( [4,5,6], a * 3 )
    end

  end

=end
