View Source Dreamy (dreamy v0.1.2)
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 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
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]
Macro for defining a constant attribute and function
Examples
iex> use Dreamy
iex> const :example, "XYZ"
iex> @example
"XYZ"
iex> example()
"XYZ"
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}
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
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(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}