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

Sergej Jurečko sergej.jurecko@REDACTED
Mon Nov 23 09:07:38 CET 2015

lists:keyfind is faster and returns result directly instead of

For records, you should use: lists:keyfind(Value,#myrecord.myelement, List).

Compiler will turn: #myrecord.myelement into a tuple position.


On Mon, Nov 23, 2015 at 9:00 AM, YuanZhiqian <on-your-mark@REDACTED>

> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151123/46374280/attachment.htm>

More information about the erlang-questions mailing list