View Source Dreamy.Either (dreamy v0.2.4)

Datatype for representing Either, Or

Summary

Types

Monodic type representing a left or right tuple

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 empty Either tuple, aka a Neither

Returns an Either tuple with right value populated, and the left nil

Wraps the left value in a Dreamy.Option, returns an empty if the value is nil

Wraps the right value in a Dreamy.Option, returns an empty if the value is nil

Types

@type left(l, _r) :: t(l, nil)
@type neither() :: t(nil, nil)
@type right(_l, r) :: t(nil, r)
@type t(l, r) :: {Dreamy.Either, l, r}

Monodic type representing a left or right tuple

Functions

@spec either(l, r) :: t(l, r) when l: var, r: var

Returns an Either tuple

Examples

iex> use Dreamy
...> either(:l, :r)
{Dreamy.Either, :l, :r}

Applies the function to the left value and flattens

Examples

iex> use Dreamy
...> either(:l, :r)
...> |> flat_map_left(fn _ -> left(:new_left) end)
{Dreamy.Either, :new_left, :r}
Link to this function

flat_map_right(arg, fun)

View Source

Applies the function to the right value and flattens

Examples

iex> use Dreamy
...> either(:l, :r)
...> |> flat_map_right(fn _ -> right(:new_right) end)
{Dreamy.Either, :l, :new_right}
@spec get_left(t(l, any())) :: l when l: var

Returns the left value from an Either tuple

Examples

iex> use Dreamy
...> either(:l, :r)
...> |> get_left()
:l
@spec get_right(t(any(), r)) :: r when r: var

Returns the right value from an Either tuple

Examples

iex> use Dreamy
...> 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

iex> use Dreamy
...> left(:l)
{Dreamy.Either, :l, nil}

Applies the function to the left value

Examples

iex> use Dreamy
...> either(:l, :r)
...> |> map_left(&Atom.to_string/1)
{Dreamy.Either, "l", :r}

Applies the function to the right value

Examples

iex> use Dreamy
...> either(:l, :r)
...> |> map_right(&Atom.to_string/1)
{Dreamy.Either, :l, "r"}
@spec neither() :: neither()

Returns an empty Either tuple, aka a Neither

Examples

iex> use Dreamy
...> neither()
{Dreamy.Either, nil, nil}
@spec right(r) :: right(nil, r) when r: var

Returns an Either tuple with right value populated, and the left nil

Examples

iex> use Dreamy
...> right(:r)
{Dreamy.Either, nil, :r}

Wraps the left value in a Dreamy.Option, returns an empty if the value is nil

Examples

iex> use Dreamy
...> left(:l)
...> |> to_option_left()
{Dreamy.Option, :l}

iex> use Dreamy
...> right(:r)
...> |> to_option_left()
{Dreamy.Option, :empty}

Wraps the right value in a Dreamy.Option, returns an empty if the value is nil

Examples

iex> use Dreamy
...> right(:r)
...> |> to_option_right()
{Dreamy.Option, :r}

iex> use Dreamy
...> left(:l)
...> |> to_option_right()
{Dreamy.Option, :empty}