axelson
Scenic Core Team
Is there anywhere that “MFA” is described in detail in the official Elixir documentation? I’ve tried to find it before but was unable to. Am I just missing it somewhere?
(I know what it is I just to have somewhere to link to in my own documentation for anyone unfamiliar with the concept).
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 7- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
peerreynders
In context of typespecs:
For
child_spec()Erlang usesmfargs()to refer to a{M,F,A}tuple (module, function atom, arguments list -Kernel.apply/3,:erlang.apply/3).kip
Its a good question! The nearest I could find was an erlang type definition in the docs at Types and Function Specifications — Erlang System Documentation v29.0.2
tfwright
This has recently come up for me as I am working on a library where I am adding support for a “function reference” argument. Previously I was expecting
{module, function, args}even though theargscomponent was not really used for anything simply because that format seems to be universal in Elixir. But due to a behavior change I really need to know what arity to expect and I’m sort of at a loss when it comes to best practice!I am using NimbleOptions and there is no built in support for this. In fact, the documentation has this line which was puzzling to me right off the bat:
(There is also
{:fun, arity}but in my use case the module is also variable, edit: and also on closer reading this appears to be for functions of set arity?)I have to wonder why it seems that in Elixir
mfahas come to mean specifically the args variation and I don’t think I’ve seen amfargstype in the wild…voughtdq
Do you mean for enforcing that it has a specific arity or supporting functions that have unknown arities? Not sure about best practices as I prefer to support them all as a matter of flexibility.
For unknown, the
{SomeModule, :function, args}is what I would reach for. I rarely use it in practice though:Then all the others -
{SomeModule, :function}&SomeModule.function/2fn _a, _b -> :ok endFor expected arity, it’s just the others (i.e. no
{m, f, a}).Not sure about that option for NimbleOptions, but I think it can take a capture like
&Enum.map/2, which would cover the bases of requiring a specific arity. Then it’s just a matter of taste on whether you want to support{SomeModule, :function}.Edit:
Yeah I was actually surprised to see it called
aritybecause that would imply it should be{MyModule, :my_fun, 2}, right? It would be interesting to know the historical context of calling the third elementarity.tfwright
Both, I think. Possibly I am missing some angle but in my use case I intended to require the user specify a function, which requires specifying an arity, without making any assumptions about the arguments.
I suppose I could allow them to specify only the function name, but in that case I would have to simply pick the first function defined in the module with that name, which seems like undesirable ambiguity. I could see why in many cases it wouldn’t matter, since the user controls the function and the option, so it can be left to them to pass the correct configuration that matches their implementation, but in my case I can’t infer the desired arity from the option (for reasons I don’t think are relevant here).
Mostly however I am just confused about the
mfa/mfargsmismatch between Elixir and Erlang.voughtdq
Did a little code excavation and it turns out that, even in the Erlang repository “mfa” can mean both, but if in the “args” variant, I see a lot more adhoc type specs. It’s probably one of those cases where its interchangeable use has caused it to have multiple meanings. It does help that you can match on the third element for the various cases:
{m, f, a} when is_integer(a) and a >= 0- known arity{m, f, :_}- unknown arity{m, f, a} when is_list(a)- args instead of arityI think capturing
&SomeModule.function/2is more familiar, but{SomeModule, :function, 2}does make it easier to check if the function exists (vs having to check the capture withFunction.info/2).soyjeansoy
afair I read
mfain typespec section in Elixir hexdocs.