Skip to content

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

License

Notifications You must be signed in to change notification settings

bwireman/dreamy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dreamy 😴

ci mit commits 1.0.0 downloads PRs Welcome Dreamy 😴

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

Modules

  • Dreamy: Dreamy provides useful macros, functions, types & operators to make elixir even dreamier 😴
  • Dreamy.Defaults: Helpers for dealing with Defaults for functions
  • Dreamy.Either: Datatype for representing Either, Or
  • Dreamy.Monodic: Functions for use with both Result and Option monads
  • Dreamy.Option: Functions for use with Options
  • Dreamy.Result: Functions for use with :ok, and :error tuples
  • Dreamy.Types: Useful Type definitions

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

About

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

Topics

Resources

License

Stars

Watchers

Forks