Given a list of distinct items, I want to get a dictionary lookup
for each element's index in the list.
I can write this in normal code like the following:
//reference C# pseudocode
interface IThing
{
int Id {get;}
}
...
List<IThing> things = ...; // guaranteed not to have the same id more than once
...
Dictionary<int, int> lookup = new();
for (int i = 0; i < things.Count; ++i)
lookup[things[i].Id] = i;
I'm fairly sure this can be achieved using Linq or MoreLinq but I cannot think what it would be called to find the correct extension method. Does this algorithm have a particular name and is there something provided... the main issue being that most Linq methods do not tell you the index of the item?