How to Search for an item in a List in Erlang?

后端 未结 7 1832
抹茶落季
抹茶落季 2021-01-04 07:56

I am writing a cache gen-server for the company Use. I am wondering how to search an item from the list as I want the cost of the search for comparing various data structure

7条回答
  •  温柔的废话
    2021-01-04 08:20

    Use keyfind function from lists module. For example:

    30> List = [{"A1",["ankit","sush", "Hover", "x4", "a3","nilesh","mike","erlang"]}].
    [{"A1",
      ["ankit","sush","Hover","x4","a3","nilesh","mike",
       "erlang"]}]
    31> lists:keyfind("A1", 1, List).
    {"A1",
     ["ankit","sush","Hover","x4","a3","nilesh","mike","erlang"]}
    

提交回复
热议问题