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.
go get github.com/alexandreLamarre/ro@v0.1.0
This library requires you to enable the go experimental feature rangefunc :
export GOEXPERIMENT=rangefunc
You can import ro
using:
import (
"github.com/alexandreLamarre/ro"
)
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