O'Reilly logo

Metaprogramming Elixir by Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required