[erlang-questions] performing lists:keysearch on a list of records

Dmitry Kolesnikov dmkolesnikov@REDACTED
Mon Nov 23 09:08:38 CET 2015


Hello,

You are on safe side with you approach.
Just use 

#Name.Field
The following expression returns the position of the specified field in the tuple representation of the record

as it is defined by
http://erlang.org/doc/reference_manual/records.html

Best Regards, 
Dmitry


> On Nov 23, 2015, at 10:00 AM, YuanZhiqian <on-your-mark@REDACTED> wrote:
> 
> Hi guys,
> 
>   Glad to meet everyone here. 
> 
>   I have a little question about the lists:keysearch function that I would like to search a record in a list by using one of its fields, because lists:keysearch is tuple-oriented and records is implemented internally as tuples, so I this the function should work as well to records, and it does as I tested in the shell. ( lists:keysearch(Key, 2, List), supposing the key is in the first field )
> 
>   However I wonder if there's any side effects in this behavior, since I was taught that never access records' fields directly in the way of treating tuples. 
> 
>   P.S. There's another question here, is there any difference between lists:keyfind/3 and lists:keysearch/3? I can tell any difference between them except for the return value's formats.
> 
> Mvh
> Zhiqian
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list