al2o3cr

al2o3cr

There’s a common pattern in Elixir libraries where an “implementation module” is used by generic functions provided by the library, and the library provides a use macro that takes care of filling in the correct parameter automatically.

Examples:

  • Ecto.Repo uses this technique to pass the name of the module it’s used in to functions in Ecto.Repo.Schema:

https://github.com/elixir-ecto/ecto/blob/a81aba7840afcf53c3408de17b756ec415a866d6/lib/ecto/repo.ex#L267-L269

  • Guardian uses this technique both for it’s core functions as well as for a plug; it’s where I got the term “implementation module” from:

https://github.com/ueberauth/guardian/blob/0b7aba1840bf2f8b75bc3a258463a3fba7f325de/lib/guardian.ex#L401-L404

https://github.com/ueberauth/guardian/blob/0b7aba1840bf2f8b75bc3a258463a3fba7f325de/lib/guardian/plug.ex#L80-L81

Is there a name for this pattern? “Specialization”? “Compile-time currying”?

Showing Posts 1 to 1

LostKobrakai

LostKobrakai

I’m not sure there is a name for it, but instance module might be quite fitting. Basically the module holding the use call becomes the API into a specific instance of the service provided by the library. It’s a convenience over needing the user supply common config per instance over and over again. The use macro itself is basically a instance or wrapper factory.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New
nseaSeb
I’ve just put together a small POC exploring PDF inspection from Elixir/Phoenix: The idea is pretty simple: drag & drop a PDF in a...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews