Module: Combinatorics::CartesianProduct::Mixin
Overview
Instance Method Summary collapse
-
#cartesian_product(*others) {|subset| ... } ⇒ Enumerator
(also: #cartprod, #cartesian)
Calculates the Cartesian product of an Enumerable object.
Instance Method Details
#cartesian_product(*others) {|subset| ... } ⇒ Enumerator Also known as: cartprod, cartesian
Calculates the Cartesian product of an Enumerable object.
46 47 48 49 50 51 52 53 |
# File 'lib/combinatorics/cartesian_product/mixin.rb', line 46 def cartesian_product(*others,&block) return enum_for(:cartesian_product,*others) unless block # a single empty Set will result in an empty Set return nil if (empty? || others.any?(&:empty?)) Array[self,*others].comprehension(&block) end |