al2o3cr

al2o3cr

Is there a commonly-understood name for this pattern?

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”?

First Post!

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.

Where Next?

Popular in Discussions Top

New
ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
CharlesO
Erlang :list.nth simple, but 1 - based nth(1, [H|_]) -> H; nth(N, [_|T]) when N > 1 -> nth(N - 1, T). Elixir Enum.at … coo...
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
New
kostonstyle
Hi all How can I compare haskell with elixir, included tools, webservices, ect. Thanks
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New

We're in Beta

About us Mission Statement