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

Add mapWithIndex #78

Open
BalmungSan opened this issue Apr 9, 2021 · 0 comments
Open

Add mapWithIndex #78

BalmungSan opened this issue Apr 9, 2021 · 0 comments

Comments

@BalmungSan
Copy link
Contributor

BalmungSan commented Apr 9, 2021

I found myself doing this a lot:

someCollection.iterator.zipWithIndex.map { case (a, idx) => f(a, idx) }.to(SomeCollectionType)

Which is a little bit verbose just to avoid allocating the intermediate collection.
Additionally to the semantic improvement, since map is just a simple loop it is very easy to keep track of the index without any kind of overhead.

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

No branches or pull requests

1 participant