{"path": "/projects/contexir/", "title": "Contexir · Bruno Dias", "html": "<!doctype html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"utf-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <meta name=\"description\" content=\"Context-oriented programming for Elixir. Activate layers to refine function behavior in the current BEAM process.\">\n  <title>Contexir · Bruno Dias</title>\n  <link rel=\"canonical\" href=\"https://diasbruno.github.io/projects/contexir/\" data-project-metadata>\n  <link rel=\"icon\" href=\"/assets/site/signature.svg\" type=\"image/svg+xml\">\n  <link rel=\"alternate\" type=\"application/atom+xml\" title=\"diasbruno\" href=\"/atom.xml\">\n  <link rel=\"alternate\" type=\"application/json\" href=\"/projects/contexir/content.json\">\n  <link rel=\"stylesheet\" href=\"/assets/site/tokens.css\">\n  <link rel=\"stylesheet\" href=\"/assets/site/site.css\">\n  <link rel=\"stylesheet\" href=\"/assets/site/footer.css\">\n\n</head>\n<body class=\"light\">\n<div id=\"site-page\">\n<a class=\"skip-link\" href=\"#content\">Skip to content</a>\n<header class=\"site-header\">\n  <a class=\"brand\" href=\"/\" data-site-navigation aria-label=\"Bruno Dias, home\">\n    <img src=\"/assets/site/signature.svg\" width=\"24\" height=\"34\" alt=\"\">\n  </a>\n  <nav aria-label=\"Main navigation\">\n    <ul>\n<li><a class=\"nav-vrn\" href=\"/vrn/\" data-site-navigation><span class=\"nav-label\">vrn</span> <span class=\"nav-badge\">research</span></a></li>\n<li><a class=\"nav-posts\" href=\"/posts/\" data-site-navigation>Posts</a></li>\n<li><a class=\"nav-projects\" href=\"/projects/\" data-site-navigation aria-current=\"location\">Projects</a></li>\n<li><a class=\"nav-about\" href=\"/about/\" data-site-navigation>About</a></li>\n</ul>\n  </nav>\n</header>\n\n<main class=\"section\" id=\"content\" tabindex=\"-1\">\n  <article class=\"post-detail project-detail\">\n    <header class=\"section-header\">\n      <p class=\"post-category\">Project</p>\n      <h1>Contexir</h1>\n      <p class=\"post-subtitle\">Context-oriented programming for Elixir. Activate layers to refine function behavior in the current BEAM process.</p>\n      <p class=\"project-technologies\">Elixir · BEAM</p>\n    </header>\n    <div class=\"post-columns\">\n      <section class=\"post-body\" aria-label=\"Project overview\">\n<h2>Overview</h2>\n<p>Contexir brings context-oriented programming to Elixir. A layer can add behavior before or after a function, or wrap the next implementation and decide when to continue. Callers can activate layers explicitly or select them with context values.</p>\n<h2>A small example</h2>\n<p>An inventory function can keep its base behavior while a separate layer reports when the count changes.</p>\n<pre><code class=\"language-elixir\">defmodule Inventory do\n  use Contexir\n\n  def restock(count, amount, _context), do: count + amount\nend\n\nimport Contexir.Layer\n\ndeflayer ReportRestock do\n  refine Inventory do\n    defpartial restock(_count, amount, _context), mode: :before do\n      IO.puts(&quot;Adding #{amount} items&quot;)\n    end\n  end\nend\n</code></pre>\n<p>Layer activation is local to the BEAM process, so a newly spawned process can choose its own context.</p>\n\n      </section>\n      <aside class=\"post-links\" aria-labelledby=\"project-links-heading\">\n        <h2 id=\"project-links-heading\">Links</h2>\n        <ul>\n<li><a href=\"https://github.com/diasbruno/contexir\">Repository</a></li>\n<li><a href=\"https://contexir.hexdocs.pm/\">Documentation</a></li>\n<li><a href=\"https://hex.pm/packages/contexir\">Hex package</a></li>\n<li><a href=\"/projects/\" data-site-navigation>All projects</a></li>\n        </ul>\n      </aside>\n    </div>\n  </article>\n</main>\n\n<footer class=\"site-footer\">\n  <div class=\"site-footer-inner\">\n    <a class=\"site-footer-home\" href=\"/\" data-site-navigation>Bruno Dias</a>\n    <ul aria-label=\"Footer links\">\n      <li><a href=\"https://github.com/diasbruno\">GitHub</a></li>\n      <li><a href=\"/atom.xml\">Atom feed</a></li>\n    </ul>\n  </div>\n</footer>\n\n</div>\n<script type=\"module\" src=\"/assets/site/navigation.js\"></script>\n</body>\n</html>\n"}
