View Source 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

Installation

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

usage

Usage

either-new

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

Either.error

Make an error tuple from a value.

either-map

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

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

LICENSE

MIT