Skip to content

jechol/either

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Either

test Coverage Status Hex.pm GitHub

Either is helpers to handle :ok, {:ok, value}, :error and {:error, reason} in consistent way.

This library is copied from Reather.Either from SeokminHong/reather-lite.

Installation

def deps do
  [
    {:either, "~> 0.1.1"}
  ]
end

Usage

Either.new

Convert a value into ok or error tuple. The result is a tuple having an :ok or :error atom for the first element, and a value for the second element.

Either.error

Make an error tuple from a value.

Either.map

map a function to an either tuple. The given function will be applied lazily when the either is an ok tuple.

Either.traverse

Transform a list of eithers to an either of a list. If any of the eithers is error, the result is error.

iex> [{:ok, 1}, {:ok, 2}] |> Either.traverse()
{:ok, [1, 2]}
iex> [{:ok, 1}, {:error, "error!"}, {:ok, 2}]
...> |> Either.traverse()
{:error, "error!"}

LICENSE

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages