View Source Dreamy (dreamy v1.0.0)

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

Summary

Functions

Operator for Enum.map

conditionally apply a function to the input value, otherwise letting it pass through unchanged

Macro for defining a constant attribute and function

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

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

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
...> [5, 7]
...> >>> x
...> >>> (&div(&1, 2))
...> >>> x
[1, 2]
Link to this function

conditional_apply(val, bool, fun)

View Source
@spec conditional_apply(v, false, function()) :: v when v: var
@spec conditional_apply(v, true, (v -> res)) :: res when v: var, res: var

conditionally apply a function to the input value, otherwise letting it pass through unchanged

Examples

iex> use Dreamy
...> x = fn y -> y - 1 end
...> 2
...> |> conditional_apply(true, x)
...> |> conditional_apply(false, x)
...> |> conditional_apply(true, x)
0

iex> use Dreamy
...> x = fn y -> y <> "!" end
...> "Hello"
...> |> conditional_apply(false, x)
...> |> conditional_apply(false, x)
...> |> conditional_apply(true, x)
...> |> conditional_apply(false, x)
"Hello!"
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 {:error, "error"} do
...> {:ok, v} -> v
...> end
{:error, "error"}

iex> use Dreamy
...> fallthrough {:ok, "OK"} do
...> {:ok, "OK"} -> "OK"
...> end
"OK"
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 nil, {:error, :not_found} do
...> {:ok, _} -> :ok
...> end
{:error, :not_found}

iex> use Dreamy
...> otherwise {:ok, nil}, {:error, :not_found} do
...> {:ok, _} -> :ok
...> end
:ok