Search in record list

Richard Cameron camster@REDACTED
Fri Mar 17 15:23:36 CET 2006


On 17 Mar 2006, at 13:59, Inswitch Solutions wrote:

> Does someone know an easy way to search by a field of a record on a  
> list of records?
>
> For example:
>  [ {process_info, {Id, Pid, QueueLength}}...]
>
> Find the record with Pid element in the list.

You could deal with this example using list comprehensions:

[ R || R={process_info, {, PidX, _}} <- MyList, PidX==Pid ]

... although this example isn't actually a list of "records" as such.  
If you really did have a list of records (proper Erlang record with  
lots of # characters in the code to prove it) then you could say  
something like this:

[ R || R=#process_info{pid=PidX} <- MyList, PidX==Pid ]

Richard.



More information about the erlang-questions mailing list