feat: [#50] Add support for Go1.23+ iterators#53
feat: [#50] Add support for Go1.23+ iterators#53Izzette wants to merge 2 commits intobenbjohnson:masterfrom
Conversation
|
I'd like to make add an I also need to add a test case for the yield function returning false. |
markuspeloquin
left a comment
There was a problem hiding this comment.
I have no association with this project. I was just thinking about using it until I saw it doesn't have proper iterators.
High level:
- Don't provide iterators for builders
- Rename AllWithIndex to All2, matching Seq2
- Remove the asserts (which I'm guessing you planned on doing anyway)
- Maybe also upgrade the version in go.mod (instead of coping the Seq/Seq2/Ordered interfaces), it's not like Go 1.22 is supported anymore
I also do wonder if a more direct version would be better, rather than an adapter over Iterator. Like copy it, take out the parts you don't need, and simplify it until it looks like Seq.
| // This can be used to perform range-like operations on the [iter.Seq] and inter-operate with other libraries using the Go 1.23 iterable function API. | ||
| // | ||
| // TODO(Izzette): could this use a better name? | ||
| func IndexedSeq[T any](it IndexedIterator[T]) Seq[T] { |
There was a problem hiding this comment.
It'd be nice if you didn't rely on interfaces for this for performance critical code. You can accomplish this with generics.
func IndexedSeq[T any, Iter indexedIterator[T]])(it Iter) Seq[T] {In this case, the indexedIterator interface is used a constraint.
See: https://pkg.go.dev/iter and https://go.dev/blog/range-functions
Resolves #50