View Source Dreamy (dreamy v0.1.3)

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

Summary

Functions

Operator 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 true clause to cond statements, that returns the default value

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 getting the first :ok result if one exists

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 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]

iex> use Dreamy
...> x = fn y -> y - 1 end
...> [2, 3]
...> >>> x
...> >>> (&IO.inspect/1)
...> >>> x
...> >>> (&IO.inspect/1)
[0, 1]
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

or_else(default, list)

View Source (macro)

Macro for adding a default catchall true clause to cond statements, that returns the default value

Examples

iex> use Dreamy
...> x = 5
...> or_else "Less than 10" do
...> x == 10 -> "10"
...> x > 10 -> "Greater than 10"
...> end
"Less than 10"

iex> use Dreamy
...> x = 11
...> or_else "Less than 10" do
...> x == 10 -> "10"
...> x > 10 -> "Greater than 10"
...> end
"Greater than 10"
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(a, (a -> b)) :: b when a: var, b: var

function for applying anonymous functions

Examples

iex> use Dreamy
iex> 2
...> |> through(fn x -> x - 1 end)
...> |> 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(a, err_a) ||| Dreamy.Types.result(b, any()) ::
  {:ok, a} | {:ok, b} | {:error, err_a}
when a: var, b: var, err_a: var

Function getting the first :ok result if one exists

Examples

iex> use Dreamy
...> {:ok, "success"} ||| {:ok, "success 2"}
{:ok, "success"}

iex> use Dreamy
...> {:error, "oops"} ||| {:ok, "success 2"}
{:ok, "success 2"}

iex> use Dreamy
...> {:error, "oops"} ||| {:error, "darn"}
{:error, "oops"}

iex> use Dreamy
...> {:ok, "first try"} ||| {:error, "darn"} ||| {:ok, "finally"}
{:ok, "first try"}

iex> use Dreamy
...> {:error, "oops"} ||| {:error, "darn"} ||| {:ok, "finally"}
{:ok, "finally"}
@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}