scala-library-next icon indicating copy to clipboard operation
scala-library-next copied to clipboard

Add mapWithIndex

Open BalmungSan opened this issue 4 years ago • 0 comments

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.

BalmungSan avatar Apr 09 '21 18:04 BalmungSan