# Proposal: adding ets:lookup\_element\_as\_list/3

**URL:** <https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743>\
**Category:** Proposals: Ideas\
**Tags:** erlang-otp\
**Created:** [August 16, 2022, 9:44am UTC](https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743 "2022-08-16T09:44:35Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![michalmuskala](https://erlangforums.com/user_avatar/erlangforums.com/michalmuskala/32/247_2.png) [@michalmuskala](https://erlangforums.com/u/michalmuskala)\
**Post date:** [August 25, 2022, 2:53pm UTC](https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743/21 "2022-08-25T14:53:26Z")

</div>

I’d say the core issue here is having 2 completely different data structures - a map (`set`, `ordered_set` types) and a multimap (`bag`, `duplicate_bag` types) sharing the same access API. Whatever we do, there’s going to be confusion because of this “original sin” of ETS.

---

<div class="post-metadata">

**Author:** ![Maria-12648430](https://erlangforums.com/user_avatar/erlangforums.com/maria-12648430/32/604_2.png) [@Maria-12648430](https://erlangforums.com/u/Maria-12648430)\
**Post date:** [August 25, 2022, 2:59pm UTC](https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743/22 "2022-08-25T14:59:20Z")

</div>

Yes, but we can’t do anything about _that_ now I guess 😉 All we can do now is not add more confusion (than necessary 😅).

---

<div class="post-metadata">

**Author:** ![RMorisset](https://erlangforums.com/user_avatar/erlangforums.com/rmorisset/32/1601_2.png) [@RMorisset](https://erlangforums.com/u/RMorisset)\
**Post date:** [August 25, 2022, 3:05pm UTC](https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743/23 "2022-08-25T15:05:19Z")

</div>

I agree that always returning a list is cleaner.

What convinced me to switch to an extra argument to lookup\_element is the precedent of `maps:get` and `proplists:get_value`.

But as a newcomer to Erlang, I’d be happy to implement whatever API the community prefer, whether that is `lookup_element_as_list/3`, `lookup_element/4` or something else. All that I care about is that it be performant whether the element is present or not and reasonably ergonomic.

---

<div class="post-metadata">

**Author:** ![LeonardB](https://erlangforums.com/user_avatar/erlangforums.com/leonardb/32/1856_2.png) [@LeonardB](https://erlangforums.com/u/LeonardB)\
**Post date:** [August 25, 2022, 4:41pm UTC](https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743/24 "2022-08-25T16:41:46Z")

</div>

Personally I prefer the default.

The structure/type if the table and contents being interrogated is a known entity when you’re using it.

If it’s not, something is off 😛

If I know it’s a bag, I can always specify an empty list as the default.

I, as the programmer, get to make the decision in the actual call, rather than having to wrap it up in a case or function should I actually want to just use the returned value.

Just my 2c.

---

<div class="post-metadata">

**Author:** ![Maria-12648430](https://erlangforums.com/user_avatar/erlangforums.com/maria-12648430/32/604_2.png) [@Maria-12648430](https://erlangforums.com/u/Maria-12648430)\
**Post date:** [August 25, 2022, 6:38pm UTC](https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743/25 "2022-08-25T18:38:12Z")

</div>

Actually, we don’t have to pick one or the other. @RMorisset could implement both, `lookup_element/4` _and_ `lookup_element_as_list` (but please, find another name 😉), if we ask him nicely 😇

---

<div class="post-metadata">

**Author:** ![RMorisset](https://erlangforums.com/user_avatar/erlangforums.com/rmorisset/32/1601_2.png) [@RMorisset](https://erlangforums.com/u/RMorisset)\
**Post date:** [October 11, 2022, 1:27pm UTC](https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743/26 "2022-10-11T13:27:03Z")

</div>

The patch adding `lookup_element/4` just landed (see [Add lookup\_element/4, which takes a default value by RobinMorisset · Pull Request #6234 · erlang/otp · GitHub](https://github.com/erlang/otp/pull/6234#issuecomment-1274498008)), so it will be part of OTP 26. Thank you everyone for the comments and suggestions, and thanks Sverker for reviewing and landing my patch.

[Previous page](https://erlangforums.com/t/proposal-adding-ets-lookup-element-as-list-3/1743.md?page=1)
