Erlang lists:index_of function?

后端 未结 6 1984
臣服心动
臣服心动 2020-12-10 01:58

I\'m looking for an Erlang library function that will return the index of a particular element in a list.

So, if

<         


        
6条回答
  •  感动是毒
    2020-12-10 02:44

    The following function returns a list of indices of a given element in a list. Result can be used to get the index of the first or last occurrence of a duplicate element in a list.

    indices_of(Element, L) ->                                                                                                                                                          
        Indices = lists:zip(lists:seq(1,length(L)), L),                                                                                                                                
        [ I || {I, E} <- Indices, E == Element ].   
    

提交回复
热议问题