Skip to content

Latest commit

 

History

History
36 lines (31 loc) · 741 Bytes

README.md

File metadata and controls

36 lines (31 loc) · 741 Bytes

SwiftProductGenerator

A generic cartesian product generator written in swift similar to Python's itertools.Product.

Mission

Reduce memory consumption and processing time for cartesian product of arbitrary collections.

Usage

The generator is initialized with an array containing the collections to be combined:

let arrays = [
  [0,1],
  [0,1],
  [0,1]
]

let generator = product(arrays)

An equivalent statement would be:

let generator = product(repeating: [0,1], count: 3)

The generator from the examples will generate this array lazily

[
  [0, 0, 0]
  [0, 0, 1]
  [0, 1, 0]
  [0, 1, 1]
  [1, 0, 0]
  [1, 0, 1]
  [1, 1, 0]
  [1, 1, 1]
]