Latest 0.0.1
License MIT
Platforms ios 9.0, osx 10.10

This library provides a product function that creates a lazy cartesian product.

For instance:

let sequence = product(["a", "b"], ["c", "d"])
sequence.forEach { tuple in

// prints
("a", "c")
("a", "d")
("b", "c")
("b", "d")

Note that in the example above, sequence is a CartesianProduct2Sequence<Array<String>, Array<String>> and not a Array<(String, String)>. Meaning that sequence has not computed all the values of the product of both arrays upfront.

You can pass up to 15 parameters to the product function (even if that may not be such a good idea).


Using Cocoapods:

Simply add the following line to your Podfile:

pod 'CartesianProduct'

Using Swift Package Manager:

To include CartesianProduct into a Swift Package Manager package, add it to the dependencies attribute defined in your Package.swift file.

dependencies: [
    .Package(url: "", majorVersion: <majorVersion>, minor: <minor>)

Generated content

The CartesianProduct.swift file is generated with GYB.

You can download GYB like so:

chmod +x gyb

Then use make generate.

Running the tests

Run make test.


  • Pierre Felgines Blog


This project is licensed under the MIT License – see the LICENSE file for details


Latest podspec

    "name": "CartesianProduct",
    "version": "0.0.1",
    "summary": "Swift lazy cartesian product generator",
    "homepage": "",
    "license": {
        "type": "MIT"
    "authors": "Pierre Felgines",
    "social_media_url": "",
    "source": {
        "git": "",
        "tag": "v0.0.1"
    "source_files": "Sources/**/*.swift",
    "swift_version": "4.2",
    "platforms": {
        "ios": "9.0",
        "osx": "10.10"

Pin It on Pinterest

Share This