Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

People also ask

How do you check if an element is in a list in Erlang?

use List::Util 'first'; print "ok\n" if first {$_ eq $x} @list; grep() will find all the elements that match... in a large list this may waste time. first() will return true as soon as the element is found.

Is Erlang a list?

In Erlang, Lists are created by enclosing the values in square brackets. Following is a simple example of creating a list of numbers in Erlang.

What is Proplist?

The proplist, sometimes called the “opaque” is a persistent way of storing information between invocations to the callback. The create callback can return the proplist (an array of tuples) and will get it sent back on the next invocation.


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 structures in erlang like dict, orddict, List, tuples, tree, queue etc to use for cache program.

Example:

List = [{"A1",["ankit","sush", "Hover", "x4", "a3","nilesh","mike","erlang" | ...]}|...].

Now, I want to search for the Key A1 and search for 'mike' in the list. What is the best way to search the above List.

Please provide some examples. Atleast Pseudo for it.