[erlang-questions] lists module functions for maps?

Karl Velicka karolis.velicka@REDACTED
Mon Sep 23 13:07:19 CEST 2019


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.

I'd be curious to know what your usecase for these functions is.

Some of them can be trivially implemented:

keyfind(Key, MapList) -> hd(lists:filter(fun(Map) -> maps:is_key(Key, Map)
end, MapList).

(The example implementation there is inefficient but I hope you get the
idea)

Some others, like keysort(Key, MapList1) -> MapList2 don't quite make sense
to me as the semantics are unclear.


I think elaborating on the use cases would help your proposal.

All the best,
Karl

On Mon, 23 Sep 2019 at 09:00, Vance Shipley <vances@REDACTED> wrote:

> Should we have a corollary to lists:keyfind/3 which works on lists of
> map()?
>
>      keyfind(Key, MapList) -> Map | false
>
> ... and the rest:
>
>      keydelete(Key, MapList1) -> MapList2
>      keymap(Fun, Key, MapList1) -> MapList2
>      keymember(Key, MapList) -> boolean()
>      keymerge(Key, MapList1, MapList2) -> MapList3
>      keyreplace(Key, MapList1, NewMap) -> MapList2
>      keysort(Key, MapList1) -> MapList2
>      keystore(Key, MapList1, NewMap) -> MapList2
>      keytake(Key, MapList1) -> {value, Map, MapList2} | false
>
>
> --
>      -Vance
> _______________________________________________
> 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/20190923/884d8515/attachment.htm>


More information about the erlang-questions mailing list