It is for optimization purposes. We could implement all? on top of the
reduce but that would imply dispatching to the protocol, then to the
implementation and then process the reduce operation. So we skip all of
that by dispatching to the local implementation.
Another way to put it: sometimes you will find non-idiomatic code in Elixir
codebase so *you* don't have to write non-idiomatic code. :)
The other (possibly conflicting) idea is that those could be part of the
protocol itself but that would make the protocol unnecessarily large. I do
expect the Enumerable protocol to grow though at some point, specially if
we end-up implementing a queue/array/vector abstraction.
Founder and Director of R&D
On Wed, Oct 12, 2016 at 5:06 PM, Jay Hayes <j...@iamvery.com> wrote:
> Today I'm studying Elixir protocols and stumbled upon something I found
> 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.
> 55e34a3679/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.
> 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/
> For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group and stop receiving emails from it, send an email
To view this discussion on the web visit
For more options, visit https://groups.google.com/d/optout.