View Source Dreamy 😴

ci mit commits 1.0.0 downloads PRs Welcome Dreamy 😴

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

Modules

Usage

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

Installation

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