View Source Dreamy.Either (dreamy v0.2.3)
Datatype for representing Either, Or
Summary
Functions
Returns an Either tuple
Applies the function to the left value and flattens
Applies the function to the right value and flattens
Returns the left value from an Either tuple
Returns the right value from an Either tuple
Returns an Either tuple with left value populated, and the right nil
Applies the function to the left value
Applies the function to the right value
Returns an Either tuple with right value populated, and the left nil
Types
Functions
@spec either(l, r) :: t(l, r) when l: var, r: var
Returns an Either tuple
Examples
use Dreamy
iex> either(:l, :r)
{Dreamy.Either, :l, :r}
Applies the function to the left value and flattens
Examples
use Dreamy
iex> either(:l, :r)
...> |> flat_map_left(fn _ -> left(:new_left) end)
{Dreamy.Either, :new_left, :r}
Applies the function to the right value and flattens
Examples
use Dreamy
iex> either(:l, :r)
...> |> flat_map_right(fn _ -> right(:new_right) end)
{Dreamy.Either, :l, :new_right}
Returns the left value from an Either tuple
Examples
use Dreamy
iex> either(:l, :r)
...> |> get_left()
:l
Returns the right value from an Either tuple
Examples
use Dreamy
iex> either(:l, :r)
...> |> get_right()
:r
@spec left(l) :: left(l, nil) when l: var
Returns an Either tuple with left value populated, and the right nil
Examples
use Dreamy
iex> left(:l)
{Dreamy.Either, :l, nil}
Applies the function to the left value
Examples
use Dreamy
iex> either(:l, :r)
...> |> map_left(&Atom.to_string/1)
{Dreamy.Either, "l", :r}
Applies the function to the right value
Examples
use Dreamy
iex> either(:l, :r)
...> |> map_right(&Atom.to_string/1)
{Dreamy.Either, :l, "r"}
@spec right(r) :: right(nil, r) when r: var
Returns an Either tuple with right value populated, and the left nil
Examples
use Dreamy
iex> right(:r)
{Dreamy.Either, nil, :r}