rob-brown / MonadEx

Upgrade your pipelines with monads.
MIT License
309 stars 13 forks source link

How to chain Result Monads using Monadex? #12

Closed Fl4m3Ph03n1x closed 3 years ago

Fl4m3Ph03n1x commented 3 years ago

Background

In my quest to learn more about this library I am trying to chain a Result Monad several times in a function. I understand this is achieved via the fmap, a function which takes a function and a Monad and returns a Monad.

defmodule TestMonadex do
  use Monad.Operators

  import Monad.Result

  # This wont work
  def p2(x) do
    x
    |> success()
    <|> (&plus_1/1)
    <|> (&plus_1/1) 
  end

  defp plus_1(n), do: n + 1
end

Problem

The problem here is that according to the documentation, Result Monad does not implement the fmap:

https://hexdocs.pm/monadex/Monad.Result.html#content

Question