Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NathanBaulch
Copy link

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:

iter := lo.ToIterator(1, 2, 3, 4)
result := lo.FilterI(iter, func(nbr int, index int) bool { return nbr%2 == 0 })
fmt.Printf("%v", result.Slice())

@NathanBaulch
Copy link
Author

Probably worth thinking about if/how this would integrate with the new iter package in the stdlib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant