erlang list filter question -
i have list - sep1:
[ .... ["message-id", "aaaaaaaaaaaaaaaaaaa"], ["to", "bbbbbbbbbbbbbbbbb"] ... ]
i try element first item = message_id example:
lists:filter(fun(y) -> (lists:nth(1,lists:nth(1,y)) =:= "message-id") end, sep1).
but error:
exception error: no function clause matching lists:nth(1,[]) in function utils:'-parse_to/1-fun-1-'/1 in call lists:'-filter/2-lc$^0/1-0-'/2
but if i:
io:format(lists:nth(1,lists:nth(1,sep1))). > message-id
what's wrong?
thank you.
it's better change representation [{key, value}, ...]
can use lists:key* functions, proplists module, or convert dict dict:from_list/1.
but if still want use lists:filter/2 can filter list of lists first element following:
lists:filter(fun ([k | _]) -> k =:= "message-id" end, listoflists).
if want extract tails of lists first element match "message-id" can use list comprehensions:
[tail || ["message-id" | tail] <- listoflists].
Comments
Post a Comment