[erlang-questions] lists module functions for maps?

Vance Shipley vances@REDACTED
Mon Sep 23 14:36:44 CEST 2019

On Mon, Sep 23, 2019 at 7:07 PM Karl Velicka <karolis.velicka@REDACTED> wrote:
> I'm afraid I can't see the equivalence in your example

Think small maps and big lists.

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

As Brujo suggests many use cases for lists:keyfind/3 et. al. deal with
lists of records. This is a very common pattern in our organization.
As we use maps more we naturally want to have the simple efficient
(BIF) implementation in the lists module.

One example is with JSON where we have an object which contains an
array of objects which we want to filter, sort, get, take, etc..

     1> #{id := Id, name := Name, characteristic := Chars} = zj:decode(Body),
     1> length(Chars).
     2> hd(Chars).
     #{id = 42, name = foo, type = bar, value = "hello"}.

Sure I can always write simple funs to handle these but we have
collected common patterns of operations on lists into the lists module
and made it very fast. It seems quite obvious to add support for the
new type of term which may be in those lists.


More information about the erlang-questions mailing list