[erlang-questions] performing lists:keysearch on a list of records
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.
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions