Curious why Lists should return error while Maps return values being part of the same protocol implementation.
sabi...@gmail.com
unread,
Sep 7, 2020, 7:59:07 PM9/7/20
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to elixir-lang-core
I believe it is relying on the default reduce-based implementation for lists (because a loop cannot be avoided for linked lists) while there is a more efficient way for maps to count or check memberships.
This protocol requires four functions to be implemented, reduce/3,
count/1, member?/2, and slice/1. The core of the protocol is the
reduce/3 function. All other functions exist as optimizations paths
for data structures that can implement certain properties in better
than linear time.
Sayan Chakraborty
unread,
Sep 8, 2020, 3:37:25 AM9/8/20
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to elixir-lang-core
Thanks for the reply. But isn't lenght(list), :lists.member(element, enumerable) better alternative here?
its what's being invoked in their namesake functions in Enum module atleast for Lists