View Source Dreamy.Either (dreamy v0.2.3)

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 Either tuple with right value populated, and the left nil

Types

@type left(l, _r) :: t(l, 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

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}
Link to this function

flat_map_right(arg, fun)

View Source

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}
@spec get_left(t(l, any())) :: l when l: var

Returns the left value from an Either tuple

Examples

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

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}