/combinatoric

Go port of the combinatoric bits from python's itertools

Primary LanguageGoMIT LicenseMIT

Combinatoric Build Status Coverage Status Go Report Card

Combinatoric is a simple Go port of the "combinatoric" parts of Python's itertools--specifically, combinations, permutations, and product.

See godocs for more.

Installation

$ go get https://github.com/ecooper/combinatoric

Quickstart

package main

import (
    "fmt"
    "github.com/ecooper/combinatoric"
)

func main() {
    src := []interface{}{"A", "B", "C", "D"}

    // Create a new CombinationIterator of 2 elements using src
    iter, _ := combinatoric.Combinations(src, 2)

    // Print the length of the iterator
    fmt.Printf("Expecting %d combinations:\n", iter.Len())

    // Set c to the next combination until Next returns a nil slice.
    for c := iter.First(); c != nil; c = iter.Next() {
        fmt.Printf("%s\n", c)
    }

    // Restore the CombinationsIterator to its original state
    iter.Reset()
}

Usage

See godocs for more documentation and usage examples.