A monadic system for the Elixir language
Elixir
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
README.md
mix.exs

README.md

Elixir Monads

This provides a monadic system for Elixir, a Ruby-flavored language for the Erlang VM.

When dealing with Erlang libraries, several common patterns emerge:

case Library.might_fail() do
    {:ok, value} ->
        case Library.also_might_fail(value) do
            {:ok, something} ->
                some_pid <- {:ok, something}
            {:error, reason} ->
                some_pid <- {:error, reason}
        end
    {:error, reason} ->
        some_pid <- {:error, reason}
end

By stealing the marvelous idea of Monads from the more mainstream functional languages, you can abstract out that tree like this:

import Monad
import ErrorM

some_pid <- (monad ErrorM do
    value <- Library.might_fail()
    Library.also_might_fail(value)
end)

Wasn't that easy?