4 ms·
You are missing a much bigger piece. Protocols. I can implement any data structure, and if I define reduce for that data structure I get the entire Enum module
by phamilton 13y ago
You are missing a much bigger piece. Protocols.
I can implement any data structure, and if I define reduce for that data structure I get the entire Enum module for free, all tail call optimized.
It means I can mix and match data structures. I can do crazy things like zip a binary search tree and a lazy data stream together and then call take(5) to get the first 5 elements. And all that is required is reduce to be defined for all data structures. Protocols are a big deal.
- scribu 13y agoErlang/Elixir noob here. Are you saying that protocols are a useful thing to learn in a) Erlang, b) Elixir or c) both?
- gargantuan 13y agoElixir has them built-in. They are basically an interface. A protocol says "this object implements this interface".
- phamilton 13y agoProtocols (and macros) are the real differences in Elixir that you don't have in Erlang. The presence of protocols in Elixir enable many really cool features and designs that you wouldn't be able to do easily in Erlang.