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 On Tuesday, 8 September 2020 at 05:29:07 UTC+5:30 [email protected] wrote: > 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. > The fallback happens here: > https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/enum.ex#L608 > > It is explained in the Enumerable documentation here: > https://hexdocs.pm/elixir/Enumerable.html > This protocol requires four functions to be implemented, reduce/3 > <https://hexdocs.pm/elixir/Enumerable.html#reduce/3>, count/1 > <https://hexdocs.pm/elixir/Enumerable.html#count/1>, member?/2 > <https://hexdocs.pm/elixir/Enumerable.html#member?/2>, and slice/1 > <https://hexdocs.pm/elixir/Enumerable.html#slice/1>. The core of the > protocol is the reduce/3 > <https://hexdocs.pm/elixir/Enumerable.html#reduce/3> function. All other > functions exist as optimizations paths for data structures that can > implement certain properties in better than linear time. > Le mardi 8 septembre 2020 à 08:51:52 UTC+9, [email protected] a écrit : > >> I came across this piece of code which does Enumerable protocol >> implementation for Lists - >> https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/enum.ex#L3761-L3763 >> >> Consequently, some lines below the same implementation of Maps have this >> - >> https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/enum.ex#L3783-L3798 >> >> Curious why Lists should return error while Maps return values being part >> of the same protocol implementation. >> >> -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/f49f8407-3b47-4c1d-9cd1-b43261f09065n%40googlegroups.com.
