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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -