Further Exploration

We took our code generation experience to the next level by producing highly maintainable, performant programs that we can take and use in the services we build today. We saw the advantages of advanced code generation and had some fun generating code from remote APIs. If you’re inspired by the possibilities of these techniques, try pushing further. Here are a few ideas to spark your imagination.

  • Add a __using__ definition to the Mime module to allow arbitrary modules to use Mime and append their own custom MIME mappings, such as:

     
    defmodule​ MimeMapper ​do
     
    use​ Mime, ​"text/emoji"​: [​".emj"​],
     
    "text/elixir"​: [​".exs"​]
     
    end​​​
     
    ​​
     
    iex>​ MimeMapper.exts_for_type(​"text/elixir"​)
     
    [​".exs"​]​​
     
    ​​
     
    iex>​ MimeMapper.exts_for_type(​ ...

Get Metaprogramming Elixir 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.