-
-
Notifications
You must be signed in to change notification settings - Fork 853
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
feat: range-over-func POC #439
base: master
Are you sure you want to change the base?
Conversation
Probably worth thinking about if/how this would integrate with the new iter package in the stdlib. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm considering a new "iter" subpackage.
samber/lo is widely used and upgrading to Go 1.22 seems rough.
I think we can keep the same naming for every helpers, but under samber/lo/iter.
WDYT ?
|
||
// MapI transforms an iterator into an iterator of another type. | ||
// Play: https://go.dev/play/p/TODO | ||
func MapI[T any, R any](iter Iterator[T], iteratee func(item T, index int) R) Iterator[R] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we should receive and return iterators.
type Iterator[V any] func(func(int, V) bool) | ||
|
||
// ToIterator TODO | ||
func ToIterator[V any](collection ...V) Iterator[V] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToIterator
might already be implemented in the go standard library as slices.All
.
As per this comment: gomoni/it#12 (comment)
I was surprised to see no mention of the upcoming range-over-func experimental feature in the issues/PR list. I haven't measured anything but in theory this feature could dramatically reduce slice allocations when composing "queries" over large collections since no intermediate slices need to be created.
Is there any interest in this? This POC PR demonstrates what iterator support might look like, including tests and examples. I went with an "I" suffix (to mirror the "F" convention) to differentiate the iterator functions from their
slice.go
counterparts.For example: