Myke
Myke

Reputation: 281

How can I get the indexes of elements in a Haskell list

Is there any function in Haskell that returns the indexs of elements like elemIndex in a list. For example for the list [1,2,3,4,2,3], looking for 2 returns [1,4].

Upvotes: 2

Views: 126

Answers (1)

Mihai Maruseac
Mihai Maruseac

Reputation: 21425

You can always use Hoogle for this type of questions. Basically, you get the type of the function you're looking for -- in our case you have a list [a] and an a to search for and want a return of [Int] for the indices -- and just search for it (in your case, the first result, elemIndices, seems to work)

Upvotes: 7

Related Questions