Fl4m3Ph03n1x

Fl4m3Ph03n1x

List of monad libaries for Elixir

Background

I use a library called rop in my code, which is basically an implementation of the Error/Result Monad.

On my never ending search for improvement, I have decided to adopt mix format in one of my personal projects.

Problem

The problem here is that mix format and the rop library don’t play nice together. The library defines as a macro the operator >>>, which is also the same operator used for bitwise operations in Elixir.

So the code does not get properly formatted. Ever.

I have tried to contact the maintainer of the project via the project page by creating issues, but to no avail. The project has also not been updated for several years now which leads to me to think its sunny days are long behind it.

Instead of cloning the project and doing a duplicate of someone else’s work (albeit with some changes and fixes) I have decided it would be preferable to look for another library.

What am I looking for?

I am looking for Monad libraries in Elixir that:

Thus I have found the following options:

Which is not a lot …

Question

Cloning the library in question to fix it is not totally out of question, however unless I add some serious heat to the project I see it more as polluting the hex archive with a duplicate of something that already exists.

  • what would you do in my situation?
  • what other monad / fp libraries do you know?

Most Liked

hauleth

hauleth

Maybe change an idea a little and write your own macro like:

defmacro on_ok(value, call) do
  quote do
    case unquote(value) do
      {:ok, val} -> {:ok, unquote(Macro.pipe(quote(do: val), call, 0))}
      {:error, _} = error -> error
    end
  end
end

Now it is useable like:

foo()
|> on_ok(bar())
|> on_ok(baz())

Which will be logically equivalent to:

with {:ok, a} <- foo(),
     {:ok, b} <- bar(a),
     {:ok, c} <- baz(b),
     do: {:ok, c}
kokolegorille

kokolegorille

Maybe Witchcraft. You might also find videos from the author…

https://www.youtube.com/results?search_query=brooklyn+zelenka

But You might have the same formatting concerns.

Family Function Operator
Setoid equivalent? ==
nonequivalent? !=
Ord greater_than? >
lesser_than? <
Semigroup append <>
Functor lift ~>
convey ~>>
chain >>>
over <~
ap <<~
reverse_chain <<<
Semigroupoid compose <
pipe_compose <~>
Arrow product ^^^
fanout &&&
fuelen

fuelen

The library is so small, that I’d rather copy that 1 macro to my codebase and replace >>> with ~>>

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New

Other popular topics Top

jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement