<div dir="ltr"><div><div><div>lists:keyfind is faster and returns result directly instead of {value,Result}. <br><br></div>For records, you should use: lists:keyfind(Value,#myrecord.myelement, List).<br><br></div>Compiler will turn: #myrecord.myelement into a tuple position.<br><br><br></div>Sergej<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 23, 2015 at 9:00 AM, YuanZhiqian <span dir="ltr"><<a href="mailto:on-your-mark@hotmail.com" target="_blank">on-your-mark@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><div dir="ltr">Hi guys,<div><br></div><div>  Glad to meet everyone here. </div><div><br></div><div>  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 )</div><div><br></div><div>  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. </div><div><br></div><div>  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.</div><div><br></div><div>Mvh</div><div>Zhiqian</div>                                        </div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>