Erlang lists:index_of function?

后端 未结 6 1983
臣服心动
臣服心动 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:36

    I think the writer makes a valid case. Here is my use case from a logging application. The objective is to check the severity of an error against the actions to be performed against various levels of error response.

    get_index(A,L) ->
        get_index(A,L,1).
    get_index(A,[A|_],N) ->
        N;
    get_index(A,[_|T],N) ->
        get_index(A,T,N+1).
    
    get_severity(A) ->
        Severity=[debug,info,warn,error],
        get_index(A,Severity).
    

提交回复
热议问题