<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">There is some <i class="">historical</i><span style="font-style: normal;" class=""> context at play here, Karl.</span><div class="">Records (which are, in many occasions, the predecessors of maps) are tuples and therefore it’s not uncommon to find code that uses the functions listed by Vance to work with them. For instance…</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>find_user(UserName, Users) -></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>lists:keyfind(UserName, #user.username, Users).</div><div class=""><br class=""></div><div class="">If we move from records to maps as our means to implement users, then we need something like…</div><div class=""><br class=""></div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>find_user(UserName, Users) -></div><div class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>case lists:dropwhile(fun(#{username := UN}) -> UN =/= UserName end, Users) of</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>[] -> false;</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>[User|_] -> User</div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>end.</div></div><div class=""><br class=""></div><div class="">It would be <i class="">nice</i> if we don’t need to do that and instead can do…</div><div class=""><br class=""></div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>find_user(UserName, Users) -></div><div class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>lists:keyfind_for_maps(UserName, username, Users).</div></div><div class=""><br class=""></div><div class="">Hope this helps :)</div><div class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: 'Trebuchet MS'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><span id="docs-internal-guid-e691a4cc-056a-0210-b8b7-ea8d87d888ad" class=""><span style="font-size: 11pt; font-family: Arial; font-weight: 700; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;" class=""><br class="Apple-interchange-newline"><hr class=""></span></span><div class=""><b class=""><i class=""><a href="http://about.me/elbrujohalcon" class="">Brujo Benavides</a></i></b></div></div></div><div style="color: rgb(0, 0, 0); font-family: 'Trebuchet MS'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><b class=""><br class=""></b></div><br class="Apple-interchange-newline">
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On 23 Sep 2019, at 08:07, Karl Velicka <<a href="mailto:karolis.velicka@gmail.com" class="">karolis.velicka@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I'm afraid I can't see the equivalence in your example - I see a list of tuples as a list of values, whereas a list of maps is a list of containers. In my mind, a more apt comparison would be a list of maps vs a list of lists of tuples, and functions operating on the latter would strike me as an odd addition to stdlib.</div><div class=""><br class=""></div><div class="">I'd be curious to know what your usecase for these functions is. <br class=""></div><div class=""><br class=""></div><div class="">Some of them can be trivially implemented:</div><div class=""><br class=""></div><div class=""> keyfind(Key, MapList) -> hd(lists:filter(fun(Map) -> maps:is_key(Key, Map) end, MapList).</div><div class=""><br class=""></div><div class="">(The example implementation there is inefficient but I hope you get the idea)</div><div class=""><br class=""></div><div class="">Some others, like keysort(Key, MapList1) -> MapList2 don't quite make sense to me as the semantics are unclear.<br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I think elaborating on the use cases would help your proposal.</div><div class=""><br class=""></div><div class="">All the best,</div><div class="">Karl<br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 23 Sep 2019 at 09:00, Vance Shipley <<a href="mailto:vances@motivity.ca" class="">vances@motivity.ca</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Should we have a corollary to lists:keyfind/3 which works on lists of map()?<br class="">
<br class="">
keyfind(Key, MapList) -> Map | false<br class="">
<br class="">
... and the rest:<br class="">
<br class="">
keydelete(Key, MapList1) -> MapList2<br class="">
keymap(Fun, Key, MapList1) -> MapList2<br class="">
keymember(Key, MapList) -> boolean()<br class="">
keymerge(Key, MapList1, MapList2) -> MapList3<br class="">
keyreplace(Key, MapList1, NewMap) -> MapList2<br class="">
keysort(Key, MapList1) -> MapList2<br class="">
keystore(Key, MapList1, NewMap) -> MapList2<br class="">
keytake(Key, MapList1) -> {value, Map, MapList2} | false<br class="">
<br class="">
<br class="">
--<br class="">
-Vance<br class="">
_______________________________________________<br class="">
erlang-questions mailing list<br class="">
<a href="mailto:erlang-questions@erlang.org" target="_blank" class="">erlang-questions@erlang.org</a><br class="">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank" class="">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="">
</blockquote></div>
_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""></div></blockquote></div><br class=""></div></body></html>