View Source Dreamy (dreamy v0.1.1)

Dreamy provides useful macros, functions, types & operators to make elixir even more dreamy 😴

Summary

Functions

Operator short hand for Enum.map

Macro for defining a constant attribute and function

Macro for adding a default catchall -> clause to case statements, that returns the input value

Function for flipping results

Macro for adding a default catchall -> clause to case statements, that returns the default value

function for applying anonymous functions

Function for extracting values from :ok records

Function for extracting values from :error tuples

Function for applying result tuples on success only

Function for applying result tuples on success only

Functions

Link to this macro

enumerable >>> func

View Source (macro)

Operator short hand for Enum.map

Examples

iex> use Dreamy
...> x = fn y -> y + 1 end
...> y = fn z -> z * 2 end
...> [1, 2]
...> >>> x
...> >>> y
[4, 6]
Link to this macro

const(name, code)

View Source (macro)

Macro for defining a constant attribute and function

Examples

iex> use Dreamy
iex> const :example, "XYZ"
iex> @example
"XYZ"

iex> example()
"XYZ"
Link to this macro

fallthrough(val, list)

View Source (macro)

Macro for adding a default catchall -> clause to case statements, that returns the input value

Examples

iex> use Dreamy
...> fallthrough 1 do
...> 2 -> 2
...> end
1

iex> use Dreamy
...> fallthrough 2 do
...> 2 -> 2
...> end
2
@spec flip(Dreamy.Types.result(res, err)) :: Dreamy.Types.result(err, res)

Function for flipping results

Examples

iex> use Dreamy
...> flip({:ok, 3})
{:error, 3}

iex> use Dreamy
...> flip({:error, 3})
{:ok, 3}
Link to this macro

otherwise(val, default, list)

View Source (macro)

Macro for adding a default catchall -> clause to case statements, that returns the default value

Examples

iex> use Dreamy
...> otherwise 1, nil do
...> 2 -> 2
...> end
nil

iex> use Dreamy
...> otherwise 2, nil do
...> 2 -> 2
...> end
2
@spec through(any(), (any() -> any())) :: any()

function for applying anonymous functions

Examples

iex> use Dreamy
iex> 2 |>
iex> through(fn x -> x - 1 end) |>
iex> through(fn x -> x - 1 end)
0
@spec unwrap(Dreamy.Types.result(x, y)) :: x | {:error, y} when x: var, y: var

Function for extracting values from :ok records

Examples

iex> use Dreamy
...> {:ok, "hello"} |> unwrap
"hello"

iex> use Dreamy
...> {:error, "world"} |> unwrap
{:error, "world"}
@spec unwrap_error(Dreamy.Types.result(x, y)) :: {:ok, x} | y when x: var, y: var

Function for extracting values from :error tuples

Examples

iex> use Dreamy
...> {:ok, "hello"} |> unwrap_error
{:ok, "hello"}

iex> use Dreamy
...> {:error, "world"} |> unwrap_error
"world"
@spec Dreamy.Types.result(res, err) ~> (res -> x) :: x | {:error, err}
when res: var, x: var, err: var

Function for applying result tuples on success only

Examples

iex> use Dreamy
...> {:ok, 1} ~>
...> fn x -> {:ok, x + 1} end ~>
...> fn y -> y + 1 end
3

iex> use Dreamy
...> {:error, 1} ~> fn x -> x + 1 end
{:error, 1}
@spec Dreamy.Types.result(res, err) ~>> (Dreamy.Types.result(res, err) -> x) ::
  x | {:error, err}
when x: var, err: var

Function for applying result tuples on success only

Examples

iex> use Dreamy
...> {:ok, 1} ~>>
...> fn {:ok, x} -> {:ok, x + 1} end ~>>
...> fn {:ok, x} -> {:ok, x + 1} end
{:ok, 3}

iex> use Dreamy
...> {:error, 1} ~>> fn {:ok, x} -> {:ok, x + 1} end
{:error, 1}