Fl4m3Ph03n1x

Fl4m3Ph03n1x

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?

Showing Posts 1 to 5

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 &&&
Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

Unfortunately Witchcraft also uses the bitwise operator for certain operations. That is why I didn’t include it:

https://github.com/witchcrafters/witchcraft#operators

It breaks the first requirement :frowning:

fuelen

fuelen

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

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}
Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

@fuelen @hauleth I understand I could do a change like that. As I mentioned it wouldn’t be out of the scope, however (ignoring the risk of repeating myself):

(…) 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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

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
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews