scala-library-next
scala-library-next copied to clipboard
Add mapWithIndex
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.