-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any plans to add support for Go 1.23's iterators? #525
Comments
As an example, //go:build go1.23
package iter
// IndexOf returns the index at which the first occurrence of a value is found in a sequence or return -1
// if the value cannot be found.
func IndexOf[T comparable](delegate func(func(T) bool), element T) int {
index := 0
for item := range delegate {
if item == element {
return index
}
index++
}
return -1
} (The build constraint will make sure this file is only compiled for folks using Go 1.23 or higher). |
See #528 |
FWIW, I have written a few of these also, and would be happy to contribute: |
I also did some benchmarking, and found that when chaining a few operations (like a couple I was honestly a little surprised the performance improvement wasn't greater. |
FWIW, I've produced https://github.com/jub0bs/iterutil:
|
Have you benchmarked heap allocations too? I expect a big difference, esp. for long combinator chains. |
I think if we import iter.Seq/iter.Seq2, the implement may be easy, but the performance for inplace operations like Reverse, Replace should drop a lot |
Hi there! You're probably aware that Go 1.23 added support for iterators to the standard library with
iter.Seq
. Many of the features of this library could be adapted to natively support range over functions.I'd even be happy to work on this feature set. I main go-functional, which is exactly what I described above so many of the iterators from go-functional could be copied over with little modification to support an iter subpackage in this repo for example.
It would support beheaviour like this from go-functional:
The text was updated successfully, but these errors were encountered: