Skip to content

๐Ÿ˜Ž A generic iterator Go library based on Go 1.22+ rangefunc experiment, built for composability and readability

License

Notifications You must be signed in to change notification settings

alexandreLamarre/ro

Repository files navigation

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

About

๐Ÿ˜Ž A generic iterator Go library based on Go 1.22+ rangefunc experiment, built for composability and readability

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages