Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

cassiemeharry/elixir-monad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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?

About

A monadic system for the Elixir language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages