Your Turn

  • Exercise: Protocols-3

    Collections that implement the Enumerable protocol define count, member?, reduce, and slice functions. The Enum module uses these to implement methods such as each, filter, and map.

    Implement your own versions of each, filter, and map in terms of reduce.

  • Exercise: Protocols-4

    In many cases, inspect will return a valid Elixir literal for the value being inspected. Update the inspect function for structs so that it returns valid Elixir code to construct a new struct equal to the value being inspected.

Get Programming Elixir ≥ 1.6 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.