product: Create a cartesian product iterator

Description Usage Arguments Examples

Description

Create an iterator that returns values from multiple iterators in cartesian product fashion. That is, they are combined the manner of nested for loops.

Usage

1

Arguments

...

Named iterables to iterate over. The right-most iterables change more quickly, like an odometer.

Examples

1
2
3
4
5
6
# Simulate a doubly-nested loop with a single while loop
it <- ihasNext(product(a=1:3, b=1:2))
while (hasNext(it)) {
  x <- nextElem(it)
  cat(sprintf('a = %d, b = %d\n', x$a, x$b))
}

Example output

Loading required package: iterators
a = 1, b = 1
a = 1, b = 2
a = 2, b = 1
a = 2, b = 2
a = 3, b = 1
a = 3, b = 2

itertools documentation built on May 2, 2019, 2:26 p.m.