Skip to content

Add mapWithIndex #78

@BalmungSan

Description

@BalmungSan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions