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

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
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
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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
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
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
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New

We're in Beta

About us Mission Statement