Dreamy provides useful macros, functions, types & operators to make elixir even dreamier 😴
- 📔 Docs
- 💾 Download
- 👾 Discord Post
Dreamy
: Dreamy provides useful macros, functions, types & operators to make elixir even dreamier 😴Dreamy.Defaults
: Helpers for dealing with Defaults for functionsDreamy.Either
: Datatype for representing Either, OrDreamy.Monodic
: Functions for use with both Result and Option monadsDreamy.Option
: Functions for use with OptionsDreamy.Result
: Functions for use with :ok, and :error tuplesDreamy.Types
: Useful Type definitions
defmodule Example.Usage do
use Dreamy
# read file and split into a map of software => version,
# -> %{"elixir" => "x.x.x", "erlang" => "x.x.x"}
@spec versions() :: map()
def versions do
File.read!(".tool-versions")
|> String.split("\n", parts: 2)
>>> (&String.trim/1)
>>> (&String.split/1)
>>> (&List.to_tuple/1)
|> Enum.into(%{})
end
defp foo(x), do: {:ok, x + 1}
defp bar(x), do: {:ok, x * 2}
# managing results without Dreamy
def without_dreamy(x) do
with {:ok, y} <- foo(x),
{:ok, y} <- foo(y),
{:ok, y} <- bar(y) do
y
end
end
# VS. with Dreamy
def with_dreamy(x), do:
foo(x)
~> (&foo/1)
~> (&bar/1)
|> unwrap()
end
Available in Hex, the package can be installed
by adding dreamy
to your list of dependencies in mix.exs
:
def deps do
[
{:dreamy, "~> 1.0.0"}
]
end