`EnumerableOperator#product *`

`factors``EnumerableOperator#tuples *`

`factors`

Returns an `Enumerable`

object which iterates over the Cartesian
product of the factors, each of which must be `Enumerable`

. Only the
current tuple of the sequence is kept in memory.

`EnumerableOperator#sum *`

`factors``EnumerableOperator#sum *`

`cat``EnumerableOperator#sum *`

`concatenation`

Returns an `Enumerable`

object which iterates over the concatenation
of the factors, each of which must be `Enumerable`

. Only the current
element of the sequence is kept in memory.

`EnumerableOperator#diagonal *`

`factors`

Returns an `Enumerable`

object which iterates over the diagonal of the
Cartesian product of the factors, each of which must be `Enumerable`

.
In other words, the n-th entry is a array of the n-th entries of each
factor. The resulting sequence terminates when any one factor terminates.
Hence the sequence has the same length as the shortest factor.

Each factor is converted to an array, if necessary, before iteration
begins. Internally, `diagonal`

does not enumerate the sequences in
parallel, but in the order given. If the sequences have side-effects of
enumeration, this may result in different behavior than if the sequences
were truly enumerated in parallel (e.g., see matz's approach using threads
in the Ruby FAQ:
http://www.rubycentral.com/faq/rubyfaq-5.html#ss5.5
).

include EnumerableOperator diagonal enum0, enum1, ...

or

EnumerableOperator.diagonal enum0, enum1, ...

and similarly for product and sum.

require 'enum/op' include EnumerableOperator for i, j in product 1..3, "bar".."baz" printf "%6s", i.to_s + j; puts if j == "baz" end puts for i in sum 1..5, 'a'..'c', 90..92 printf "%4s", i.to_s end puts "\n\n" for i, j, k in diagonal 1..4, 'a'..'d', ?a..?d printf "%4d. %s is 0x%x\n", i, j, k end

Enumerable tools 1.1

The current version of this software can be found at http://redshift.sourceforge.net/enum .

This software is distributed under the Ruby license. See http://www.ruby-lang.org.

Joel VanderWerf, vjoel@sourceforge.net