Reputation: 35
I have a list with elements that can have duplicates and i want to
map a function for example: map (\x -> f (5 + (elemIndex x l))) l
The problem is that if the list has duplicate elements elemIndex
returns the index of the first one. I want it to be the index of x
in l
,where x
is the current element.
I guess I am looking for a function to replace elemIndex
in my code
Upvotes: 1
Views: 202
Reputation: 33464
You can zip
your list with a list of indices before map
ping. There also is a shorthand zipWith
for zip
followed by map
.
zipWith (\i x -> f (5 + i)) [0 ..] l
Upvotes: 5