/ro

😎 A generic iterator Go library based on Go 1.23+ rangefunc, built for composability and readability

Primary LanguageGoApache License 2.0Apache-2.0

ro

Go Version Release GoDoc Lint Test Coverage License

alexandreLamarre/ro (short for "range-over") is a generic iterator Go library based on Go 1.22+ rangefunc experiment.

The library is built for composability and readibility while providing similar functionality to other language's interator libraries such as itertools

This library is intended to be paired with samber/lo, where applicable.

🚀 Install

go get github.com/alexandreLamarre/ro@v0.1.0

✔️ Requirements

This library requires you to enable the go experimental feature rangefunc :

export GOEXPERIMENT=rangefunc

💡 Usage

You can import ro using:

import (
    "github.com/alexandreLamarre/ro"
)

👀 Example

it := ro.Drop(
    ro.Apply(
        ro.Limit(
            ro.Permutations(
                ro.ToSlice(
                    ro.Range(0, 6, 1),
                ),
                5,
            ),
            5,
        ),
        func(perm []int) int {
            return digitsToInt(perm)
        },
    ),
    func(i int) bool {
        return i > 10000
    },
)
for v := range it {
    fmt.Println(v)
}

yields the following output:

1234
2134

The above iterator yields all numbers < 10000 that are formed from the digits of the first 5 generated permutations of {0,1,2,3,4,5} of size 5