Skip to content

shterrett/binder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binder

A simple library to allow easy piping of functions that return { :ok, ... } or { :error, ... }, as well as functions that may return nil.

Usage

Either

Imagine needing to chain multiple functions that may return { :ok, ... } tuples (and potentially some that may not). For instance, given functions might_succed_* that take in a value and return either { :ok, ... } or { :error, ... } tuples, and a function do_a_thing that simply takes a value and transforms it, the functions can be piped together like this

x
|> might_succeed_1
|> Either.bind(&might_succeed_2/1)
|> Either.map(&do_a_thing/1)
|> Either.bind(&might_succeed_3/1)

Maybe

For functions that can return nil, Maybe allows the piping together of functions and handles the nil so that the functions don't have to:

x
|> maybe_nil_1
|> Maybe.map(&maybe_nil_2/1)
|> Maybe.bind(&maybe_nil_2/1)
|> Maybe.bind(&do_a_thing/1)

Installation

If available in Hex, the package can be installed by adding binder to your list of dependencies in mix.exs:

def deps do
  [{:binder, "~> 0.1.0"}]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/binder.

About

Maybe/Either monad for Elixir

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages