Today I'm studying Elixir protocols and stumbled upon something I found 
curious.

Enumerable came to mind pretty quickly for me as a good example for 
protocols. The interesting thing that I noticed is the default 
implementations of Enumerable for Elixir types is a little underwhelming. 
In particular count/1 and member?/2 aren't even implemented on the 
protocol. As it turns out, I discovered that _many_ Enum functions for 
lists in Enum directly instead of in terms of the protocol (e.g. 
https://github.com/elixir-lang/elixir/blob/c07c345c3c7f2c48531ffe441099c755e34a3679/lib/elixir/lib/enum.ex#L2690-L2700).
 
Of course, I understand that the behavior is OK as is, but it seems to 
create a little confusion for me about the purpose of the protocol in 
addition to be a bad example.

I have some suspicion that there might be an optimization involved here, 
but I'm curious to hear more about the reason for this design. Also, I'd 
love to take a shot at any improvements that might be involved.

Thanks!

-- 
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 elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/05049472-813d-42af-ad18-67ff8da5d2e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to